MATH 302 Lecture 17

From Notes
Jump to navigation Jump to search

« previous | Wednesday, October 26, 2011 | next »


Chapter 8.3: Divide and Conquer Algorithms

Examples:

  • Binary Search on Sorted List:
  • Merge Sort:
  • Recursive Max/Min of Unsorted List:
  • Multiplying 2n-bit Numbers:

In general, form is:

Note: the book restricts the last term to powers of n

Master Theorem

The master theorem provides a general boilerplate solution for solving recurrence relations (like divide and conquer algorithms) that satisfy a particular format.

Definition

Let be an increasing function satisfying a recurrence relation:

Whenever

  • for some ,
  • is an integer > 1
  • and are real numbers ≥ 0

Then

Proof

Proposition. If and is a power of , then a function satisfying the recurrence relation is of the form


Proof. Let . Then


Counting

Product Rule

Suppose we have to make choices followed by choices. For example, selecting what to wear from shirts and pants. For each shirt you choose, there are possible pants to choose from. Therefore, the total number of choices is their product:

Addition Rule

When choices are independently selected. For example, when choosing a representative for a high school: there are freshmen, sophomores, juniors, and seniors. There are ways to choose a representative among all high school students.

Inclusion-Exclusion

Just like in statistics:

For example: How many bit strings of length either begin with 1 or end with 00?

  • There are bit strings that begin with 1
  • There are bit strings that end with 00
  • There are bit strings thta begin with 1 and end with 00

Therefore, there are bit strings that begin with 1 or end with 00.

Division Rule

How many 3-item subsets can be made from a set of elements?

There are ways to choose the first element, ways to choose the second element, and ways to choose the last element. Since the three elements can be rearranged in 3! = 6 ways, and inclusion in a set does not rely on the order, we divide the total number of ways to choose the set by 6:

Counting Functions

How many functions are there from {a, b, c, d} to {1, 2, 3}?

For each element in the domain (a, b, c, and d), there are 3 targets to choose from in the codomain. Therefore, the number of possible functions is 3 · 3 · 3 · 3 = 34

In general, for a domain containing items and a codomain containing items, the number of possible functions from the domain to the codomain is

One-to-One Functions

For a one-to-one function, once an element in the codomain has been chosen, it cannot be pointed to by any element in the domain. Therefore, the number of possible one-to-one functions is <math>c(c-1)(c-2)\dots(c-d+1) = \frac{c!}{(c-d)!}