

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!


UC Berkeley—CS 170: Efficient Algorithms and Intractable Problems Handout Midterm 1 Solutions Lecturers: Christos Papadimitriou and Umesh Vazirani
The pre and post numbers should have been the following: A(1,10), B(11,18), C(13,14), D(2,9), E(3,6), F(12,17), G(7,8), H(4,5), I(15,16). We have 5 strongly connected components:
G H I
A,D,E B,C,F
Notes number Midterm 1 Solutions 2
n (^2) = −1. What allows us to keep dividing the problem is that the squares of these points maintain this property. Specifically, if ω is an nth^ root of unity, then ω^2 is an (n/2)th^ root of unity. The inverse can also be done with an FFT using ω−^1 since 1 + ω + ...ωn−^1 = 0. (If you had all of this, you got more than 5 points).
If we begin our search at A, proceed to B, and then to C, the edge (C, B) is a cross edge. (b) FALSE.
If we begin at A, then the only edge is a tree edge.
First consider the naive algorithm: sequentially check each element. This takes linear time. Our divide and conquer algorithm should try to beat this. Let us first examine the middle element. If its value matches its index in the original array, we’re done. If it is bigger than its index, then every subsequent element will also be bigger than its index since the array values grow at least as fast as the indices. Similarly, if it’s less than its index, then every previous element in the array will be less than its index by the same reasoning. So after the comparison, we only need to examine half of the array. We can recurse on the appropriate half of the array. If we continue this division until we get down to a single element and we still have not found our desired element, then it is not possible. Find(A,x) // A is the array, x is the offset from the original array mid = length(A)/ if (A[mid] = mid+x) then return TRUE