An introduction to the MIT algorithm--third speaking. The Divide-and-conquer

Source: Internet
Author: User

The topic of introduction to MIT algorithm under this column (algorithms) is an individual's learning experience and notes on the introduction to the MIT algorithm of NetEase Open course. All the content comes from the lectures of Charles E. Leiserson and Erik Demaine teachers in MIT Open Course Introduction to algorithms. (http://v.163.com/special/opencourse/algorithms.html)

Section III-------Divide and conquer law the Divide-and-conquer

The main content of this lesson is to introduce the idea of divide and conquer law, and some examples of algorithms applying the idea of divide and conquer, and analyze the performance of the algorithm combined with the main theorem method of the last lesson.

The so-called divide-and-conquer law, namely divide and conquer, conquer. The general algorithm design steps are:

1, Divide. Divide, divide the problem into several sub-problems;

2, Conquer. The first step neutron problem is solved by recursive method;

3, Combine. Integration of the results of each sub-problem will result in a solution to the problem.

First, merge sort

As shown in the merger and order in the division of the idea, according to the design idea is easy to get the efficiency of the merger sort recursive. When the recursive formula is obtained, it is easy to find the case 2 which satisfies the main theorem method, so the complexity of the merging sort is θ (NLGN).

Two or two points find

As shown in binary search in the division of the idea, the same way to get the recursive formula, it is easy to find that it satisfies the main theorem method of case 2, so the complexity of the merge order is θ (LGN).

Third, the A^n

In order to calculate the number of a^n, the traditional practice (so-called naive algorithm) is that the loop multiplies n times, and the algorithm efficiency is θ (n). However, if the idea of divide-and-conquer method is used, the algorithm efficiency can be increased to θ (LGN), as shown in.

Iv. calculation of the Fibonacci sequence

The Fibonacci sequence should also be familiar, with its recursive definition as shown. The method of solving Fibonacci series is also more, mainly have the following several.

1. Naïve recursive algorithm (Naive recursive algorithm)

At this time the algorithm efficiency is Ω (φ^n), exponential level. where φ= (1 + 5^½)/2, which is the golden split ratio.

2. Simple recursive square algorithm (Naive recursive squaring)

This algorithm is mainly based on a mathematical character of the Fibonacci sequence. This property indicates that the Fibonacci sequence F (n) is the Φ^n/5^½ downward rounding. Thus, the solution of the problem becomes a problem of exponentiation, so the efficiency of the algorithm is θ (LGN).

However, this method is not very reliable, mainly when n is relatively large, due to the hardware limitations of the computer's floating-point arithmetic results and the real value of the error.

3. Bottom-up algorithm (bottom-up)

Considering the simple recursive algorithm in 1, in order to solve F (n), it is necessary to solve F (n-1) and F (n-2) at the same time, obviously doing a lot of repetitive work. This redundancy can be avoided by using a bottom-up algorithm. To calculate f (n), the F0,F1,F2 is calculated in turn ... FN, the calculation of FN requires only the first two results, which increases the efficiency of the algorithm to θ (n).

4. Recursive square algorithm (Recursive squaring)

The algorithm is also based on a theorem, theorem and proof process as shown. In this way, the problem is solved to become the matrix of the problem, the efficiency of the algorithm is increased to θ (LGN).

V. Matrix multiplication

As shown in the matrix multiplication problem description, there are several main methods for matrix multiplication.

1. General algorithm (standard algorithm)

Matrix multiplication, the first thought of course is the following algorithm, it is not difficult to see the efficiency of the algorithm for θ (n^3).

For I←1-n do-j←1 to-n do-          c[i][j]←0 for k←1-n do                  C[i][j]←c[i][j] + a[i][k]⋅b[k][j]  

  

2. Divide-and-conquer algorithm (Divide-and-conquer algorithm)

The method of divide and conquer is used in matrix multiplication, and the first sense should be effective to improve the efficiency of the algorithm. As shown in the divide-and-conquer scheme, and the efficiency analysis of the algorithm. It is shown that the algorithm efficiency is θ (n^3). Algorithm efficiency has not improved.

3. Strassen algorithm (Strassen ' s algorithm)

Considering that the method of divide-and-conquer in 2 can not effectively improve the efficiency of the algorithm, in order to improve the efficiency of the algorithm, we must find a way to reduce the coefficients of 2 in the recursive formula by the main theorem. Strassen proposes a divide-and-conquer approach that reduces the coefficient to 7, as shown in.

It's hard to imagine how Strassen came up with this scheme, but it did reduce the original recursive coefficient from 8 to 7. As shown here is the algorithm efficiency analysis of the algorithm:

Thus, the Strassen algorithm increases the multiplication efficiency of the matrix to θ (n^2.81). Although this 2.81 does not seem to increase in number, but because the algorithm efficiency itself refers to a number of levels, so when n is relatively large (n≥30 on modern machines), the advantages of the Strassen algorithm is already very obvious.

Of course, there are many optimization algorithms for matrix operations. The efficiency of matrix multiplication is now theoretically the best: Θ (n^2.376 ...). But among the many optimization algorithms, the Strassen algorithm is the simplest.

An introduction to the MIT algorithm--third speaking. The Divide-and-conquer

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.