|
CSE Home | About Us | Search | Contact Info |
P = 1 x 3 + 1 x 2 + 1 x + 1
Q = 2 x 3 - 3 x 2 - 4 x + 5
M(1) = c, andShow that the solution to this recurrence is O(nlog27), (log27 = 2.81...). Assume that n is a power of 2. Use the "tree" method shown in lecture and on the slides.
M(n) = 7 M(n/2) + c n2 for n > 1.
The following identities that you've probably seen before might be useful:
1 + x + x2 + x3 + ... + xk = (xk+1 - 1)/(x - 1) for any x != 1, and
alogbn = (blogba)logbn = (blogbn)logba = nlogba,
Input: an unordered list of triples (xl, xr, h), where 0 < xl < xr and 0 < h.
Problem: Each triple describes a rectangle of height h whose base is on the x axis, and whose left and right sides are at positions xl and xr, respectively. Imagine that each rectangle is opaque, and that the whole collection is illuminated from behind. The problem is to calculate the silhouette of the set of rectangles - a description of the visible edges in the resulting scene. (This is a very simple case of what's called hidden line elimination in computer graphics.)
Output: A list of pairs (xi,yi), ordered by increasing xi, of the coordinates of points where the height of the silhouette changes.
Example: Given input:
(1,2,1) (10,12,2) (2,4,1) (5,8,3) (3,6,4)the output should be:
(0,0) (1,0) (1,1) (3,1) (3,4) (6,4) (6,3) (8,3) (8,0) (10,0) (10,2) (12,2) (12,0) (infinity,0).
INPUT OUTPUT . +--------+ . +--------+ | | . | | | | . | | | +--+-----+ . | +-----+ | | | | . | | | | | | . | | | | | | +----+ . | | +----+ | | | | | | . | | | | | | | | | | . | | | | +--+--+--+ | | | | | . +-----+ | | | | | | | | | | | | . | | | | | | | | | | | | | . | | | | +--+--+--+--+--+--+-----+-----+----+------ . +--+ +-----+ +------ 0 1 2 3 4 5 6 7 8 9 10 12 0 1 2 3 4 5 6 7 8 9 10 12Give a brief English description of your algorithm, plus pseudocode for it. Give a recurrence relation for its running time and solve it. (If the recurrence is one we solved in class, just state that and give the solution; otherwise, justify your solution.)
Partial credit for correct but non-divide-and-conquer solutions.
(Extra Credit) The following recurrence generalizes all of the recurrences for divide and conquer algorithms we've seen so far, and many others.
T(1) = c, andShow, for any positive integers a, and c, any k ≥ 0, and any integer b ≥ 2, that its solution is:
T(n) = a T(n/b) + c nk for n > 1.
Loosely speaking, it says that if the number of subproblems is large in comparison to the other parameters, then the work at the leaf level of the recursion tree dominates the run time (case a); if the number of subproblems is small, then the work at the root level dominates (case b), and at the critical in-between value, all levels contribute equally (case c).
Computer Science & Engineering University of Washington Box 352350 Seattle, WA 98195-2350 (206) 543-1695 voice, (206) 543-2969 FAX [comments to cse417-webmaster@cs.washington.edu] |