Analysis of Algorithms, 91

Total Page:16

File Type:pdf, Size:1020Kb

Analysis of Algorithms, 91

UML CS Analysis of Algorithms 91.404 (section 201) Fall, 2002

Homework Set #9

Assigned: Monday, 12/2 Due: Friday, 12/13 (start of lecture) This assignment covers textbook material in Chapters 15-16 and 22-24. Note: Partial credit for wrong answers is only given if work is shown.

Part 1: Chapters 15-16 (Algorithmic Paradigms for Optimization Problems)

1. (20 points) Dynamic Programming: Find an optimal parenthesization of a matrix-chain product whose sequence of dimensions is: <13, 10, 2, 6, 11, 8>.

2. (20 points) Dynamic Programming: Textbook, Exercise 15.3-5, p. 350.

3. (30 points) Greedy Algorithms: Textbook, Exercise 16.2-3, p. 384. Provide pseudocode, correctness justification, and worst-case run-time analysis.

4. (5 points) Greedy Algorithms: What is an optimal Huffman code for the following set of frequencies? A: 5 B: 16 C: 7 D: 2 E: 8 F: 10 G: 23 H: 4

Part 2: Chapter 22 (Elementary Graph Algorithms)

5. (15 points) Breadth-First Search: For the undirected graph G1 in Figure 1: a) (5 points) Show an adjacency list representation in which nodes are listed in lexicographic order.

b) (10 points) Draw the Breadth-First Search spanning forest of trees consisting of tree edges C D that result from a Breadth-First Search of the graph with node A as the source. F c) (5 points) For each node, show the shortest path from A to that node. Give B A the length (i.e. number of edges) of each such shortest path. E Figure 1: G1 6. (15 points) Depth-First Search: For the directed graph G2 in Figure 2: a) (5 points) Show an adjacency matrix representation in which nodes are listed in lexicographic order. b) (10 points) Draw the Depth-First Search spanning forest of trees that result from a Depth-First Search of the graph. Classify and label each edge as either a tree C D edge, back edge, forward edge, or cross edge. F B c) (5 points) Does the graph G2 contain a cycle? If G2 contains a cycle, list A E vertices in the order in which they appear in one of the cycles. If G2 does not contain a cycle, explain how you arrived at this conclusion. Figure 2: G2

1 UML CS Analysis of Algorithms 91.404 (section 201) Fall, 2002

7. (5 points) Topological Sort: What is the result of executing a Topological Sort on the directed graph G2 of problem 2? Explain your answer.

2 C D Part 3: Chapter 23 (Minimum Spanning Trees) 9 2 5 6 F B 7 8 8. (15 points) Show the Minimum Spanning Tree resulting from executing Kruskal’s A E algorithm on the weighted, undirected graph G3 in Figure 3. What is the total Figure 3: G3 weight of the edges in this Minimum Spanning Tree?

Part 4: Chapter 24 (Single-Source Shortest Paths) 2 C 9 D 9. (25 points) For the weighted, directed graph G4 in Figure 4: 2 5 6 F Execute Dijkstra’s algorithm using vertex B as the source. - B 7 - In the style of Figure 24.6 on p. 596, for each vertex v show the distance values A 8 E (d[v]) and the vertices along each shortest path ([v]) from A to v. Figure 4: G4

2

Recommended publications