Homework 0 CSE 101
Homework 0 CSE 101
Winter 2015
This homework is due Friday January 9th at the start of class. Remember to justify your work even if
the problem does not explicitly say so. Writing your solutions in LATEXis recommend though not required.
Question 1 (Program Runtimes, 20 points). Consider the following programs:
Alg1(n):
For i = 1 to n
j = 1
while i+j < n
j = j+1
Alg2(n):
For i = 1 to n
j = 1
while i*j < n
j = j+1
For each of these algorithms, compute the asymptotic runtime in the form ().
Question 2 (Big-O Computations, 20 points). For each of the following functions, determine whether or
not the expression in question is (nc ) for some constant c, and if so determine the value of such a c.
Remember to justify your answer.
a(n) =
n2
7
+ 21 + log(n)
b(n) = n + (n 1) + (n 2) + . . . + 1
c(n) = 3dlog2 (n)e
d(n) = blog2 (n)c!
e(n) = 2n
Question 3 (Cycle Finding, 30 points). Recall that a 4-cycle in a graph G is a collection of four vertices
v1 , v2 , v3 , v4 so that (v1 , v2 ), (v2 , v3 ), (v3 , v4 ) and (v4 , v1 ) are all edges of G.
(a) Show that if G is a graph with |E| 2|V |3/2 , that G must contain a 4-cycle. Hint: For each vertex
v V consider all the pairs (u, w) of vertices so that u and w are both adjacent to v. If the same pair
(u, w) shows up for two different vs, show that there is a 4-cycle.
(b) Find an efficient algorithm to determine whether or not a given graph G contains a 4-cycle. What is
the asymptotic runtime of this algorithm? You should attempt to do better than the trivial algorithm of
simply checking all quadruples v1 , v2 , v3 , v4 of vertices.
Question 4 (Recurrence Relations, 30 points). Consider the recurrence relation
T (1) = 1,
T (n) = 2T (bn/2c) + n.