Single-Source Shortest Paths

Slides:



Advertisements
Similar presentations
Single Source Shortest Paths
Advertisements

Chapter 9: Graphs Shortest Paths
1 Greedy 2 Jose Rolim University of Geneva. Algorithmique Greedy 2Jose Rolim2 Examples Greedy  Minimum Spanning Trees  Shortest Paths Dijkstra.
Tirgul 12 Algorithm for Single-Source-Shortest-Paths (s-s-s-p) Problem Application of s-s-s-p for Solving a System of Difference Constraints.
3 -1 Chapter 3 The Greedy Method 3 -2 The greedy method Suppose that a problem can be solved by a sequence of decisions. The greedy method has that each.
Graphs & Graph Algorithms 2 Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
More Graph Algorithms Weiss ch Exercise: MST idea from yesterday Alternative minimum spanning tree algorithm idea Idea: Look at smallest edge not.
Dijkstra’s Algorithm Slide Courtesy: Uwash, UT 1.
Chapter 9: Graphs Spanning Trees Mark Allen Weiss: Data Structures and Algorithm Analysis in Java Lydia Sinapova, Simpson College.
Dijkstra's algorithm.
Shortest Path Algorithms. Kruskal’s Algorithm We construct a set of edges A satisfying the following invariant:  A is a subset of some MST We start with.
Graphs CS 400/600 – Data Structures. Graphs2 Graphs  Used to represent all kinds of problems Networks and routing State diagrams Flow and capacity.
© The McGraw-Hill Companies, Inc., Chapter 3 The Greedy Method.
Dijkstras Algorithm Named after its discoverer, Dutch computer scientist Edsger Dijkstra, is an algorithm that solves the single-source shortest path problem.
Charles Lin. Graph Representation Graph Representation DFS DFS BFS BFS Dijkstra Dijkstra A* Search A* Search Bellman-Ford Bellman-Ford Floyd-Warshall.
COSC 2007 Data Structures II Chapter 14 Graphs III.
Shortest Path in Weighted Graph : Dijkstra’s Algorithm.
Most of contents are provided by the website Graph Essentials TJTSD66: Advanced Topics in Social Media.
CSC 213 – Large Scale Programming. Today’s Goals  Discuss what is meant by weighted graphs  Where weights placed within Graph  How to use Graph ’s.
Data Structures & Algorithms Shortest Paths Richard Newman based on book by R. Sedgewick and slides by S. Sahni.
CSE 373: Data Structures and Algorithms Lecture 21: Graphs V 1.
Graphs – Part III CS 367 – Introduction to Data Structures.
Graph Search Applications, Minimum Spanning Tree
Graphs Representation, BFS, DFS
Chapter 9 : Graphs Part II (Minimum Spanning Trees)
Shortest Paths and Minimum Spanning Trees
Minimum Spanning Trees
Minimum Spanning Trees and Shortest Paths
Cinda Heeren / Geoffrey Tien
Algorithms and Data Structures Lecture XIII
Lecture 12 Algorithm Analysis
Introduction to Graphs
Minimum Spanning Trees
Short paths and spanning trees
Data Structures & Algorithms Graphs
Graph & BFS.
Graphs Representation, BFS, DFS
Minimum Spanning Tree.
Greedy Algorithms / Dijkstra’s Algorithm Yin Tat Lee
Algorithms (2IL15) – Lecture 5 SINGLE-SOURCE SHORTEST PATHS
CSE373: Data Structures & Algorithms Lecture 18: Dijkstra’s Algorithm
CSE 373: Data Structures and Algorithms
Algorithms and Data Structures Lecture XIII
Lecture 13 Algorithm Analysis
Lecture 13 Algorithm Analysis
Lecture 12 Algorithm Analysis
Minimum Spanning Tree Algorithms
Shortest Paths and Minimum Spanning Trees
Lecture 13 Algorithm Analysis
CSE332: Data Abstractions Lecture 18: Minimum Spanning Trees
Slide Courtesy: Uwash, UT
Lecture 13 Algorithm Analysis
Advanced Computer Networks
Fundamental Data Structures and Algorithms
Minimum Spanning Tree.
Shortest Path Algorithm for Weighted Non-negative Undirected Graphs
Weighted Graphs & Shortest Paths
CSE332: Data Abstractions Lecture 17: Shortest Paths
CE 221 Data Structures and Algorithms
Slide Courtesy: Uwash, UT
CSE 417: Algorithms and Computational Complexity
Dijkstra's Shortest Path Algorithm
Implementation of Dijkstra’s Algorithm
Lecture 18: Implementing Graphs
Lecture 12 Algorithm Analysis
Lecture 12 Shortest Path.
Chapter 9: Graphs Shortest Paths
Lecture 22: Implementing Dijkstra’s
Chapter 9: Graphs Spanning Trees
INTRODUCTION A graph G=(V,E) consists of a finite non empty set of vertices V , and a finite set of edges E which connect pairs of vertices .
Presentation transcript:

Single-Source Shortest Paths Chapter 24 Cormen Leiserson Rivest&Stein: Introduction to Algorithms

Shortest path Weighted Graphs G(V, E, w) W: E R If w=1 for all edges BFS is the solution. Weight w(p) of a path p = {v0, v1, …, vk) is the sum of weights of its edges: w(p) = Σ i=1,k w(vi-1,vi) Shortest-Path distance is the shortest path with minimum w(p).

MST and Shortest path tree Starting from a minimizes the global sum of weights of the edges SPT Minimized the distances (sum of weights) from a to all the other nodes

Single-Source Shortest Paths 2 very important applications : Geographical maps and satellite navigators. Internet : Routing of messages

Representing Shortest Paths Not only compute the value of min w(p) but also the path associated to this weight. Use predecessor as in BSF u, π(u) and the procedure PrintPath. First build the Shortest path tree For the Routing Problem: Compute the shortest path from any source. Routing tables: for each destination specifies the next hop in the shortest path.

Relaxation Typical operation of the computation of the SPT. Update the value v.d of the SPT computed so far to a better value. v.d > u.d +2 RELAX ! v.d < u.d +2 DO NOT RELAX ! UPDATE: v.d = u.d +2 NO UPDATE

Dijkstra’s algorithm Assign to every node a tentative distance value: set it to zero for our initial node and to infinity for all other nodes. Set the initial node as current. Mark all other nodes unvisited. Create a set of all the unvisited nodes called the unvisited set. For the current node, consider all of its unvisited neighbors and calculate their tentative distances. Compare the newly calculated tentative distance to the current assigned value and assign the smaller one. ( Check Relaxation)

Dijkstra’s algorithm 4. When we are done considering all of the neighbors of the current node, mark the current node as visited and remove it from the unvisited set. A visited node will never be checked again. 5. If the destination node has been marked visited or if the smallest tentative distance among the nodes in the unvisited set is infinity then stop. The algorithm has finished. 6 Otherwise, select the unvisited node that is marked with the smallest tentative distance, set it as the new "current node", and go back to step 3.

Dijkstra’s algorithm

Dijkstra’s algorithm correctness Invariant: For each visited node v, v.d is the shortest distance from source to v. For each unvisited node u, u.d is the shortest distance via visited nodes only, from source to u (if such a path exists, otherwise infinity); Proof by induction

Correctness sketch After processing u it will still be true that for each unvisited node w, w.d is the shortest distance from source to w using visited nodes only, since: if there were a shorter path which doesn’t visit u we would have found it previously; if there is a shorter path using u we update it when processing u .

Dijkstra’s algorithm analysis Instructions 1-3: O(V) Instructions 4-8: O((V+E) log(V)) if Q is implemented with a heap. Total: : O((V+E) log(V)) Operation DECREASE KEY in a heap can be performed in O(logV) time.

Semi external algorithm for MST-Kruskal Semi external: the cache is big enough to contain the Union –Find data structure but not Graph. Sort the edges using any optimal external (2-level model) sorting algorithm. Scan the edges in order of increasing weight, as for the normal algorithm. If an edge is selected for the MST, output it. Number of I/O’s operations as Sorting.

External algorithm for MST -Kruskal Try to reduce the number of nodes! Edge contraction: Reduce the vertices from n to n’. For v=1 to n-n’ find the lightest edge (u, v) incident to v and contract it When after contraction n becomes n’ adopt semi-external algorithm.

Contraction Edge (c, a, 6) is the cheapest incident in a. Contract it: merge a and c to c. Relink a: (a, b, 7) becomes (c,b, 7), (a,d,9) becomes (c, d, 9). Output (b,d,2) …

Contraction Contraction can be implemented using a priority queue both to find the cheapest edge incident to v and to relink the other edges incident to v. For each edge e=(u,v) we have to store the additional information: {min(u,v), max(u,v), w(e), original e} Edges are sorted according to weight and according to the lower endpoint. Contraction is proportional to sum of the degrees of the nodes encountered. Complexity: worst case O(n2) I/O’s n=|V|, m=|E| Expected : O(sort(m)log n/n’) I/O’s