You are on page 1of 1

CS 218M Tutorial-1

1. Assume you have functions f and g such that f (n) is O(g(n)). For each of
the following statements, decide whether it is true or false and give a proof
or counterexample.
2f (n) is O(2g(n) ).
f (n)2 is O(g(n)2 ).
2. Show the following:
If T (n) 3.T (n/2) + O(n), then T (n) is O(nlog2 3 ).
If T (n) 2.T (n/2) + O(n2 ), then T (n) is O(n2 ).
3. Let G be a graph stored in the adjacency list representation and v be a vertex
of G. Let H be the graph obtained from G by deleting the vertex v. Design
an O(n + m) time algorithm to compute the adjacency list representation
of H.
4. Fibonacci numbers are defined by the recurrence: F0 = F1 = 1 and Fn =
Fn1 + Fn2 for n 2. Consider the following natural strategies for computing Fn and analyze them for the asymptotic growth of the number of
arithmetic operations.
An obvious recursive algorithm.
Maintain an array F [0..n] and fill in the entries through a single scan.
Show how Fn can becomputed
 using O(log n) arithmetic operations. (Hint:
0 1
consider the matrix
).
1 1
5. Given a sequence of n numbers a1 , a2 , . . . , an , find for each number ai the
smallest index j such that j > i and aj < ai (such a j may not exist). Show
how this can be done in O(n) time.
6. Show that any comparison based sorting algorithm requires at least log(n!)
comparisons.
7. You are given as input a sorted array A of n distinct integers, and a number
M which is known to exist in A. Your objective is find the index of M in
A. In order to do this, you are allowed to probe the array A at any index.
A probe at index i is declared bad if A[i] M .
The standard binary search algorithm finds the index of M using log(n)
probes. Show that, in general, all the probes used by the binary search
algorithm could be bad. Design an algorithm which uses at most one bad
probe and a linear (that is, O(n)) number of probes. Now suppose that you
are allowed to use at most two bad probes. Describe a strategy for finding
the index M using at most f (n) probes, for some function f (n) that grows
slower than the linear function. More precisely, it should be the case that
limn f (n)/n = 0.

You might also like