Shortest Path Consider the following weighted undirected graph: 20 10

Slides:



Advertisements
Similar presentations
Weighted graphs Example Consider the following graph, where nodes represent cities, and edges show if there is a direct flight between each pair of cities.
Advertisements

O(N 1.5 ) divide-and-conquer technique for Minimum Spanning Tree problem Step 1: Divide the graph into  N sub-graph by clustering. Step 2: Solve each.
1 Discrete Structures & Algorithms Graphs and Trees: III EECE 320.
1 A Faster Approximation Algorithm For The Steiner Problem In Graphs Kurt Mehlhorn. Information Processing Letters, 27(3):125–128, 高等演算法二
1 Greedy 2 Jose Rolim University of Geneva. Algorithmique Greedy 2Jose Rolim2 Examples Greedy  Minimum Spanning Trees  Shortest Paths Dijkstra.
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.
Chapter 9: Greedy Algorithms The Design and Analysis of Algorithms.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
Graphs & Graph Algorithms 2 Nelson Padua-Perez Bill Pugh Department of Computer Science University of Maryland, College Park.
Graphs & Graph Algorithms 2
CS2420: Lecture 40 Vladimir Kulyukin Computer Science Department Utah State University.
Minimal Spanning Trees. Spanning Tree Assume you have an undirected graph G = (V,E) Spanning tree of graph G is tree T = (V,E T E, R) –Tree has same set.
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
Prim’s Algorithm and an MST Speed-Up
Graphs & Graph Algorithms 2 Fawzi Emad Chau-Wen Tseng Department of Computer Science University of Maryland, College Park.
Minimum Spanning Trees. Subgraph A graph G is a subgraph of graph H if –The vertices of G are a subset of the vertices of H, and –The edges of G are a.
TECH Computer Science Graph Optimization Problems and Greedy Algorithms Greedy Algorithms  // Make the best choice now! Optimization Problems  Minimizing.
Using Dijkstra’s Algorithm to Find a Shortest Path from a to z 1.
© The McGraw-Hill Companies, Inc., Chapter 3 The Greedy Method.
Minimum Spanning Trees
COSC 2007 Data Structures II Chapter 14 Graphs III.
Module 5 – Networks and Decision Mathematics Chapter 23 – Undirected Graphs.
Lecture 19 Greedy Algorithms Minimum Spanning Tree Problem.
Minimum spanning trees (MST) Def: A spanning tree of a graph G is an acyclic subset of edges of G connecting all vertices in G. A sub-forest of G is an.
Runtime O(VE), for +/- edges, Detects existence of neg. loops
1 Prim’s algorithm. 2 Minimum Spanning Tree Given a weighted undirected graph G, find a tree T that spans all the vertices of G and minimizes the sum.
Graphs and MSTs Sections 1.4 and 9.1. Partial-Order Relations Everybody is not related to everybody. Examples? Direct road connections between locations.
Design and Analysis of Algorithms - Chapter 91 Greedy algorithms Optimization problems solved through a sequence of choices that are: b feasible b locally.
P, NP, and NP-Complete Problems Section 10.3 The class P consists of all problems that can be solved in polynomial time, O(N k ), by deterministic computers.
Spanning Trees Dijkstra (Unit 10) SOL: DM.2 Classwork worksheet Homework (day 70) Worksheet Quiz next block.
Proof of correctness of Dijkstra’s algorithm: Basically, we need to prove two claims. (1)Let S be the set of vertices for which the shortest path from.
Kruskal’s Algorithm for Computing MSTs Section 9.2.
Minimum Spanning Trees
Randomized Min-Cut Algorithm
COMP108 Algorithmic Foundations Greedy methods
Chapter 9 : Graphs Part II (Minimum Spanning Trees)
Introduction to Algorithms
Shortest Paths and Minimum Spanning Trees
Shortest Path 6/18/2018 4:22 PM Presentation for use with the textbook Data Structures and Algorithms in Java, 6th edition, by M. T. Goodrich, R. Tamassia,
Minimal Spanning Trees
The Greedy Method and Text Compression
Minimum Spanning Trees and Shortest Paths
Greedy Algorithms / Minimum Spanning Tree Yin Tat Lee
Topological Sort (topological order)
Three Graph Algorithms
Minimal Spanning Trees
Short paths and spanning trees
The A* Algorithm Héctor Muñoz-Avila.
Minimum Spanning Trees
Minimum Spanning Tree Neil Tang 3/25/2010
Connected Components Minimum Spanning Tree
Graphs & Graph Algorithms 2
Greedy Algorithms / Dijkstra’s Algorithm Yin Tat Lee
CSE373: Data Structures & Algorithms Lecture 12: Minimum Spanning Trees Catie Baker Spring 2015.
CSE373: Data Structures & Algorithms Lecture 20: Minimum Spanning Trees Linda Shapiro Spring 2016.
Chapter 13 Graph Algorithms
Lecture 24 CSE 331 Oct 29, 2012.
Autumn 2015 Lecture 10 Minimum Spanning Trees
Minimum Spanning Tree Neil Tang 4/3/2008
CSE 373: Data Structures and Algorithms
Autumn 2016 Lecture 10 Minimum Spanning Trees
Shortest Paths.
CSE 417: Algorithms and Computational Complexity
Implementation of Dijkstra’s Algorithm
CSE 373: Data Structures and Algorithms
Spanning Trees Lecture 20 CS2110 – Spring 2015.
Prim’s Minimum Spanning Tree Algorithm Neil Tang 4/1/2008
Prim’s algorithm for minimum spanning trees
Winter 2019 Lecture 10 Minimum Spanning Trees
Heaps Section 6.4, Pg. 309 (Section 9.1).
Presentation transcript:

Shortest Path Consider the following weighted undirected graph: 20 10 22 20 9 16 7 18 6 2 8 24 5 4 6 66 10 20 We want: A path 5  v1  v2  …  20 Such that cost(5v1) + cost(v1 v2) + … + cost ( 20) is minimum

How About Using the MST Algorithm? 20 10 22 20 9 16 7 18 6 2 8 24 5 4 6 66 10 20 Compute the MST Take the path between the two nodes that goes through the MST

The Fringe Given a Graph G = (V,E) and T a subset of V, the fringe of T, is defined as: Fringe(T) = { (w,x) in E : w  T and x V − T} T

Djikstra Algorithm: Idea We are computing a shortest path from node u to a node v Start the algorithm with T = {u}, construct Fringe(T) At each iteration, select the (z,w) in Fringe(T) such that the path from u to w has the lowest cost Stop when v is part of T (not of the fringe!)

Example 20 10 22 20 16 7 9 18 6 2 8 24 5 4 6 66 10 20

The Dijkstra’s Algorithm // Input: G = (G,V), nodes u and v in V //output: Shortest path from u to v T  {u}; F  Fringe({u}); ET  {} While v is not in the T do Choose (z,w) in F with the shortest path (u, u1), (u1,u2),…, (un,z) (z,w) with (u, u1), (u1,u2),…, (un,z) in ET T  T  {w} ET  ET  {(z,w)} for each {(w,x) : (w,x) in E − ET } do If no (w’,x) in F then F  F  {(w,x)} else If the path u  x going through (w,x) has less weight than the path ux going through (w’,x) then F  ( F − {(w’,x)})  {(w,x)}

Properties Is Dijkstra’s Algorithm greedy? Yes Why Dijkstra’s Algorithm works? T V  T The path from u to every node in T is the minimum path w u r s v 6 20 x

Complexity Actual complexity is O(|E|log2 |E|) It is easy to see that it is at most |E||V| (i.e., |E|2): the outer “while” is performed |V| times the inner for is performed at most |E| times

Homework 010 Write the pseudo-code for the algorithm inserting an element in a min-heap Do the same for a Heap Write the pseudo-code for isLeaf(i) (Slide 15 of class about Heaps) Change Dijkstra’s Algorithm (Slide 6) to compute the minimum distance from u to every node in the graph True or False: the subgraph (T,ET) resulting from 4 is an MST of the input graph In the graph of 2.b (Page 323). Follow Dijkstra’s Algorithm to compute the path from c to l 011 Write the pseudo-code for the algorithm deleting the element with the minimum priority value in a min-heap Do the same but deleting the one with the highest priority for a Heap Write the pseudo-code for Parent(i) (Slide 15 of class about Heaps) True or False: the subgraph (T,ET) resulting from 4 is a tree connecting all nodes of the input graph In the graph of 2.b (Page 323). Follow Dijkstra’s Algorithm to compute the path from l to a