CS101 Spring 2003 - Final Review Sheet 1. (1 point each) State whether the following are true or false. Justify your answers. a. n O(n 2 ) b. n10 (2 n ) c. o( g (n)) O( g (n)) for any function g (n) . d. If the limit L lim ( f (n) / g (n)) exists and 0 L , then f (n) ( g (n)) . n e. 1/ n O(1/ n 2 ) f. 4lg n (8lg n ) g. lg n o( n ) h. (n 1)! (n!) i. lg n (ln n) j. 3lg n (3ln n ) 2. (10 points) Use the Master Theorem to give an asymptotically tight estimate for the solution to the recurrence T (n) 9T (n / 3) n 2 . 3. (10 points) Given a linked list structure in which each list node x contains a key field key[x] , and a pointer to the next element next[x ] , write a recursive algorithm called ReversePrint that prints out the keys in reverse order. Your algorithm will take a single argument which is a pointer to a node in the list. For instance, given the following list L, head[L] 1 2 3 4 5 / the call ReversePrint(head[L]) would print: 5 4 3 2 1. Write you algorithm in pseudo-code (i.e. use the conventions spelled out in section 2.1), not java or C. 4. State the following properties: a. (5 points) The Heap property: b. (5 points) The Binary Search Tree properties: c. (5 points) The Red-Black Tree properties: 5. Trace Depth First Search on the following directed acyclic graph. Process the vertices in numerical order in line 5 of DFS, and line 3 of DFS-VISIT (see reference sheet). 1 2 5 8 3 4 6 9 7 10 11 a. (5 points) Draw the DFS forest associated with this graph. b. (5 points) Fill in the following table of discovery and finish times. Vertex 1 2 3 4 5 6 7 8 9 10 11 Adjacency List Discover Time Finish time c. (5 points) Determine the classification of each edge in the graph and fill in the table below. How can we be sure that the graph is acyclic? Edge (1, 5) (1, 6) (1, 8) (2, 3) (2, 5) (2, 9) (3, 6) (3, 7) (3, 10) (4, 3) (4, 7) (5, 8) (6, 9) (7, 6) (9, 10) (10, 11) (11, 8) Classification 6. Briefly describe the Weighted Union heuristic used by the linked list representation of a disjoint set data structure. Also describe the Union by Rank and Path Compression heuristics used by the disjoint set forest implementation of a disjoint set data structure. a. (5 points) Weighted Union b. (5 points) Union by Rank: c. (5 points) Path Compression: 7. Trace Dijkstra’s algorithm on the following weighted directed graph with 1 as the source vertex. 2 1 4 2 1 1 3 4 1 3 a. (10 points) Complete the following table giving the d-values for each vertex after each iteration of the while loop 4-8. Vertex 1 2 3 4 Initialize 0 d-values after iteration # 1 2 3 4 b. (10 points) Draw the predecessor subgraph after initialization, and after each iteration of the while loop 4-8. 8. Suppose that we have numbers between 1 and 1000 in a binary search tree and want to search for the number 572. Determine whether each of the following sequences could be the sequence of keys examined. If your answer is no, clearly explain why. a. (5 points) 201, 357, 919, 400, 451, 499, 670, 572 b. (5 points) 157, 580, 217, 378, 445, 570, 591, 572 9. (10 points) Draw the result of executing RB-INSERT(T, 2) on the Red-Black Tree below. 4 Black 3 Black 1 Red nil 5 Black nil nil nil nil 10. (10 points) Show that the longest simple path from a node x 0 in a Red-Black tree to a descendant leaf has length at most twice that of a shortest simple path from x 0 to a descendant leaf. 11. (15 points) Recall the recursive definition of a Complete Binary Tree: T consists of either (1) a single root node, or (2) a root node connected to the roots of two (identical) complete binary trees Tl and Tr called the left and right subtrees, respectively. Let N (T ) denote the number of nodes in T, and H (T ) the height of T. Prove by induction on the height H (T ) that N (T ) 2 H (T )1 1 . Clearly state your assumption in the induction step. H (T ) H (Tl ) 1 H (Tr ) 1 if H (T ) 0 . I. Basis: Suppose H (T ) 0 . II. Induction: Suppose H (T ) 0 , and assume: You may use without proof the fact that Some additional problems from the book: 13.1-5 13.1-6 13.3-2 7.1-1 8.2-1
© Copyright 2026 Paperzz