DOC PREVIEW
WSU CPTS 223 - The Shortest Path Problem

This preview shows page 1-2-21-22 out of 22 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 22 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 22 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 22 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 22 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 22 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

111111The Shortest Path ProblemShortest-Path AlgorithmsFind the “shortest” path from point A to point B“Shortest” in time, distance, cost, …Numerous applicationsMap navigationFlight itinerariesCircuit wiringNetwork routing22222Shortest Path ProblemsInput is a weighted graph where each edge (vi,vj) has cost ci,jto traverse the edgeCost of a path v1v2…vNis Weighted path costUnweighted path length is N-1, number of edges on path3∑−=+111,NiiicShortest Path ProblemsSingle-source shortest path problemGiven a weighted graph G=(V,E), and a start vertex s, find the minimum weighted path from s to every other vertex in G4Negative WeightsGraphs can have negative weightsE.g., arbitrageShortest positive-weight path is a net gainPath may include individual lossesProblem: Negative weight cyclesAllow arbitrarily-low path costsSolutionDetect presence of negative-weight cycles5Shortest Path ProblemsUnweighted shortest-path problem: O(|E|+|V|)Weighted shortest-path problemNo negative edges: O(|E| log |V|)Negative edges: O(|E|·|V|)Acyclic graphs: O(|E|+|V|)No asymptotically faster algorithm for single-source/single-destination shortest path problem6Unweighted Shortest PathsNo weights on edgesFind shortest length pathsSame as weighted shortest path with all weights equalBreadth-first search7Unweighted Shortest PathsFor each vertex, keep track ofWhether we have visited it (known)Its distance from the start vertex (dv)Its predecessor vertex along the shortest path from the start vertex (pv)8Unweighted Shortest Paths9Solution 1: Repeatedly iterate through vertices, looking for unvisited vertices at current distance from start vertex s.Running time: O(|V|2)Unweighted Shortest Paths10Solution 2: Ignore vertices that have already been visited by keeping only unvisited vertices (distance = ∞) on the queue.Running time: O(|E|+|V|)Unweighted Shortest Paths11Course Evaluation Site in now Open!Check eLearning or course website for URLhttp://skylight.wsu.edu/s/0ef32967-be3f-4f54-b83d-e8d722ea95d3.srvWeighted Shortest PathsDijkstra’s algorithmGREEDY strategy:Always pick the next closest vertex to the sourceUse priority queue to store unvisited vertices by distance from sAfter deleteMin v, update distances of remaining vertices adjacent to v using decreaseKeyDoes not work with negative weights13Dijkstra’s Algorithm1415BuildHeap: O(|V|)DeleteMin: O(|V| log |V|)DecreaseKey: O(|E| log |V|)Total running time: O(|E| log |V|)16DijkstraWhy Dijkstra WorksHypothesisA least-cost path from X to Y contains least-cost paths from X to every city on the path to YE.g., if XC1C2C3Y is the least-cost path from X to Y, thenXC1C2C3 is the least-cost path from X to C3XC1C2 is the least-cost path from X to C2XC1 is the least-cost path from X to C117AD CB201010100100100This is called the “Optimal Substructure” propertyWhy Dijkstra WorksPROOF BY CONTRADICTION:Assume hypothesis is falseI.e., Given a least-cost path P from X to Y that goes through C, there is a better path P’ from X to C than the one in PShow a contradictionBut we could replace the subpath from X to C in P with this lesser-cost path P’The path cost from C to Y is the sameThus we now have a better path from X to YBut this violates the assumption that P is the least-cost path from X to YTherefore, the original hypothesis must be true18X CYP’Printing Shortest Paths19What about graphs with negative edges?Will the O(|E| log|V|) Dijkstra’s algorithm work as is?-10v1v4v2v3321sourceNo change and so v4. dist will remain 4.Correct answer: v4.dist should be updated to -5V3V4.dist = 4, V3.dist = 5 V2No changeV4V2.dist = 3V1Updates to distdeleteMinSolution:Do not mark any vertex as “known”.Instead allow multiple updates.Negative Edge Costs21Running time: O(|E|·|V|)v1v4v2v3321sourceNo updatesV4V4V3V4, V3V2V1QueueV4.dist = -5V3V4.dist = 4, V3.dist = 5 V2No updatesV4V2.dist = 3V1Updates to distDequeue-10Negative Edge Costs22Running time: O(|E|·|V|)Negative weight


View Full Document

WSU CPTS 223 - The Shortest Path Problem

Download The Shortest Path Problem
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view The Shortest Path Problem and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view The Shortest Path Problem 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?