A B C D E F G 1) Use Dijkstra's Algorithm to determine the shortest distance from vertex A to all other vertices in the graph with the weighted adjacency matrix given below: A B C D E F G 0 12 ∞ 3 ∞ 6 ∞ 2 0 7 ∞ 10 ∞ 4 ∞ ∞ 0 ∞ ∞ ∞ 1 7 8 13 0 ∞ 2 ∞ ∞ 2 3 ∞ 0 ∞ 6 ∞ 5 12 ∞ 4 0 12 ∞ ∞ 1 2 3 4 0 Fill in the chart below to indicate the steps of the algorithm. Each column stores the estimate of the shortest distance from A to the labeled vertex. Add to S A D F E B C G B 12 11 10 10 10 10 10 C ∞ 16 16 12 12 12 12 D 3 3 3 3 3 3 3 E ∞ ∞ 9 9 9 9 9 F 6 5 5 5 5 5 5 G ∞ ∞ 17 15 14 13 13 What is the path reconstruction to get from A to G? A D F E C G 2) Use Prim's Algorithm starting at vertex B to find the minimum spanning tree of the graph with the adjacency matrix below: A B C D E F G A 0 12 2 3 ∞ 6 1 B 12 0 7 ∞ 10 ∞ 4 C 2 7 0 ∞ 4 7 1 D 3 ∞ ∞ 0 ∞ 2 ∞ E ∞ 10 4 ∞ 0 ∞ 6 F 6 ∞ 7 2 ∞ 0 12 G 1 4 1 ∞ 6 12 0 In particular, state each edge considered, and then whether or not that edge is added. (At each iteration of the algorithm, consider only one edge.) Added? Added? Edge #1: BG YES Edge #5: AD YES Edge #2: GA YES Edge #6: DF YES Edge #3: GC YES Edge #7: CE YES Edge #4: AC NO, CYCLE 3) Do the same thing for Kruskal’s Edge #1: AG Edge #2: CG Edge #3: AC Edge #4: DF Added? YES YES NO, CYLE YES Edge #5: AD Edge #6: CE Edge #7: BG Added? YES YES YES 4) Huffman Encoding Character A B C D E F G H Frequency 16 4 5 31 86 18 10 30 Huffman Code 0110 00000 00001 010 1 0111 0001 001 Construct the Huffman tree for this file below. Afterwards, add the Huffman codes for each of the characters in the chart above. Note: There are multiple possible answers to this question based on which side you choose when merging nodes. 200 / 114 / 49 / \ 19 30,h / \ 9 10,g / \ 4,b 5,c \ 86,e \ 65 / \ 31,d 34 / \ 16,a 18,f Assuming that the file was previously stored using three bit codes for each character, and that it takes no space to store the Huffman codes themselves, how many bits are saved when encoding this particular file using Huffman coding? Old file = 600 bits New file = 4x16 + 5x4 + 5x5 + 3x31 + 1x86 + 4x18 + 4x10 + 3x30 = 490 Bits saved = 110 5) (5 pts) Show the order in which the nodes in the graph below would be visited in a breadth first search starting at node number 1. Note: Whenever there is a choice of where to visit first, always visit the lower numbered vertex. _________________ | | 1 ------- 2-------- 5-------8-----11-------------15 | | \_____6—10—13 / / | | \ / / / 3--------4----------7----------9 ----- 12----14 1, 2, 3, 4, 5, 6, 11, 7, 8, 10, 9, 15, 13, 12, 14 6) (5 pts) Show the order in which the nodes in the graph from question #5 would be visited in a depth first search starting at node number 1. . Note: Whenever there is a choice of where to visit first, always visit the lower numbered vertex. 1, 2, 4, 3, 7, 6, 10, 13, 9, 11, 8, 5, 15, 14, 12 7) (10 pts) Write down the solution for each of these recurrence relations utilizing the Master Theorem: n a) T (n) 4T ( ) n 2 (n) e) T(n) = 4T(n/2) + n2 (n2 log n) e) T(n) = 4T(n/2) + n3 (n3) d) T(n) = 4T(n/4) + n (n log n) e) T(n) = 7T(n/2) + n2 (n log27) Other Problems solved in the slides: Divide and Conquer: Skyline, Subset Sum Recursive, Integer Multiplication, Tromino Tiling Greedy: Single Room Scheduling, Multiple Room Scheduling, Fractional Knapsack Dynamic Programming: Fibonacci and Change Problem Topological Sort Graph Two-Coloring