ps4sol - CS161: Design and Analysis of Algorithms Summer...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS161: Design and Analysis of Algorithms Summer 2004 Problem Set #4 Solutions General Notes Regrade Policy: If you believe an error has been made in the grading of your problem set, you may resubmit it for a regrade. If the error consists of more than an error in addition of points, please include with your problem set a detailed explanation of which problems you think you deserve more points on and why. We reserve the right to regrade your entire problem set, so your final grade may either increase or decrease. On problem 1(f), many people assumed that if the key [ y ] < key [ x ] then y was in the left subtree of x or that if priority [ y ] < priority [ x ] then y was a child of x . These stipulations are not true, since in either case you can also have y not be a descendant of x and the condition may still hold. Also, many people did not prove both the if and the only if parts of the statement. For augmented red-black trees in general, if the augmentation does not satisfy Theorem 14.1, you should show that it can be maintained efficiently through insertion, deletion, and rotations . On problem 5(b), a common mistake was to sort by the x indices, but to not take into account the order for equal x index. For equal x i s, you need to sort by decreasing index y j so that you can match at most one y j to each x i . 1. [34 points] Treaps Throughout this problem, please be as formal as possible in your arguments whenever asked to show or conclude some result. (a) [4 points] Do problem 13-4(a) on page 297 of CLRS. Answer: Our proof is inductive and constructive. The induction is on the number of elements in the treap. The base case of 0 nodes is the empty treap. We now suppose that the claim is true for 0 k < n nodes, and show it is true for n . Given a set of n nodes with distinct keys and priorities, the root is uniquely determined - it must be the node with the smallest priority in order for the min- heap property to hold. Now suppose this root node has key r . All elements with key < r must be in the left subtree, and all elements with key > r must be in the right subtree. Notice that each of these sets has at most n- 1 keys, and therefore has a unique treap by the inductive assumption. Thus, for the n-node treap, the root is uniquely determined, and so are its subtrees. Therefore, the treap exists and is unique. Notice this suggests an algorithm for finding the unique treap: choose the element with the smallest priority, partition the remaining elements around its key, and recursively build the unique treaps from the elements smaller than the root key Problem Set #4 Solutions 2 (these will go in the left subtree) and the elements larger than the root key (right subtree)....
View Full Document

This document was uploaded on 05/25/2011.

Page1 / 16

ps4sol - CS161: Design and Analysis of Algorithms Summer...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online