

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
These lecture notes from math 6a, spring quarter 2003-04, cover divide-and-conquer algorithms and recurrence relations. The master theorem is presented, which provides insight into the complexity of certain classes of divide-and-conquer algorithms. The theorem is proven and two examples, binary search and mergesort, are provided to illustrate its application.
Typology: Study notes
1 / 3
This page cannot be seen from the preview
Don't miss anything!


Jim Lambers Math 6A Spring Quarter 2003- Lecture 24 Notes
These notes correspond to Section 6.3 in the text.
In the previous lectures, we have studied recurrence relations in which a term an of a sequence is determined by preceding terms an− 1 , an− 2 ,... , an−k where k is the degree of the recurrence relation. These recurrence relations arise from problems in which the solution for an input of size n, where the notion of size of the input depends on the problem, can be obtained from solutions of slightly smaller instances of the same problem, such as those of size n − 1 , n − 2, and so on. However, in many cases, a problem with input of size n can be solved by reducing the problem to a problems with input of size n/b, for some b > 1, and then constructing the solution of the original problem from the a solutions that are obtained. This approach to problem-solving is known as divide-and-conquer. The number of operations performed to solve a problem in this manner, which we denote by f (n), satisfies a recurrence relation of the form
f (n) = af (n/b) + g(n),
where g(n) denotes the number of operations needed to construct the solution of the original problem of size n from the a solutions of problems of size n/b. The following theorem provides essential insight into the complexity of certain classes of divide- and-conquer algorithms. We use the “big-Oh” notation to measure complexity. A function f (n) is said to be O(g(n)) if there exists a constant c such that f (n) ≤ cg(n) for all n ≥ n 0 for some integer n 0.
Theorem (Master Theorem) Let f be an increasing function that satisfies the recurrence relation
f (n) = af (n/b) + cnd,
whenever n = bk^ for some positive integer k, a ≥ 1 , b is an integer greater than 1, c > 0 and d ≥ 0. Then
f (n) =
O(nd) if a < bd O(nd^ log n) if a = bd O(nlogb^ a) if a > bd
Proof For simplicity, we assume that f (1) = c; this assumption will not affect the growth of f that we are trying to measure. We then have
f (n) = af (n/b) + cnd = a[af (n/b^2 ) + c(n/b)d] + cnd = a^2 f (n/b^2 ) + ac(n/b)d^ + cnd = a^2 [af (n/b^3 ) + c(n/b^2 )d] + ac(n/b)d^ + cnd = a^3 f (n/b^3 ) + a^2 c(n/b^2 )d^ + ac(n/b)d^ + cnd
= aj^ f (n/bj^ ) + cnd
∑j−^1
i=
ai(1/bi)d
= aj^ f (n/bj^ ) + cnd
∑j−^1
i=
(a/bd)i
= alogb^ nf (1) + cnd
log ∑b n− 1
i=
(a/bd)i
= alogb^ nc + cnd
k∑− 1
i=
(a/bd)i
= alogb^ ncnd/(bd)k^ + cnd
k∑− 1
i=
(a/bd)i
= cnd
∑k
i=
(a/bd)i.
This expression for f (n) can be proven more rigorously using mathematical induction, which we do not do here. The sum is a geometric series with initial term cnd^ and common ratio a/bd. We consider three cases:
f (n) = cnd^
(a/bd)k+1^ − 1 (a/bd) − 1