算法时间复杂度的计算-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.

算法时间复杂度的计算-The master method - tauruspdj - tauruspdj的博客算法时间复杂度的计算-The master method - tauruspdj - tauruspdj的博客

Example:

算法时间复杂度的计算-The master method - tauruspdj - tauruspdj的博客

算法时间复杂度的计算-The master method - tauruspdj - tauruspdj的博客

 

Ideas of master theorem

算法时间复杂度的计算-The master method - tauruspdj - tauruspdj的博客

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.

算法时间复杂度的计算-The master method - tauruspdj - tauruspdj的博客

算法时间复杂度的计算-The master method - tauruspdj - tauruspdj的博客

 

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.

算法时间复杂度的计算-The master method - tauruspdj - tauruspdj的博客

 

master method 不仅可以应用到软件,在其他方面也有应用:

VLSI layout
Problem: Embed a complete binary tree with n leaves in a grid using minimal area.

算法时间复杂度的计算-The master method - tauruspdj - tauruspdj的博客

另一种更加高效的H-tree embedding

算法时间复杂度的计算-The master method - tauruspdj - tauruspdj的博客

posted @ 2013-02-24 13:50  Excelight  Views(698)  Comments(0)    收藏  举报