CS510: ANALYSIS of
ALGORITHMS
Kalamazoo
College
Spring 1998
Divide and Conquer Summary
To use divide and conquer as an algorithm design technique, we must divide
the problem into two smaller subproblems, solve each of them recursively,
and then meld the two partial solutions into one solution to the full
problem. Whenever the merging takes less time than solving the two
subproblems, we get an efficient algorithm.
Examples -
- Merge Sort
Classic example of a divide-and-conquer algorithm.
It takes only linear time to merge two sorted lists of n/2 elements each of
which was obtained in O(n) time.
- fast Fourier transform
- Strassen's matrix multiplication algorithm
- Fast Exponentiation
- Binary Search
fast algorithm for searching in a sorted array S
of keys. To search for key q, we compare q to the middle key S[n/2]. If
q appears before S[n/2], it must reside in the top half of our set; if
not, it must reside in the bottom half of our set. By recursively
repeating this process on the correct half, we find the key in a total of
O(lg n) comparisons.
Applications include 20 questions, finding a point of transition.
- Square and Other Roots
Uses the bisection method to find the solutions to
a given equation. We say that x is a root of the function f if f(x) = 0.
Assume that l is a value so that f(x) < 0 and r is a value so that f(x) > 0.
solve (f(x), l, r)
let m = (1+r)/2
let val = f(m)
if (ABS(val) < TOL) return m
if (val < 0) solve (f(x), m, r)
else solve (f(x), l, m)
Complexity of O(lg n). This algorithm can be made faster
by interpolation on the interval to find a test point closer to the actual
root.
Exercises from Chapter 3
Kelly Schultz, Kalamazoo College