A Shortest Path Algorithm. Motivation Given a connected, positive weighted graph Find the length of a shortest path from vertex a to vertex z.

Slides:



Advertisements
Similar presentations
Coloring Warm-Up. A graph is 2-colorable iff it has no odd length cycles 1: If G has an odd-length cycle then G is not 2- colorable Proof: Let v 0, …,
Advertisements

 Theorem 5.9: Let G be a simple graph with n vertices, where n>2. G has a Hamilton circuit if for any two vertices u and v of G that are not adjacent,
Single Source Shortest Paths
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.
* Bellman-Ford: single-source shortest distance * O(VE) for graphs with negative edges * Detects negative weight cycles * Floyd-Warshall: All pairs shortest.
The Greedy Approach Chapter 8. The Greedy Approach It’s a design technique for solving optimization problems Based on finding optimal local solutions.
Lecture 6 Shortest Path Problem. s t Dynamic Programming.
 2004 SDU Lecture9- Single-Source Shortest Paths 1.Related Notions and Variants of Shortest Paths Problems 2.Properties of Shortest Paths and Relaxation.
Data Structures and Algorithms Graphs Single-Source Shortest Paths (Dijkstra’s Algorithm) PLSD210(ii)
Graph Traversals Visit vertices of a graph G to determine some property: Is G connected? Is there a path from vertex a to vertex b? Does G have a cycle?
CS 206 Introduction to Computer Science II 11 / 07 / 2008 Instructor: Michael Eckmann.
Midwestern State University Department of Computer Science Dr. Ranette Halverson CMPS 2433 CHAPTER 4 - PART 2 GRAPHS 1.
CSC 331: Algorithm Analysis Paths in Graphs. The DFS algorithm we gave is recursive. DFS generates a search tree showing paths from one vertex to all.
CSCI 3160 Design and Analysis of Algorithms Tutorial 2 Chengyu Lin.
1 Shortest Path Algorithms Given a graph G = (V, E) and a distinguished vertex s, find the shortest weighted path from s to every other vertex in G. weighted.
Applied Discrete Mathematics Week 12: Trees
PLANAR SHORTEST PATH & R-DIVISIONS Dwyane George March 10, 2015.
Shortest Paths Definitions Single Source Algorithms –Bellman Ford –DAG shortest path algorithm –Dijkstra All Pairs Algorithms –Using Single Source Algorithms.
Greedy Algorithms Reading Material: Chapter 8 (Except Section 8.5)
Shortest Paths Definitions Single Source Algorithms
Greedy Algorithms Like dynamic programming algorithms, greedy algorithms are usually designed to solve optimization problems Unlike dynamic programming.
The Shortest Path Problem
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.
KNURE, Software department, Ph , N.V. Bilous Faculty of computer sciences Software department, KNURE The distance.
May 5, 2015Applied Discrete Mathematics Week 13: Boolean Algebra 1 Dijkstra’s Algorithm procedure Dijkstra(G: weighted connected simple graph with vertices.
CS 146: Data Structures and Algorithms July 21 Class Meeting
Copyright © Cengage Learning. All rights reserved.
Chapter 4: Finding the Shortest Path Lesson 1: Dijkstra’s Algorithm
Using Dijkstra’s Algorithm to Find a Shortest Path from a to z 1.
Dijkstra’s Algorithm. 2 Shortest-path Suppose we want to find the shortest path from node X to node Y It turns out that, in order to do this, we need.
5.4 Shortest-path problem  Let G=(V,E,w) be a weighted connected simple graph, w is a function from edges set E to position real numbers set. We denoted.
Lecture 12-2: Introduction to Computer Algorithms beyond Search & Sort.
May 1, 2002Applied Discrete Mathematics Week 13: Graphs and Trees 1News CSEMS Scholarships for CS and Math students (US citizens only) $3,125 per year.
Prof. Swarat Chaudhuri COMP 482: Design and Analysis of Algorithms Spring 2012 Lecture 10.
CSE, IIT KGP Euler Graphs and Digraphs. CSE, IIT KGP Euler Circuit We use the term circuit as another name for closed trail.We use the term circuit as.
 Rooted tree and binary tree  Theorem 5.19: A full binary tree with t leaves contains i=t-1 internal vertices.
1 The Floyd-Warshall Algorithm Andreas Klappenecker.
Introduction to Algorithms Jiafen Liu Sept
CSE 2331 / 5331 Topic 12: Shortest Path Basics Dijkstra Algorithm Relaxation Bellman-Ford Alg.
 Quotient graph  Definition 13: Suppose G(V,E) is a graph and R is a equivalence relation on the set V. We construct the quotient graph G R in the follow.
Length of a Path The weight (length) of a path is the sum of the weights of its edges. adcbe Path p: Edge weights: w(a, b) = 7, w(b, c) = 2, w(c,
Introduction to Algorithms All-Pairs Shortest Paths My T. UF.
Dijkstra animation. Dijksta’s Algorithm (Shortest Path Between 2 Nodes) 2 Phases:initialization;iteration Initialization: 1. Included:(Boolean) 2. Distance:(Weight)
Graphs Definition: a graph is an abstract representation of a set of objects where some pairs of the objects are connected by links. The interconnected.
 Hamilton paths.  Definition 20: A Hamilton paths is a path that contains each vertex exactly once. A Hamilton circuit is a circuit that contains.
Spanning Trees Dijkstra (Unit 10) SOL: DM.2 Classwork worksheet Homework (day 70) Worksheet Quiz next block.
5.6 Prefix codes and optimal tree Definition 31: Codes with this property which the bit string for a letter never occurs as the first part of the bit string.
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.
Trees.
Graphs – Breadth First Search
Shortest Path Problems
12. Graphs and Trees 2 Summary
COMP 6/4030 ALGORITHMS Prim’s Theorem 10/26/2000.
Greedy Algorithms / Minimum Spanning Tree Yin Tat Lee
Shortest Path Graph represents highway system Edges have weights
The Art Gallery Problem
Algorithms (2IL15) – Lecture 5 SINGLE-SOURCE SHORTEST PATHS
A Shortest Path Algorithm
Basic Graph Algorithms
CS 583 Analysis of Algorithms
Advanced Algorithms Analysis and Design
Shortest Path Algorithms
Theorem 5.13: For vT‘, l’(v)= min{l(v), l(vk)+w(vk, v)}
All pairs shortest path problem
Chapter 24: Single-Source Shortest Paths
CS 584 Project Write up Poster session for final Due on day of final
Chapter 24: Single-Source Shortest Paths
Lecture 12 Shortest Path.
Graph Theory: Euler Graphs and Digraphs
Presentation transcript:

A Shortest Path Algorithm

Motivation Given a connected, positive weighted graph Find the length of a shortest path from vertex a to vertex z.

Dijkstra’s Shortest Path Algorithm Input: A connected, positive weighted graph,vertices a and z Output: L(z), the length of a shortest path from a to z 1.Dijkstra(w,a,z,L){ 2. L(a)=0 3. for all vertices x ≠a 4. L(x)=∞ 5. T=set of all vertices 6. while(z є T){ 7. choose v є T with minimum L(v) 8. T=T-{v} 9. for each x є T adjacent to v 10. L(x)=min{L(x),L(v)+w(v,x)} 11. } 12.}

Example Find L(z) b ze f d c a g 6

Initialization b ze f d c a g 6 ∞ ∞ ∞ ∞ ∞ ∞ ∞ 0

Iteration 1 b ze f d c a g 6 ∞ ∞ ∞ ∞ ∞ ∞ ∞ 0 2 1

Iteration 2 b ze f d c a g 6 ∞ ∞ ∞ ∞ ∞

Iteration 3 b ze f d c a g 6 4 ∞ ∞ 6 ∞

Iteration 4 b ze f d c a g ∞

Proof of Dijkstra’s Algorithm Basic Step(i=1): we set L(a)=0, and L(a) is sure the length of a shortest path from a to a. Inductive step: For an arbitrary step i Suppose for step k<i, L(v) is the length of a shortest path from a to v. Next, suppose that at the it step we choose v in T with minimum L(v). We will seek a contradiction that if there is a w whose length is less than L(v) then w is not in T. By way of contradiction, suppose there is a w with L(w)<L(v), wєT. Then, let P be the shortest path from a to w, and let x be the vertex nearest to a on P that is in T and let u be x’s predecessor. The node u must not be in T (because x was the nearest node to a that was in T). By assumption, L(u) was the length of the shortest path from a to u. Then, L(x) ≤ L(u)+w(u,x) ≤ length of P < L(v). This is a contradiction. So w is not in T. According to our assumption, every path from a to v has length at least L(v). au x w …… P

Example 2 b z d c a e 2 Find L(z)

Initialization b z d c a e 2 ∞ ∞ ∞ ∞ ∞ 0 1

Iteration 1 b z d c a e 2 ∞ ∞ ∞ ∞ ∞ 0 a,2 a,1 1

Iteration 2 b z d c a e 2 ∞ ∞ ∞ 0 a,2 a,1 d,2 1

Iteration 3 b z d c a e 2 ∞ d,2 ∞ 0 a,2 a,1 b,5 1

Iteration 4 b z d c a e 2 d,2 ∞ 0 a,2 a,1 b,5 1 e,4

Iteration 5 b z d c a e 2 d,2 0 a,2 a,1 b,5 1 e,4

Theorem For input consisting of an n-vertex, simple, connected, weighted graph, Dijkstra’s algorithm has worst-case run time Ѳ (n 2 ). Proof: The while loop will take Ѳ (n 2 ) worst-case running time.