Divide and Conquer Algorithms Part III - PowerPoint PPT Presentation

1 / 8
About This Presentation
Title:

Divide and Conquer Algorithms Part III

Description:

Divide and Conquer Algorithms. Part III. Vasileios Hatzivassiloglou. University of Texas at Dallas. Solving divide and conquer recurrences ... – PowerPoint PPT presentation

Number of Views:33
Avg rating:3.0/5.0
Slides: 9
Provided by: VasileiosH9
Category:

less

Transcript and Presenter's Notes

Title: Divide and Conquer Algorithms Part III


1
Divide and Conquer AlgorithmsPart III
  • Vasileios Hatzivassiloglou
  • University of Texas at Dallas

2
Solving divide and conquer recurrences
  • Theorem 1 Let f(n) be an increasing function
    with f(n) af(n/b) c whenever n is divisible
    by b, where a1, b integer greater than 1, and c
    a positive real. Then,
  • if a1, f(n) O(logn)
  • if agt1, f(n) O(nlogba)
  • Additionally, the theorem specifies the exact
    values of f(n) for n a power of b.

3
Proving Theorem 1
  • If nbk for some k (k logbn),
  • f(n) af(n/b) c
    a(af(n/b2) c) c
    a2f(n/b2) ac c
    a2(f(n/b3) c) ac c
    a3f(n/b3) a2c ac
    c ... akf(1) c(1 a a2
    ... ak-1)
  • Assume a1 and that nbk. Then, ai 1 and the
    sum is ck, so that f(n) f(1) ck f(1)
    clogbn O(logn).

4
Proving Theorem 1
  • If a1 but n is not a power of b, there is some k
    such that bk lt n lt bk1. Because f is increasing,
    f(bk) f(n) f(bk1).
  • f(n) f(bk1) f(1) c(k1) f(1) c ck lt
    f(1) c clogbn since k lt logbn. So f(n) is
    again O(logn).

5
Proving Theorem 1
  • Now consider agt1 and first the case where nbk
    for some k.
  • The sum is c(ak-1)/(a-1) (sum of the terms of a
    geometric progression), so
  • f(n) akf(1) c(ak-1)/(a-1)
    (f(1)c/(a-1))ak c/(a-1) O(ak)
    O(alogbn) O(nlogba).
  • The proof for the remaining case is similar to
    the previous part of the proof, using the next
    higher k.

6
Applying Theorem 1
  • Binary search
  • f(n)f(n/2)2
  • O(logn)
  • Finding the minimum and maximum
  • f(n)2f(n/2)2
  • O(nlog22) O(n1) O(n)

7
Reading
  • Section 7.3 (Theorem 1 to Example 8)

8
Review problems
  • Find the asymptotic form (O notation) of an
    increasing function f for which f(n) 3f(n/3)
    3 when n is divisible by 3.
  • Solve the recurrence relation T(n) 3T(n/2) 2,
    T(1) 2 when n is a power of 2.
  • An elimination tournament has n 2k teams in
    each round, all surviving teams play exactly one
    game and the winners advance to the next round.
    Construct recurrence relations for (a) the number
    of rounds played (b) the total number of games
    played.
Write a Comment
User Comments (0)
About PowerShow.com