Finish Recurrences, Heaps




CS146

Chris Pollett

Feb 24, 2014

Outline

Introduction

The Substitution Method

More on Substitution Guess Choice

Subtleties

Changing Variables

Quiz (Sec 5)

Which of the following statements is true?

  1. If `n` is not a power of `2`, then the padding to make `n` a power of 2 reduces Strassen to be a `Theta(n^3)` algorithm.
  2. The divide and conquer algorithm for the maximum sub-array problem was `Omega(n^2)`.
  3. `log (n!) in Theta(log (n^n))`

Quiz (Sec 6)

Which of the following statements is true?

  1. Any algorithm solving matrix multiplication must be `Omega(n^2)`.
  2. `n! in Theta(n^n)`
  3. The divide and conquer algorithm for the maximum sub-array problem was `o(n log n)`.

The Recursion Tree Method

Recursion Tree Example

Recursion Tree for example Below

More on the example

The Master Method

Master Theorem

Let `a ge 1` and `b > 1` be constants, let `f(n)` be a function, and let `T(n)` be defined on the nonnegative integers by the recurrence
`T(n) = aT(n/b) + f(n)`, where we interpret `n/b` to mean either `lfloor n/b rfloor` or `|~n/b~|`. Then `T(n)` has the following asymptotic bounds:

  1. If `f(n) = O(n^(log_b a - epsilon))` for some `epsilon > 0`, then `T(n) = Theta(n^(log_b a))`.
  2. If `f(n) = Theta(n^(log_b a))`, then `T(n) = Theta(n^(log_b a)log n)`.
  3. If `f(n) = Omega(n^(log_b a + epsilon))` for some `epsilon > 0`, and if `af(n/b) le c f(n)` for some constant `c <1` and all sufficiently large `n`, then `T(n) = Theta(f(n))`.

Remarks on the Master Theorem

Examples Using the Master Method

Heaps

An example of a heap binary tree

Max/Min Heaps