Presentation is loading. Please wait.

Presentation is loading. Please wait.

Shortest Path Dr. Yasir. Weighted Graphs In many applications, each edge of a graph has an associated numerical value, called a weight. Usually, the edge.

Similar presentations


Presentation on theme: "Shortest Path Dr. Yasir. Weighted Graphs In many applications, each edge of a graph has an associated numerical value, called a weight. Usually, the edge."— Presentation transcript:

1 Shortest Path Dr. Yasir

2 Weighted Graphs In many applications, each edge of a graph has an associated numerical value, called a weight. Usually, the edge weights are nonnegative integers. Weighted graphs may be either directed or undirected. The weight of an edge is often referred to as the "cost" of the edge. In applications, the weight may be a measure of the length of a route, the capacity of a line, the energy required to move between locations along a route, etc.

3 Weight of edges can represent everything in real world, e.g amount of money to be transferred from one account to an other account can be positive or negative, Think of a driver, who gets paid to drive his employer from s to t but he pays between a and b (say travelling between his home and his workplace). Weighted Graphs

4 Shortest Path Given a weighted graph, and a designated node S, we would like to find a path of least total weight from S to each of the other vertices in the graph. The total weight of a path is the sum of the weights of its edges.

5 Single-Source Shortest Path Problem The problem of finding shortest paths from a source vertex v to all other vertices in the graph.

6 Applications Traffic Information Systems are most prominent use - Mapping (Map Quest, Google Maps) - Routing Systems

7 Dijkstra's Algorithm is a solution to the single-source shortest path problem in graph theory. Works on both directed and undirected graphs. However, all edges must have nonnegative weights. Approach: Greedy Input: Weighted graph G={E,V} and source vertex v ∈ V, such that all edge weights are nonnegative. Output: Lengths of shortest paths (or the shortest paths themselves) from a given source vertex v ∈ V to all other vertices. Complexity: |E| log |V| A greedy algorithm is a mathematical process that looks for simple, easy-to-implement solutions to complex, multi-step problems by deciding which next step will provide the most obvious benefit.

8 Edsger Wybe Dijkstra May 11, 1930 – August 6, 2002 - Received the 1972 A. M. Turing Award, widely considered the most prestigious award in computer science. - The Schlumberger Centennial Chair of Computer Sciences at The University of Texas at Austin from 1984 until 2000 - Made a strong case against use of the GOTO statement in programming languages and helped lead to its deprecation. - Known for his many essays on programming.

9 Dijkstra's Algorithm – Main Idea The idea is to visit the nodes in order of their closeness to source vertex s. The closest node to s, say x, must be adjacent to s and the next closest be either adjacent to s or x. The third closest node to s must be either adjacent to s or x or y, and so on.

10

11 Relaxation

12 3 5 6 2 2 9 6 2 7 3 1 5 Dijkstra's Algorithm – Working

13 3 5 6 2 2 9 6 2 7 3 1 5 Initialize: Dijkstra's Algorithm – Working 0

14 d 3 5 6 2 2 9 6 2 7 3 1 5 Blue shows the relaxation process

15 c 3 5 6 2 2 9 6 2 7 3 1 5 Dijkstra's Algorithm – Working

16 3 5 6 2 2 9 6 2 7 3 1 5 Red shows that these vertices are visited and decision has been made

17 3 5 6 2 2 9 6 2 7 3 1 5 Dijkstra's Algorithm – Working

18 3 5 6 2 2 9 6 2 7 3 1 5

19 ce bdf 3 5 6 2 2 9 6 2 7 3 1 5

20 ce bdf 3 5 6 2 2 9 6 2 7 3 1 5

21 ce bdf 3 5 6 2 2 9 6 2 7 3 1 5 Yellow line represent that this edge is of no more use.

22 ce bdf 3 5 6 2 2 9 6 2 7 3 1 5 Dijkstra's Algorithm – Working

23 ce bdf 3 5 6 2 2 9 6 2 7 3 1 5

24 ce bdf 3 5 6 2 2 9 6 2 7 3 1 5

25 ce bdf 3 5 6 2 2 9 6 2 7 3 1 5

26 ce bdf 3 5 6 2 2 9 6 2 7 3 1 5

27 ce bdfg 3 5 6 2 2 9 6 2 7 3 1 5

28


Download ppt "Shortest Path Dr. Yasir. Weighted Graphs In many applications, each edge of a graph has an associated numerical value, called a weight. Usually, the edge."

Similar presentations


Ads by Google