Find the shortest path from a to z

Slides:



Advertisements
Similar presentations
EXAMPLE: X Y Z T 5 VERTICES 6 EDGES S Collection List Set ArrayList LinkedList SortedSet HashSet TreeSet.
Advertisements

6.8 The Cheapest-Link Algorithm. The Cheapest-Link Algorithm Pick the edge with the smallest weight and mark it Pick the next edge with the smallest weight.
AB 11 22 33 44 55 66 77 88 99 10  20  19  18  17  16  15  14  13  12  11  21  22  23  24  25  26  27  28.
Design and Analysis of Algorithms Single-source shortest paths, all-pairs shortest paths Haidong Xue Summer 2012, at GSU.
1 Section 9.4 Spanning Trees. 2 Let G be a simple graph. A spanning subtree of G is a subgraph of G containing every vertex of G –must be connected; contains.
Graph Search Methods A vertex u is reachable from vertex v iff there is a path from v to u
Graph Search Methods A vertex u is reachable from vertex v iff there is a path from v to u
Graphs Chapter 12. Chapter Objectives  To become familiar with graph terminology and the different types of graphs  To study a Graph ADT and different.
Discrete Structures Lecture 13: Trees Ji Yanyan United International College Thanks to Professor Michael Hvidsten.
Prim’s Algorithm from a matrix A cable TV company is installing a system of cables to connect all the towns in the region. The numbers in the network are.
How to solve Euler paths & circuits. by Mr. King.
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Shortest Path Problems Directed weighted graph. Path length is sum of weights of edges on path. The vertex at which the path begins is the source vertex.
Fall 2007CS 2251 Graphs Chapter 12. Fall 2007CS 2252 Chapter Objectives To become familiar with graph terminology and the different types of graphs To.
2/10/03Tucker, Sec Tucker, Applied Combinatorics, Sec. 3.2, Important Definitions Enumeration: Finding all of the possible paths in a rooted tree.
In Greek this just means: Working with Triangles
Quickest Route B St Li C La time matrix (minutes) Liskeard Launceston Callington St Austell Bodmin 32 What is the quickest route from.
KNURE, Software department, Ph , N.V. Bilous Faculty of computer sciences Software department, KNURE The distance.
Using Dijkstra’s Algorithm to Find a Shortest Path from a to z 1.
Shortest Path Algorithm This is called “Dijkstra’s Algorithm” …pronounced “Dirk-stra”
Shortest Path. Dijkstra’s Algorithm finds the shortest path from the start vertex to every other vertex in the network. We will find the shortest path.
Dijkstras Algorithm Named after its discoverer, Dutch computer scientist Edsger Dijkstra, is an algorithm that solves the single-source shortest path problem.
Networks.
Vertices and Edges Introduction to Graphs and Networks Mills College Spring 2012.
Shortest Path Problems Dijkstra’s Algorithm. Introduction Many problems can be modeled using graphs with weights assigned to their edges: Airline flight.
The diagram below shows water flowing through a pipework system. The values on the edges are the capacities of water that they can carry.
Graphs Chapter 12. Chapter 12: Graphs2 Chapter Objectives To become familiar with graph terminology and the different types of graphs To study a Graph.
Minimum Spanning tree Prim’s algorithm 1.Select any vertex 2.Select the shortest edge connected to that vertex 3.Select the shortest edge which connects.
EXAMPLE 4 Find a minimum distance Parking You are going to buy books. Your friend is going to buy CDs. Where should you park to minimize the distance you.
Today we will… Identify the vertices and edges on a given shape.
Chapter 14 Section 3 - Slide 1 Copyright © 2009 Pearson Education, Inc. AND.
Graph Theory Def: A graph is a set of vertices and edges G={V,E} Ex. V = {a,b,c,d,e} E = {ab,bd,ad,ed,ce,cd} Note: above is a purely mathematical definition.
A B The points on the coordinate plane below are three vertices of a rectangle. What are the coordinates of the fourth vertex? C.
Unit 3 Chinese Postman. Non - Eulerian Semi - Eulerian Eulerian.
Know the number of 100’s in centuries and thousands.
A vertex u is reachable from vertex v iff there is a path from v to u.
Shortest Path from G to C Using Dijkstra’s Algorithm
Vertical Height (In Feet)
Discrete Math 2 Weighted Graph Search Tree
Minimum Spanning Trees and Shortest Paths
Cinda Heeren / Geoffrey Tien
Shortest Path Problems
Discussion section #2 HW1 questions?
Party-by-Night Problem
GEOMETRY.
Quiz Review.
Shortest Path.
Shortest Path.
מיומנויות תקשורת בין אישית סוגי שיחות שונים בין שנים, בבית הספר.
القامة المقلوبة عندما يراد ايجاد منسوب اسفل الجسر (او اي نقطة تقع فوق خط النظر) يقلب وضع القامة بحيث تكون قاعدتها علي النقطة المعنية (شكل 2) وتضاف القراءة.
Graphs.
Shortest Path Problems
Shortest Path Algorithms
Label Name Label Name Label Name Label Name Label Name Label Name
Shortest path algorithm
1.5 The Distribute Property of Multiplication over Addition
Minimum Spanning tree Select any vertex
Shortest Path Algorithm for Weighted Non-negative Undirected Graphs
Shortest Path.
Network Flows – Restricted vertices
Weighted Graphs & Shortest Paths
A vertex u is reachable from vertex v iff there is a path from v to u.
and 6.855J Dijkstra’s Algorithm
Euler circuit Theorem 1 If a graph G has an Eulerian path, then it must have exactly two odd vertices. Theorem 2 If a graph G has an Eulerian circuit,
Dijkstra's Shortest Path Algorithm
Implementation of Dijkstra’s Algorithm
Warm Up - Copy each of the following into your notebook, then solve.
Have your homework out when the bell rings.
Warm Up – 3/14 - Friday 100 seats are to be apportioned.
Prim’s algorithm for minimum spanning trees
Presentation transcript:

Find the shortest path from a to z 3 3 b d g 8 3 2 2 1 h 6 3 a z e 6 1 8 3 9 f i c 1 3

∞ 3 ∞ ∞ 3 b b d d g g 8 3 2 2 1 ∞ h h ∞ 6 3 a z z e e ∞ 6 1 8 3 9 f f Label all vertices as ∞ and put vertex a in the vertex list. ∞ 3 ∞ ∞ 3 b b d d g g 8 3 2 2 1 ∞ h h ∞ 6 3 a z z e e ∞ 6 1 8 3 9 f f i i c c ∞ 1 ∞ 3 ∞ Vertex List: a:0 b: ∞ c: ∞ d: ∞ e: ∞ f: ∞ g: ∞ h: ∞ i: ∞ z: ∞

3 ∞ ∞ 3 b b d d g g 8 3 2 2 1 ∞ h h 6 3 a z z e e ∞ 6 1 8 3 9 f f i i Re-label all vertices that can be reached from a 3 ∞ ∞ 3 2(a) b b d d g g 8 3 2 2 1 ∞ h h 6 3 6(a) a z z e e ∞ 6 1 8 3 9 f f i i c c 1 3(a) ∞ 3 ∞ Vertex List: a:0 b: 2 c: 3 d: ∞ e: 6 f: ∞ g: ∞ h: ∞ i: ∞ z: ∞

3 ∞ ∞ 3 b d d g g 8 3 2 2 1 ∞ h h 6 3 a z z e e ∞ 6 1 8 3 9 f f i i c Choose the unvisited vertex with the smallest label, in this case b. 3 ∞ ∞ 3 2(a) b d d g g 8 3 2 2 1 ∞ h h 6 3 6(a) a z z e e ∞ 6 1 8 3 9 f f i i c c 1 3(a) ∞ 3 ∞ Vertex List: a:0 b: 2 c: 3 d: ∞ e: 6 f: ∞ g: ∞ h: ∞ i: ∞ z: ∞

3 ∞ 3 b d d g g 8 3 2 2 1 ∞ h h 6 3 a z z e e ∞ 6 1 8 3 9 f f i i c c Re-label all vertices that can be reached from b now. 3 ∞ 3 2(a) 5(a,b) b d d g g 8 3 2 2 1 ∞ h h 6 3 5(a,b) a z z e e ∞ 6 1 8 3 9 f f i i c c 1 3(a) ∞ 3 ∞ Vertex List: a:0 b: 2 c: 3 d: 5 e: 6 5 f: ∞ g: ∞ h: ∞ i: ∞ z: ∞

3 ∞ 3 b d d g g 8 3 2 2 1 ∞ h h 6 3 a z z e e ∞ 6 1 8 3 9 f f i i c c Choose the unvisited vertex with the smallest label, now c. 3 ∞ 3 2(a) 5(a,b) b d d g g 8 3 2 2 1 ∞ h h 6 3 5(a,b) a z z e e ∞ 6 1 8 3 9 f f i i c c 1 3(a) ∞ 3 ∞ Vertex List: a:0 b: 2 c: 3 d: 5 e: 5 f: ∞ g: ∞ h: ∞ i: ∞ z: ∞

3 ∞ 3 b d d g g 8 3 2 2 1 ∞ h h 6 3 a z z e e ∞ 6 1 8 3 9 f f i i c c Re-label, now including c 3 ∞ 3 2(a) 5(a,b) b d d g g 8 3 2 2 1 ∞ h h 6 3 5(a,b) a z z e e ∞ 6 1 8 3 9 f f i i c c 1 3(a) 4(a,c) 3 ∞ Vertex List: a:0 b: 2 c: 3 d: 5 e: 5 f: 4 g: ∞ h: ∞ i: ∞ z: ∞

3 ∞ 3 b d d g g 8 3 2 2 1 ∞ h h 6 3 a z z e e ∞ 6 1 8 3 9 f f i i c c Choose the smallest unvisited vertex, f 3 ∞ 3 2(a) 5(a,b) b d d g g 8 3 2 2 1 ∞ h h 6 3 5(a,b) a z z e e ∞ 6 1 8 3 9 f f i i c c 1 3(a) 4(a,c) 3 ∞ Vertex List: a:0 b: 2 c: 3 d: 5 e: 5 f: 4 g: ∞ h: ∞ i: ∞ z: ∞

3 ∞ 3 b d d g g 8 3 2 2 1 ∞ h h 6 3 a z z e e 6 1 8 3 9 f f i i c c 1 Re-label, now using f 3 ∞ 3 2(a) 5(a,b) b d d g g 8 3 2 2 1 ∞ h h 6 3 5(a,b) a z z e e 12(a,c,f) 6 1 8 3 9 f f i i c c 1 3(a) 4(a,c) 3 7(a,c,f) Vertex List: a:0 b: 2 c: 3 d: 5 e: 5 f: 4 g: ∞ h: 12 i: 7 z: ∞

3 ∞ 3 b d d g g 8 3 2 2 1 ∞ h h 6 3 a z z e e 6 1 8 3 9 f f i i c c 1 Smallest unvisited vertex is now d (alphabetical tie over e) 3 ∞ 3 2(a) 5(a,b) b d d g g 8 3 2 2 1 ∞ h h 6 3 5(a,b) a z z e e 12(a,c,f) 6 1 8 3 9 f f i i c c 1 3(a) 4(a,c) 3 7(a,c,f) Vertex List: a:0 b: 2 c: 3 d: 5 e: 5 f: 4 g: ∞ h: 12 i: 7 z: ∞

Re-label using d 3 3 2(a) 5(a,b) 8(a,b,d) b d d g g 8 3 2 2 1 ∞ h h 6 3 5(a,b) a z z e e 12(a,c,f) 6 1 8 3 9 f f i i c c 1 3(a) 4(a,c) 3 7(a,c,f) Vertex List: a:0 b: 2 c: 3 d: 5 e: 5 f: 4 g: 8 h: 12 i: 7 z: ∞

Smallest unvisited vertex is now e 3 3 2(a) 5(a,b) 8(a,b,d) b d d g g 8 3 2 2 1 ∞ h h 6 3 5(a,b) a z z e e 12(a,c,f) 6 1 8 3 9 f f i i c c 1 3(a) 4(a,c) 3 7(a,c,f) Vertex List: a:0 b: 2 c: 3 d: 5 e: 5 f: 4 g: 8 h: 12 i: 7 z: ∞

Re-label using e, but no vertex gets updated 3 3 2(a) 5(a,b) 8(a,b,d) b d d g g 8 3 2 2 1 ∞ h h 6 3 5(a,b) a z z e e 12(a,c,f) 6 1 8 3 9 f f i i c c 1 3(a) 4(a,c) 3 7(a,c,f) Vertex List: a:0 b: 2 c: 3 d: 5 e: 5 f: 4 g: 8 h: 12 i: 7 z: ∞

Smallest unvisited vertex is i 3 3 2(a) 5(a,b) 8(a,b,d) b d d g g 8 3 2 2 1 ∞ h h 6 3 5(a,b) a z z e e 12(a,c,f) 6 1 8 3 9 f f i i c c 1 3(a) 4(a,c) 3 7(a,c,f) Vertex List: a:0 b: 2 c: 3 d: 5 e: 5 f: 4 g: 8 h: 12 i: 7 z: ∞

Re-label using i 3 3 2(a) 5(a,b) 8(a,b,d) b d d g g 8 3 2 2 1 h h 6 3 16(a,c,f,i) 5(a,b) a z z e e 12(a,c,f) 6 1 8 3 9 f f i i c c 1 3(a) 4(a,c) 3 7(a,c,f) Vertex List: a:0 b: 2 c: 3 d: 5 e: 5 f: 4 g: 8 h: 12 i: 7 z: 16

Now, choose g 3 3 2(a) 5(a,b) 8(a,b,d) b d d g g 8 3 2 2 1 h h 6 3 16(a,c,f,i) 5(a,b) a z z e e 12(a,c,f) 6 1 8 3 9 f f i i c c 1 3(a) 4(a,c) 3 7(a,c,f) Vertex List: a:0 b: 2 c: 3 d: 5 e: 5 f: 4 g: 8 h: 12 i: 7 z: 16

Re-label, using g 3 3 2(a) 5(a,b) 8(a,b,d) b d d g g 8 3 2 2 1 h h 6 3 16(a,c,f,i) 5(a,b) a z z e e 9(a,b,d,g) 6 1 8 3 9 f f i i c c 1 3(a) 4(a,c) 3 7(a,c,f) Vertex List: a:0 b: 2 c: 3 d: 5 e: 5 f: 4 g: 8 h: 12 9 i: 7 z: 16

Now choose h 3 3 2(a) 5(a,b) 8(a,b,d) b d d g g 8 3 2 2 1 h h 6 3 16(a,c,f,i) 5(a,b) a z z e e 9(a,b,d,g) 6 1 8 3 9 f f i i c c 1 3(a) 4(a,c) 3 7(a,c,f) Vertex List: a:0 b: 2 c: 3 d: 5 e: 5 f: 4 g: 8 h: 9 i: 7 z: 16

Re-label using h 3 3 2(a) 5(a,b) 8(a,b,d) b d d g g 8 3 2 2 1 h h 6 3 12(a,b,d,g,h) 5(a,b) a z z e e 9(a,b,d,g) 6 1 8 3 9 f f i i c c 1 3(a) 4(a,c) 3 7(a,c,f) Vertex List: a:0 b: 2 c: 3 d: 5 e: 5 f: 4 g: 8 h: 9 i: 7 z: 16 12

No vertices left to consider, so we have the shortest path 3 3 2(a) 5(a,b) 8(a,b,d) b d d g g 8 3 2 2 1 h h 6 3 12(a,b,d,g,h) 5(a,b) a z z e e 9(a,b,d,g) 6 1 8 3 9 f f i i c c 1 3(a) 4(a,c) 3 7(a,c,f) Vertex List: a:0 b: 2 c: 3 d: 5 e: 5 f: 4 g: 8 h: 9 i: 7 z: 16 12