Master theorem 主定理及其应用算法


Generic form

The master theorem concerns recurrence relations of the form:
T(n) = a \; T\!\left(\frac{n}{b}\right) + f(n)  \;\;\;\; \mbox{where} \;\; a \geq 1 \mbox{, } b > 1.
In the application to the analysis of a recursive algorithm, the constants and function take on the following significance:
  • n is the size of the problem.
  • a is the number of subproblems in the recursion.
  • n/b is the size of each subproblem. (Here it is assumed that all subproblems are essentially the same size.)
  • f (n) is the cost of the work done outside the recursive calls, which includes the cost of dividing the problem and the cost of merging the solutions to the subproblems.

Application to common algorithms


AlgorithmRecurrence RelationshipRun timeComment
Binary searchT(n) = T(\frac{n}{2}) + O(1)O(log(n))Apply Master theorem where f(n) = nc[3]
Binary tree traversalT(n) = 2 T(\frac{n}{2}) + O(1)O(n)Apply Master theorem where f(n) = nc[3]
Optimal Sorted Matrix SearchT(n) = 2 T(\frac{n}{2}) + O(\log(n))O(n)Apply Akra-Bazzi theorem for p = 1 and g(u) = log(u) to get Θ(2n − log(n))
Merge SortT(n) = 2 T(\frac{n}{2}) + O(n)O(nlog(n))

评论

此博客中的热门博文

Nu förbjuder Kina handel med elfenben

Fader av pingyins

Kineserna vill köpa Volvos kompetens