


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



The midterm will be open notes, open book.
These questions are a little harder than the ones that will be on the midterm.
You should also go over all the algorithms and analyses we did in class and make sure you understand the steps, and go over the homework solutions for homeworks 1 and 2 and make sure you understand them (although you would be safe to assume that Pr. 1 from HW 1, and Pr. 4 from HW 2, are both difficult enough that they are unlikely to appear on the midterm....). Know the definition of the expectation of a random variable, a universal hash function, and big-O and big-Ω. Be sure you can do a proof by substitution to show that a function T (n) is big-O of some other function f (n). Be sure you know where to find important formulas in your notes or in the book.
b) How many possible sequences of four numbers can be produced by the four rolls? Position matters, that is, 2, 3 , 2 , 2 is different from 2, 2 , 3 , 2.
b) Write down a recurrence relation describing the running time T (n) to find the clos- est red-blue pair in the set P.
c) Give the best solution you can for this recurrence relation, and prove it by substi- tution. By “best” here, we mean the smallest upper bound possible. Hint: You might want to look at the subsection titled “Subtleties” in Section 4.1.
Consider a function very like the one we used as part of the universal hash function, f (x) = (ax + b) mod n. Here n is the size of array A, a is chosen randomly from { 1 ,... n − 1 } and b is chosen randomly from { 0 ,... , n − 1 }. When n is prime, we could use f () to produce a permutation B of A as follows:
for i = 0 to n − 1 B[f (i)] = A[i]
Prove that when n is prime, B is a permutation of A. Hint: Prove that if i 6 = j, then f (i) 6 = f (j). Why would this imply that B is a permutation of A?
Assume that n is prime. How many permutations of A can be produced by this function?
Does this function produce every possible permutation of A?