This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full 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] Gabows Scaling Algorithm for SingleSource Shortest Paths (a) [5 points] Do problem 244(a) on page 616 of CLRS. Answer: Since the edge weights are all positive, we can use Dijkstras algorithm to find the shortest paths from the start vertex to all other vertices. The running time of Dijkstras algorithm using a binary heap is O ( E lg V ). The lg V term comes from the V calls to extractmin and the E calls to decreasekey. 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 Dijkstras algorithm, we need to implement the INSERT, DECREASEKEY, and EXTRACTMIN 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 DECREASEKEY on a vertex v , we remove v from its current linked list ( O (1)), decrease its key to i , and insert it into SHORTEST[ i ], for a total time of O (1). To EXTRACTMIN, we notice that throughout the running of Dijkstras algorithm, we always extract vertices with shortest paths of nondecreasing 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 nonempty, 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 nonempty 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 EXTRACTMIN, for an amoritized cost of O ( E/V ) each....
View
Full
Document
This document was uploaded on 05/25/2011.
 Summer '09
 Algorithms

Click to edit the document details