算法时间复杂度的计算-The master method
The master method
The master method applies to recurrences of the form
T(n) = a *T(n/b) + f(n)
where a>=1, b>1, and f is asymptotically positive.
Example:
Ideas of master theorem
CASE 1: The weight increases geometrically from the root to the leaves. The leaves hold a constant fraction of the total weight.
CASE 2: (k = 0) The weight is approximately the same on each of the logbn levels
CASE 3: The weight decreases geometrically from the root to the leaves. The root holds a constant fraction of the total weight.
The divide-and-conquer design paradigm
1. Divide the problem (instance) into subproblems.
2. Conquer the subproblems by solving them recursively.
3. Combine subproblem solutions.
Example 1: merge sort
1. Divide: Trivial.
2. Conquer: Recursively sort 2 subarrays.
3. Combine: Linear-time merge.
Example 2: Binary search
Find an element in a sorted array:
1. Divide: Check middle element.
2. Conquer: Recursively search 1 subarray.
3. Combine: Trivial.
master method 不仅可以应用到软件,在其他方面也有应用:
VLSI layout
Problem: Embed a complete binary tree with n leaves in a grid using minimal area.
另一种更加高效的H-tree embedding











浙公网安备 33010602011771号