Student Name: COT 4400: Design and Analysis of Algorithms Final Exam Duration 90 minutes MAX POINTS = 70 points The exam is open notes, open books There are six problems, for a total of 70 points Show your work, as partial credit will be given 10 points Problem 1. Consider a matrix-chain product with the sequence of dimensions <3, 10, 4, 15, 8>. a) (7 pts) Fill out the empty spaces in the m and s tables below. Show your work. b) (3 pts) Show the printing of an optimal parenthesization. m 2 3 1 0 120 300 1 2 0 600 2 1 3 4 0 s 4 1 480 3 0 4 2 1 3 4 2 2 3 1 COT 4400: Design and Analysis of Algorithms 10 points Problem 2. Determine an optimal Huffman code (using binary strings) for a file F containing a set of characters with the following frequencies: m n p q r s Frequency 30 9 15 3 7 25 t 11 7 points a) Draw a Huffman tree based on the above frequencies. Show only the final tree. 3 points b) Show the Huffman code of each character, based on the Huffman tree above. m Frequency 30 Huffman codewords n 9 p 15 q 3 r 7 s 25 t 11 2 COT 4400: Design and Analysis of Algorithms 15 points Problem 3. Consider the following graph G: A B C D E F G H I (4 points) Show DFS applied to G. (3 points) Show a classification of the edges (4 points) Show DFS applied to GT. (2 points) Circle the strongly connected components (SCCs) you obtained. (2 points) Show the corresponding component graph. 3 COT 4400: Design and Analysis of Algorithms 10 points Problem 4. Find an MST using Prim’s algorithm, starting from the vertex a, for the following graph: 2 5 c a f 10 8 4 7 b 2 5 8 d e 2 s 10 g 4 (3 points) Darken the edges of the resulting MST. (2 points) List the order in which the vertices were extracted from the queue Q. (5 points) Show a table with values for v.key and v. for each v V, at each iterative step. 4 COT 4400: Design and Analysis of Algorithms 15 points Problem 5. We apply (trace) the Bellman-Ford algorithm on the following graph, where vertex s is the source: 1 c f 3 s 3 2 -5 g (8 points) Indicate the order of the edges that you used for relaxation: Show the v.d and v. values for each vertex v V, after each iteration of relaxations: 1 c f 1 c 3 3 s 3 s 2 3 2 -5 -5 g 1 c f g f 3 s 3 2 -5 g (2 points) Darken the shortest-paths tree. (5 points) Does the algorithm return TRUE or FALSE for our graph? If it returns FALSE, for which edges (u, v) does it satisfy the inequality “v.d > u.d + w(u,v)” ? 5 COT 4400: Design and Analysis of Algorithms 10 points Problem 6. We are given a graph G=(V,E) which is undirected. Design an O(V+E) algorithm to determine if the graph G is connected. Use pseudo-code to design the algorithm. Your algorithm should return TRUE (if the graph G connected) or FALSE (otherwise). If you use an algorithm discussed in class, you can call directly that algorithm. Note: the graph is connected if there is a path between any two vertices u and v. 6