hw3 - x into S only if it is not already there Delete S x...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
Homework 3 Due: Tuesday, March 9 1. Show the red-black trees that result after successively inserting the keys 9,7,5,2,3,1 into an initially empty red-black tree and then deleting 1,2,3,5,7,9. 2. Let A [1 ,n ] be an array of real numbers. Design an algorithm to perform any sequence of the following two operations: Add ( i, x ): add the value x to A [ i ]. PartialSum ( k ): return the sum of the Frst k numbers, k i =1 A [ i ]. Notice that the number of elements remains Fxed (there are no insertions or deletions); the only changes are to the values. Each operation should take O (log n ) time. You can use an extra work space of size n . 3. Design an implementation of a data structure S that supports the following operations: Insert ( S, x ): insert the key
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: x into S only if it is not already there. Delete ( S, x ): delete the key x from S (if it is there). FindSmallest ( S, k ): Fnd the k-th smallest key in S . All these operations should take O (log n ) time in the worst case, where n is the number of elements in S . 4. Let H be a universal family of hash functions mapping [ n ] = { , 1 , . . . , n-1 } to [ m ] = { , 1 , . . . , m-1 } . ±ind the most general relation of m and n that guarantees the existence of a hash function in H that causes no collision when hashing [ n ] into [ m ]. (Hint: Consider that the probability of a random hash function from H causing some collision is strictly less than 1.) 1...
View Full Document

This note was uploaded on 02/27/2010 for the course ECE 544 taught by Professor Ray during the Spring '10 term at Rutgers.

Ask a homework question - tutors are online