This article according to Tsinghua University Deng Junhui teacher Curriculum "Data Structure" summary, course address. Recursive and recursive equations
From a recursive point of view, to solve the sum problem of array A, SUM (a,n), you need
-Recursive solution scale for n-1 problem sum (a,n-1)
-Tired plus a[n-1]
The recursive equation looks at its complexity,
T (n) t (0) =t (n−1) +o (1)//recurrence=o (1)//base:sum (a,0) (1) (2) (1) t (n) = t (n−1) + O (1)//R e C u r r e N c E (2) T (0) = O (1)//b a S e:s u m (A, 0)
Solution Process
Calculation of complexity
For the problem of sum of arrays, the common method is to write a loop to solve, and the complexity is O (n) o (n).
Using recursive analysis, can be decomposed into many child problems, the complexity of each trivial child problem is O (1) O (1), a total of n n processes. Therefore the complexity of the complex is O (n) o (n).
Reduction and treatment of
Decrease-and-conquer, in order to solve a large-scale problem, it can be divided into two sub problems: one ordinary, another scale reduction. The solution of the original problem is obtained by solving the sub problem separately.
Divide
Divide-and-conquer, in order to solve a large-scale problem, it can be divided into several (usually two) sub problems, the scale is roughly equivalent to solve the sub problem respectively. The solution of the original problem is obtained by the solution of the problem.
Common complexity issues