Analysis of Algorithms Concept Exam Code: 16 All questions are weighted equally. Assume worst case behavior and sufficiently large input sizes unless otherwise specified. Strong induction Consider this statement: n ( 1) i i = ( 1) n i=1 n (n + 1), for n 1. Consider a proof, by strong induction and using Lusthian style, to show that the above statement is true. 1. What would we need to prove for the base case, assuming we wish to have only one base case? (A) ( 1) 0 0 = ( 1) 0 1 (1+1) (B) ( 1) 0 0 = 0 (C) 0 (0+1) = 0 (D) 1 (1+1) = 1 (E) ( 1) 1 1 = 1 1 (F) ( 1) i i = ( 1) 1 i=0 (G) ( 1) 1 1 = ( 1) 1 1 (1+1) 1 (1 + 1). What would the inductive hypothesis be, assuming b is the largest base case value? (A) Assume true for b n (B) Assume true for b (C) Assume true for b < k < n (D) Assume true for b < n (E) Assume true for b k < n (F) Assume true for n (G) Assume true for b k n (H) Assume true for b < k n. If the first line of the inductive case sets up the inductive step, then the right-hand side of the second line (which shows the inductive step that was taken) should be: n (A) = ( 1) n+1 (n + 1) + i n+1 (F) = ( 1) 1 1 + i i=1 (B) = ( 1) n+1 (n + 1) + n (n+1) (C) = n (n+1) + (n 1) ((n 1)+1) (D) = ( 1) n n + ( 1) n 1 (n 1) ((n 1)+1) n (E) = ( 1) 1 1 + i i= i= n 1 (G) = ( 1) n n + i=1 i (H) = (n+1) ((n+1)+1) + n (n+1) Master recurrence theorem. In terms of the master recurrence theorem as described in Cormen, et al., where does the equation T (n) = 5T ( n 5 ) + n log n fall? (A) case (B) case 1 (C) the equation is not in the correct form (D) case (E) between case and case (F) between case 1 and case 5. In terms of the master recurrence theorem as described in Cormen, et al., where does the equation T (n) = 5T ( n ) + n log n fall? The log (base 5) of is ~ 0.68. The log (base ) of 5 is ~ 1.65. (A) between case 1 and case (B) the equation is not in the correct form (C) case (D) case (E) case 1 (F) between case and case
6. In terms of the master recurrence theorem as described in Cormen, et al., where does the equation T (n) = 9T ( n ) + n log n fall? (A) case (B) between case and case (C) case 1 (D) between case 1 and case (E) the equation is not in the correct form (F) case 7. In terms of the master recurrence theorem as described in Cormen, et al., where does the equation T (n) = T ( n ) + 1 fall? (A) case 1 (B) between case and case (C) between case 1 and case (D) case (E) case (F) the equation is not in the correct form 8. Consider using the master recurrence theorem to solve the equation T (n) = T ( n ) + n. What is the smallest listed value of ϵ that can be used in the solution? The log (base ) of is ~ 1.585. The log (base ) of is ~ 0.61. (A) the master theorem cannot be used (B) ϵ is not used in the solution (C) 0. (D) 0 (E) no legal value is listed (F) 0.6 9. Consider using the master recurrence theorem and the regularity condition for case to solve the equation T (n) = T ( n ) + n. What is the smallest legal value of the constant c listed for the solution? Useful numbers: log 0.79 log 1.6 6 ~ 0.069 ~ 1. 0.75 9 ~ 0. 16 0.1875 7 ~ 0.18 (A) no legal value is listed (B) 0.10 (C) 0.15 (D) 0.075 (E) case does not apply Self-balancing trees References to binary search trees, red-black trees, and AVL trees refer to typical implementations, unless otherwise specified. For red-black trees, null pointers are not considered nodes but do have a color (black). In a red-black tree, all nodes being inserted start out red. The length of a path in a tree is the minimum number of steps from the starting vertex to the ending vertex. The depth (or height) of a tree is the length of the path from the root to the furthest leaf. 10. Consider a right-rotation of a node n upwards in a BST. The former left child of n, assuming it exists: (A) remains the left child of n (B) becomes the niece or nephew of n (C) becomes a child of the former parent of n (D) becomes the right child of n (F) becomes a sibling of n 11. Suppose you allowed, at most, two red nodes in a row on any path from an interior node to a leaf in a red-black tree (as opposed to a standard red-black tree where you can have, at most, one red node in a row). Suppose further that all leaves in the tree are black. Of the answers listed, what is the tightest upper bound on the ratio of the longest path from the root to a leaf and the shortest path from the root to a leaf. Also, will searches and insertions would still take O(log n) time? (A), yes (B), yes (C), no (D), yes (E), no (F) infinity, no (G) none of the other answers are correct (H), no
1. The number of node recolorings that occur after an insertion into a red-black tree is: (A) Θ(1) (B) Θ(n) (C) Θ(log n) (D) Θ(n log n) 1. Consider a red-black tree with a perfect binary tree shape, that has an odd-numbered depth (e.g. depth is 11), and that has a maximum number of red nodes. Which of the following is a constraint on this tree, where B is the number of black nodes and R is the number of red nodes? (A) B = R (B) B = R (C) B = R (D) none of the other answers are correct (E) B + 1 = R (F) B = R + 1 (G) B = R + 1 (H) B = R + 1 1. What is the minimum number of operations that can yield an all-black red-black tree that has more than one node? Also, what are those operations (listed in order from first to last) (A) (insert, insert, insert) (B) (insert, insert) (C) (insert, insert, insert, insert) (insert, insert, insert, insert, delete) (E) 6 (insert, insert, insert, insert, delete, delete) (F) 6 (insert, insert, insert, delete, insert, delete) (G) 5 (insert, insert, insert, delete, delete) (H) (insert, insert, insert, delete) 15. Inserting the integers 1,,, 5, and into an empty red-black tree, in the order given, yields how many recolorings, single rotations, and double rotations, respectively? Don t forget to color the root black, if need be. (A) 8, 1, 1 (B) 7, 1, 1 (D) 9,, 0 (E) 9, 0, (F) 9, 1, 1 (G) 8,, 0 (H) 8, 0, 16. The worst case number of rotations that occur after an insertion into an AVL tree is: (A) Θ(1) (B) Θ(log log n) (C) Θ(n) (D) Θ(log n) 17. Consider an AVL tree having a root whose left side has nodes. What is the most number of nodes that can appear on the right side? (A) 15 (B) 16 (C) 11 (D) 8 (E) 7 (F) 1 (G) none of the other answers are correct 18. Consider a node n with two children in an AVL tree. If one of the children is a leaf, what is the most number of descendants the parent of n can have? (A) 15 (B) 1 (C) 0 (F)
19. Consider inserting the following numbers, in the order given, into an empty AVL tree: 1 7 8 5 9 6 Which insertion causes the first double rotation? (A) (C) (D) 7 (E) there are no double rotations (F) 6 (G) 1 Binomial heaps Assume min-heaps unless otherwise directed. When inserting into a binomial heap, the node to be inserted node is placed at the far left of the root list. During the extractmin operation, child lists are placed at the far right of the root list (in increasing degree order). Consolidation moves along the root list from left to right. After consolidation, the root list is ordered in increasing degree order. 0. Consider inserting the following values, in the order given: 9 8 5 6 1 7 0 into an empty binomial heap. After deleting the value 5, the value 6 is found in a subheap whose root has which value? (B) 1 (C) (D) none of the other answers are correct (E) (F) 7 (G) 6 (H) 1. Consider inserting the consecutive integers from 0 to 1, inclusive and in increasing order, into an empty binomial heap. After an extractmin operation, followed by deleting the value 5, the value 8 can be found in the subheap whose root has value: (C) (D) 6 (E) 1 (F) 0 (G) (H). Consider inserting the consecutive integers from 0 to 16, inclusive and in the order given, into an empty binomial heap. After four extractmins, how many subheaps are in the root list? (A) (B) 1 (C) 6 (F) 7 (G) (H). Consider inserting the consecutive integers from 1 to 1, inclusive and not necessarily in order, into an empty binomial heap. After all the insertions, what is the largest possible root value of the largest heap in the root list? (A) 6 (C) 8 (D) 7 (E) 9 (F) 1 (G) 11 (H) 10
. Consider inserting the consecutive integers from 1 to 1, inclusive and not necessarily in order, into an empty binomial heap. After all the insertions, what is the second largest possible root value of the largest heap in the root list? (A) 6 (B) 11 (C) 10 (D) 7 (E) 9 (F) none of the other answers are correct (G) 1 (H) 8 Fibonacci heaps Assume min-heaps unless otherwise directed. When inserting into a Fibonacci heap (including cut nodes), the node to be inserted node is placed at the far left of the root list. During the extractmin operation, child lists are placed at the far right of the root list (in increasing degree order). Consolidation moves along the root list from left to right. After consolidation, the root list is ordered in increasing degree order. 5. After seven consecutive inserts into an empty Fibonacci heap, how many subheaps are in the root list? (A) (B) 8 (C) (E) (F) 1 (G) 6 (H) 7 6. Consider a series of consecutive insertions into an initially empty Fibonacci heap. What is the worst-case and average cost, respectively, of a single insertion? (A) none of the other answers are correct (B) log and log (C) constant and log linear (D) constant and constant (E) constant and linear (F) log and log linear (G) constant and log (H) log and linear 7. Consider inserting the consecutive integers from 0 to 1, inclusive and in increasing order, into an empty Fibonacci heap. After an extractmin operation, followed by an 8-to-0 decreasekey operation, followed by another extractmin, the value 7 can be found in the subheap whose root has value: (A) none of the other answers are correct (B) (C) 7 (D) (E) 6 (F) 5 (G) 1 (H) 8. For a Fibonacci heap, what is the smallest possible number of nodes in a subheap of degree 6? Hint: look at smaller degreed subheaps and extrapolate. (A) 0 (C) 8 (D) 6 (E) 7 (F) 6 (G) 1 (H) 1 When cutting a node out of a Fibonacci subheap, the degree of the parent is decremented. In addition, the parent of the node (unless it is a root) is either marked, if it hasn t been previously marked, or cut, if it has. Root nodes are never marked. 9. What is the most number of nodes that can be cut in a single cascade when a leaf is cut in a subheap that starts out with degree 5? Include the leaf in your count. (B) 8 (C) (D) 1 (E) 7 (F) (G) 6 (H) 5
Disjoint sets The following questions assume a tree implementation of a disjoint set. Assume each value has a pointer to its parent with the root of the tree serving as the representative of the set. When performing a union between two trees of equal rank, assume the smaller valued root becomes the parent of the larger valued root. Assume path compression and union-by-rank unless specified otherwise. 0. The find-set operation (with path compression but no union by rank) takes a worst case time of: (A) θ(n ) (B) θ(log n) (D) θ(1) (E) θ(n) (F) θ(n log n) 1. Assuming n values, no path compression, and no union by rank, the total work of a series of m disjoint set operations is: (A) θ(n log m) (B) θ(m log n) (D) θ(m) (E) θ(nm) (F) θ(log n) (G) θ(1) (H) θ(n). Theoretically speaking, with path compression and union by rank, the total work of a series of m disjoint set operations is: (A) logarithmic (B) quadratic (C) log linear (D) linear (F) constant. Suppose one performs a series of n make-set operations followed by enough union operations so that a single set remains. What is the fewest number of union operations to achieve this result? Assume n is a power of two. (A) n + 1 (B) log n (C) n 1 (D) n (E) n (F) none of the other answers are correct For the following set of questions, consider the following sequence of operations: for each i in 0..10 do make-set(i) union(1,); union(,8); union(0,); union(,); union(5,6); union(,7) union(5,7); union(9,7); find-set(1); find-set(); union(8,6);. Immediately after the union(5,7) operation, how many nodes in the tree rooted by 1 s representative are more than one step away from the root? (A) none of the other answers are correct (B) (C) 5 (D) 1 (E) (F) 5. Immediately before the first findset operation, how many children does s representative have? (B) 1 (C) (D) none of the other answers are correct (E) (F) 6
6. After all operations, how many nodes do not have a root as a parent? (B) (C) (D) (E) 0 (F) 1 Graphs Assume graphs are simple, undirected, and connected unless otherwise specified. The length of a walk, tour, path, or cycle is the number of edges on that walk, tour, path, or cycle. 7. The degree of a vertex is count of edges that connect it to other vertices (i.e. the incident edges). The min-degree of a graph is the degree of the vertex with the least number of incident edges. Consider a graph with 6 vertices and 11 edges. What is the smallest min-degree possible in a graph with those vertex and edge counts? (A) (B) (C) 6 (E) (F) 1 8. The longest possible walk, tour, path, and cycle, respectively, in a graph with V vertices and E edges is: (A) infinite, infinite, infinite, infinite (B) V+E, E, V, V+1 (D) infinite, E+V, V-, V-1 (E) V+E, E, V, V+1 (F) V+E, E, V-, V-1 (G) infinite, E, V, V+1 (H) infinite, E, V-1, V 9. What is the primary characteristic of a complete graph? Choose the most specific answer. (A) each vertex has two edges or no edges (B) there exists a path between every pair of vertices (C) all vertices have a degree greater than some threshold (D) there exists an edge between every pair of vertices 0. T or F: If a graph has a cycle, it must have a Hamiltonian cycle. 7