CSCE 411 Lecture 5

From Notes
Jump to navigation Jump to search
Lecture Slides

« previous | Wednesday, September 5, 2012 | next »


Example Limit Superior

f(n)=n2+(1)nn2+ng(n)=n2lim supn|f(n)||g(n)|=2

Therefore f(n)O(g(n))

Divide and Conquer

  1. Divide a problem into subproblems
  2. Recursively solve subproblems
  3. Combine solutions to subproblems to get solution to original problem

Example: Merge-sort

  1. Divide the input in half
  2. Recursively sort the two halves (basis is a sequence with 1 key)
  3. Combine two sorted subsequences by merging them

Recurrence Relation

How long does Merge-sort take?

Let T(n) be the worst-case time on a sequence of n keys.

If n=1, then T(n)=Θ(1) (constant)

If n>1, then T(n)=2T(n2)+Θ(n) (2 × time of solving each half and then the merge)


Two ways to solve:

  1. Expand several times, guess pattern, and try to prove by induction. (hard!)
  2. Master theorem

Using the master theorem, g(n)=nlog22=n and f(n)=Θ(n). Therefore, T(n)=Θ(g(n)logn)=Θ(nlogn)

Master Theorem

(See Master Theorem→)


Given a recursive function (recurrence relation) of the form

T(n)=aT(nb)+f(n)

Let g(n)=nlogba=alogba. This represents the number of "leaf operations" in the divide-and-conquer tree

  1. If f(n)<<g(n) then T(n)=Θ(g(n))
  2. If f(n)g(n) then T(n)=Θ(g(n)logn)
  3. If f(n)>>g(n) then T(n)=Θ(f(n))


Other D&C Algorithms

  • Mathematics
    • Converting Binary to Decimal
    • Integer Multiplication
    • Matrix Multiplication
    • Matrix Inversion
    • Fast Fourier Transform