Divide-and-Conquer Algorithms and Recurrence Relations: Master Theorem, Study notes of Linear Algebra

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

Pre 2010

Uploaded on 09/17/2009

koofers-user-swi
koofers-user-swi 🇺🇸

5

(1)

8 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Jim Lambers
Math 6A
Spring Quarter 2003-04
Lecture 24 Notes
These notes correspond to Section 6.3 in the text.
Divide-and-Conquer Algorithms and Recurrence Relations
In the previous lectures, we have studied recurrence relations in which a term anof a sequence is
determined by preceding terms an1, an2, . . . , ankwhere kis 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 n1, n 2, and so on.
However, in many cases, a problem with input of size ncan be solved by reducing the problem
to aproblems with input of size n/b, for some b > 1, and then constructing the solution of the
original problem from the asolutions 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 nfrom the asolutions 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 csuch that f(n)cg(n) for all nn0for some
integer n0.
Theorem (Master Theorem) Let fbe an increasing function that satisfies the recurrence relation
f(n) = af(n/b) + cnd,
whenever n=bkfor some positive integer k,a1,bis an integer greater than 1, c > 0and d0.
Then
f(n) =
O(nd)if a < bd
O(ndlog n)if a=bd
O(nlogba)if a > bd
1
pf3

Partial preview of the text

Download Divide-and-Conquer Algorithms and Recurrence Relations: Master Theorem and more Study notes Linear Algebra in PDF only on Docsity!

Jim Lambers Math 6A Spring Quarter 2003- Lecture 24 Notes

These notes correspond to Section 6.3 in the text.

Divide-and-Conquer Algorithms and Recurrence Relations

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:

  • a/bd^ < 1: The sum of the geometric series is bounded by 1/(1 − a/bd), and therefore f (n) = O(nd).
  • a/bd^ = 1: The sum of the geometric series is f (n) = cndk = cnd^ logb n = O(nd^ log n).
  • a/bd^ > 1: We have

f (n) = cnd^

(a/bd)k+1^ − 1 (a/bd) − 1