CS511 – Graduate Algorithms Quiz 2 May 12, 2009 Answer all three questions. Total time: 2 hours Any violation of the following rules will get you a 0 in the quiz. • No textbooks are allowed. • Only notes/slides from the “lectures” page are allowed. • Turn your cell phones off. • Put your bags, belongings and cellphones in front of the class. • Do your rough calculations and thinking on the extra booklet. Only write your final answers neatly on the answer booklet. I will grade according to what I can read. 1
Q1. 1. A Fibonacci tree of order k , denoted F k , is defined recursively as follows: F 1 and F 2 are single nodes, and F k consists of an F k − 2 linked to an F k − 1 . Prove that for any node in a Fibonacci tree, height ( v ) = ⌈ degree ( v ) / 2 ⌉ . 2. Prove that only one subtree gets rebalanced in a scapegoat tree insertion. 10 + 10 points
Q2. The staircase of a set of points consists of the points with no other point both above and to the right. Describe a method to maintain the staircase as new points are added to the set. Specifically, describe and analyze a data structure that stores the staircase of a set of points, and an algorithm INSERT ( x, y ) that adds the point ( x, y ) to the set and returns TRUE or FALSE to indicate whether the staircase has changed. Your data structure should use O ( n ) space, and your INSERT algorithm should run in O (log n ) amortized time. 20 points
Q3. Suppose you are given an array of n numbers, sorted in increasing order. • Describe an O ( n )-time algorithm for the following problem: Find two numbers from the list that add up to zero, or report that there is no such pair. In other words, find two numbers a and b such that a + b = 0. • Describe an O ( n 2 )-time algorithm for the following problem: Find three numbers from the list that add up to zero, or report that there is no such triple. In other words, find three numbers a , b , and c , such that a + b + c = 0. 10 + 10 points
Recommend
More recommend