Вы находитесь на странице: 1из 2

CSE 450/551: Review Quiz

Prof. Andréa W. Richa


1. Solve the following recurrence relations (using substitution, recursion tree, or the Master
method):

(a) T (n) = 2T (n/2) + n, where T (1) = 1


(b) T (n) = T (n − 1) + 1, where T (1) = 2
(c) T (n) = T (n/2) + 1, where T (1) = 1

2. Sort the following functions in nondecreasing order with respect to their asymptotic order of

growth (Big-Oh notation): 2n , log n + 1/n, 1/n, 100n2 + n − 1, n3 /2 + log n, 2log n , n, nlog n .
Use the notation O(f (n)) < O(g(n)) to denote that the asymptotic order of growth of f (n)
is strictly less than that of g(n), and O(f (n)) = O(g(n)) to denote the order of growth of
f (n) and g(n) are the same. For example, the ordering of the functions 1, n + 1, 10 and n5
is O(1) = O(10) < O(n + 1) < O(n5 ).

3. Write pseudocodes for the following sorting algorithms. Also give and solve the recurrence
relations that express the running time of these algorithms. Express the final formula you
obtained for the running time of these algorithms in big-Oh notation.

(a) Quicksort
(b) Mergesort

1
4. Do a depth-first search and a breadth-first search on the graph below. Assume that your graph
is represented using adjacency lists, which are all ordered in alphabetical order. Assume that
the nodes are considered as possible roots for the depth-first or breadth-first trees, respectively,
also in alphabetical order.
Give pseudocodes for both depth-first and breadth-first procedures, explaining briefly the
main differences in these two graph search procedures. What is the asymptotic running time
of these two procedures in terms of the number of nodes, n, and the number of edges, m, in
the graph?

5. Give the pseudocode and running time for Dijsktra’s shortest-path algorithm. Does Dijkstra’s
algorithm work on a graph with negative edge weights?

6. Is a minimum spanning tree always a shortest path tree (or vice-versa)? Give a minimum
spanning tree and a shortest path tree rooted at node a for the graph below.

7. Build a balanced binary search tree contains elements indexed by the keys n, n − 1, ..., 2, 1,
where n is a positive integer. What is the height of your tree?

Вам также может понравиться