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: Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle f(n) = f\left(\frac{n}{2}\right) + 2}
  • Merge Sort: Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle f(n) = 2 f \left( \frac{n}{2} \right) + n}
  • Recursive Max/Min of Unsorted List: Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle f(n) = 2 f \left( \frac{n}{2} \right) + 2}
  • Multiplying 2n-bit Numbers: Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle f(2n) = 3f(n) + c(n)}

In general, form is:

Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle f(n) = a f \left( \frac{n}{b} \right) + g(n) }
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 Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle f} be an increasing function satisfying a recurrence relation:

Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle f(n) = af\left(\frac{n}{b}\right) + cn^d}

Whenever

  • Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle n=b^k} for some , Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle a \ge 1}
  • 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, Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle n-1} ways to choose the second element, and Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle n-2} 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:

Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle \frac{n(n-1)(n-2)}{3}= \binom{n}{3}}

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 Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle d} items and a codomain containing Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle c} items, the number of possible functions from the domain to the codomain is Failed to parse (MathML with SVG or PNG fallback (recommended for modern browsers and accessibility tools): Invalid response ("Math extension cannot connect to Restbase.") from server "https://wikimedia.org/api/rest_v1/":): {\displaystyle c^d}

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)!}