CSCE 411 Lecture 5
« previous | Wednesday, September 5, 2012 | next »
Example Limit Superior
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) &= n^2 + (-1)^n \, n^2 + n \\ g(n) &= n^2 \\ \limsup_{n\to\infty} \frac{|f(n)|}{|g(n)|} &= 2 \end{align}}
Therefore 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) \in O(g(n))}
Divide and Conquer
- Divide a problem into subproblems
- Recursively solve subproblems
- Combine solutions to subproblems to get solution to original problem
Example: Merge-sort
- Divide the input in half
- Recursively sort the two halves (basis is a sequence with 1 key)
- Combine two sorted subsequences by merging them
Recurrence Relation
How long does Merge-sort take?
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 T(n)} be the worst-case time on a sequence 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 n} keys.
If , then (constant)
If , then (2 × time of solving each half and then the merge)
Two ways to solve:
- Expand several times, guess pattern, and try to prove by induction. (hard!)
- Master theorem
Using the master theorem, and . Therefore,
Master Theorem
(See Master Theorem→)
Given a recursive function (recurrence relation) of the form
Let . This represents the number of "leaf operations" in the divide-and-conquer tree
- If 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) << g(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 T(n) = \Theta(g(n))}
- If 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) \approx g(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 T(n) = \Theta(g(n)\log{n})}
- If 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) >> g(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 T(n) = \Theta(f(n))}
Other D&C Algorithms
- Mathematics
- Converting Binary to Decimal
- Integer Multiplication
- Matrix Multiplication
- Matrix Inversion
- Fast Fourier Transform