This preview shows pages 1–4. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: CS 170 Second Midterm ANSWERS 7 April 2010 NAME (1 pt): SID (1 pt): TA (1 pt): Name of Neighbor to your left (1 pt): Name of Neighbor to your right (1 pt): Instructions : This is a closed book, closed calculator, closed computer, closed network, open brain exam, but you are permited a 1 page, doublesided set of notes, large enough to read without a magnifying glass. You get one point each for filling in the 5 lines at the top of this page. Each other question is worth 20 points. No points will be subtracted for wrong answers so its in your best interest to guess all you want. Write all your answers on this exam. If you need scratch paper, ask for it, write your name on each sheet, and attach it when you turn it in (we have a stapler). 1 2 3 Total 1 Question 1 (20 points). We are running the following four algorithms on the graph below, where the algorithms have already processed the three boldface edges: Dijkstras algorithm for shortest paths, starting from S . Prims algorithm for the Minimum Spanning Tree (MST), starting from S (ignoring edge directions). Kruskals algorithm for the Minimum Spanning Tree (MST) (ignoring edge directions). BreadthFirstSearch (BFS) starting from S (ignoring both edge directions and edge weights, but visiting neighboring vertices in lexicographic order). (a) Which 3 edges would be added next to the MST in Prims algorithm? Be sure to indicate the order in which they are added. Answer: First (A,B), then (A,E), then (E,H). (b) Which 3 edges would be added next to the MST in Kruskals algorithm? Be sure to indicate the order in which they are added. Answer: First (G,H), then (A,B), then (E,H). (c) Which 3 edges would be added next to the BFStree by BFS? Be sure to indicate the order in which they are added. Answer: First (A,B), then (A,E), then (C,F). (d) At this point in the running of Dijkstras algorithm, S has been taken off the top of the priority queue and marked as visited. Which 4 vertices would be marked next in Dijkstras algorithm, i.e. deleted from the priority queue and marked? What are the shortest paths, and their lengths, to these 4 vertices? Answer: First D (shortest path SD, length 1), then C (shortest path SC, length 2), then A (shortest path SA, length 3), then B (shortest path SAB, length 3+5=8). 2 Question 1 (20 points). We are running the following four algorithms on the graph below, where the algorithms have already processed the three boldface edges: Dijkstras algorithm for shortest paths, starting from S . Prims algorithm for the Minimum Spanning Tree (MST), starting from S (ignoring edge directions). Kruskals algorithm for the Minimum Spanning Tree (MST) (ignoring edge directions)....
View
Full
Document
This note was uploaded on 04/30/2010 for the course CS 170 taught by Professor Henzinger during the Spring '02 term at University of California, Berkeley.
 Spring '02
 HENZINGER
 Algorithms

Click to edit the document details