CSCE 222 Lecture 25

From Notes
Jump to navigation Jump to search

« previous | Wednesday, April 6, 2011 | next »


Divide and Conquer

Example

Multiplication of Integers

In binary form, two number 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} 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 b} consist of 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 2n} bits. Each integer can be rewritten as a sum of two 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} -bit integers that represent the most and least significant bits.

Let be the total number of bit operations needed to multiply two -bit integers. In this case, .

Bitwise Shift Operator

a >> n shifts the binary digits of places to the right (essentially multiplying by ).


Master Theorem

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 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} is a power of 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 b} , then a function 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} satisfying the 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(n/b) + cn^d} is of the form 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(1)n^d+cn^d\log_b{n}}


Proof. 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 k = \log_b{n}} . Then

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 \begin{align} f(n) &= cn^d + ac\left(\frac{n}{b}\right)^d+a^2c\left(\frac{n}{b^2}\right)^d+\dots+a^{k-1}c\left(\frac{n}{b^{k-1}}\right)^d+a^kf(1) \\ &= a^k f(1) + \sum_{j=0}^{k-1} a^jc\left(\frac{n}{b^j}\right)^d \\ &= a^k f(1) + \sum_{j=0}^{k-1} cn^d \\ &= a^k f(1) + kcn^d \\ &= a^{\log_b{n}} f(1) + c(\log_b{n})n^d \\ &= b^{d\log_b{n}} f(1) + c(\log_b{n})n^d \\ &= n^d f(1) + c(\log_b{n})n^d \\ &= O(n^d \log{n}) \end{align}}