ps6sol - CS161 Design and Analysis of Algorithms Summer...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS161: Design and Analysis of Algorithms Summer 2004 Problem Set #6 Solutions General Notes • Regrade Policy: If you believe an error has been made in the grading of your problem set, you may resubmit it for a regrade. If the error consists of more than an error in addition of points, please include with your problem set a detailed explanation of which problems you think you deserve more points on and why. We reserve the right to regrade your entire problem set, so your final grade may either increase or decrease. Throughout this entire problem set, your proofs should be as formal as possible. However, when asked to state an algorithm, you do not need to give pseudocode or prove correctness at the level of loop invariants. Your running times should always be given in terms of | V | and/or | E | . If representation of the graph is not specified, you may assume whichever is convenient. 1. [19 points] Gabow’s Scaling Algorithm for Single-Source Shortest Paths (a) [5 points] Do problem 24-4(a) on page 616 of CLRS. Answer: Since the edge weights are all positive, we can use Dijkstra’s algorithm to find the shortest paths from the start vertex to all other vertices. The running time of Dijkstra’s algorithm using a binary heap is O ( E lg V ). The lg V term comes from the V calls to extract-min and the E calls to decrease-key. Because of the constraints that the edge weights are integers and that the shortest path distances are bounded by | E | , we can do better. We can use a method similar to counting sort to maintain the list of vertices. We know that the weights of the path to each vertex will always be an integer between 0 and | E | , so we can keep an array SHORTEST of linked lists for each possible value. For Dijkstra’s algorithm, we need to implement the INSERT, DECREASE-KEY, and EXTRACT-MIN functions. INSERT is easy. If we want to insert a vertex that is reachable in length i , we simply add it to the beginning of the linked list in SHORTEST[ i ], which is O (1). To call DECREASE-KEY on a vertex v , we remove v from it’s current linked list ( O (1)), decrease it’s key to i , and insert it into SHORTEST[ i ], for a total time of O (1). To EXTRACT-MIN, we notice that throughout the running of Dijkstra’s algorithm, we always extract vertices with shortest paths of non-decreasing value. So, if the previous vertex was extracted at value i , we know that there can be no vertices in the array at values less than i . So, we start at SHORTEST[ i ] and if it is non-empty, we remove the first element from the linked list. If it is empty, we move up to SHORTEST[ i + 1] and repeat. The actual extraction takes time O (1). Notice that the scanning for a non-empty list could take time O ( E ) since there are a total of E lists, but since we never backtrack, Problem Set #6 2 this O ( E ) scan of the lists is averaged over the O ( V ) calls to EXTRACT-MIN, for an amoritized cost of O ( E/V ) each....
View Full Document

{[ snackBarMessage ]}

Page1 / 9

ps6sol - CS161 Design and Analysis of Algorithms Summer...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online