shortest path algorithm

20
Shortest Path Problem • Given: network topology with link costs – c(x , y): link cost from node x to node y – Infinity if x and y are not direct neighbors • Compute: least-cost paths to all nodes – From a given source u to all other nodes. 3 2 1 1 4 1 4 5 3 2 A B C D E F G H

Upload: subrata-paul

Post on 11-Apr-2017

515 views

Category:

Engineering


4 download

TRANSCRIPT

Page 1: Shortest  path algorithm

Shortest Path Problem

• Given: network topology with link costs– c(x , y): link cost from node x to node y– Infinity if x and y are not direct neighbors

• Compute: least-cost paths to all nodes– From a given source u to all other nodes.

3

2

1

14

1

4

5

3

2

A

B

C

D E

F

G

H

Page 2: Shortest  path algorithm

Subrata paul

Roll No :- 13015411. Department Of Computer Science & Engineering ,

University Of Rajshahi.

Shortest Path Routing

Page 3: Shortest  path algorithm

What Is Routing ?? •A famous quotation from RFC 791

“A name indicates what we seek.An address indicates where it is.A route indicates how we get there.” -- Jon Postel

• Routing is the process of selecting best paths.

Page 4: Shortest  path algorithm

Goals Of Routing Algorithm

• We want any several properties of any routing schema.

Property Meaning

Correctness Finds paths that work

Efficient Paths Use network bandwidth well

Fair Paths Doesn’t starve any nodes

Fast Convergence Recovers quickly after changes

Salability Works well as network grows large

Page 5: Shortest  path algorithm

What Are The Best Paths ??

• Many Possibilities :- - Latency, avoid circuitous paths.- Bandwidth, avoid slow links .- Money, avoid expensive links .- Hops, reduce switching .

A

BC

DE

F

G

Page 6: Shortest  path algorithm

Shortest Paths (1)

• Find the shortest path from A E.• All links are bidirectional , with equal cost in

both direction.

Page 7: Shortest  path algorithm

Shortest Path(2)

• ABCE is a shortest path• Dist(ABCE) = 4 + 2 + 1 = 7• This is less than : - Dist(ABE) = 8 - Dist(ABFE) = 9 - Dist(AE) = 10 - Dist(ABCDE) = 10

Page 8: Shortest  path algorithm

How To Compute ??

• Using Dijkstra’s Algorithm :- - Given a network topology . We are about to

compute shortest path from a source to all other nodes of the network.

Page 9: Shortest  path algorithm

Dijkstra’s Algorithm

• Algorithm :- - Mark all nodes tentative , set distances from source to 0(Zero)

for source and ∞(infinity) for all other nodes

- While tentative nodes remain : a ) Extract N , a node with lowest distance b) Add link to N to the shortest path tree C) Relax the distances of neighbors of N by lowering any

better distance estimates

Page 10: Shortest  path algorithm

Dijkstra’s AlgorithmA B C D E F G H

0 ∞ ∞ ∞ ∞ ∞ ∞ ∞

Page 11: Shortest  path algorithm

Dijkstra’s AlgorithmA B C D E F G H

0 4 ∞ ∞ 10 ∞ ∞ ∞

Page 12: Shortest  path algorithm

Dijkstra’s AlgorithmA B C D E F G H

0 4 6 ∞ 8 7 7 ∞

Page 13: Shortest  path algorithm

Dijkstra’s AlgorithmA B C D E F G H

0 4 6 8 7 7 7 9

Page 14: Shortest  path algorithm

Dijkstra’s AlgorithmA B C D E F G H0 ∞ ∞ ∞ ∞ ∞ ∞ ∞A B C D E F G H

0 4 6 8 7 7 7 9

Page 15: Shortest  path algorithm

Dijkstra’s AlgorithmA B C D E F G H0 ∞ ∞ ∞ ∞ ∞ ∞ ∞A B C D E F G H

0 4 6 8 7 7 7 9

Page 16: Shortest  path algorithm

Dijkstra’s AlgorithmA B C D E F G H0 ∞ ∞ ∞ ∞ ∞ ∞ ∞A B C D E F G H

0 4 6 8 7 7 7 9

Page 17: Shortest  path algorithm

Dijkstra’s AlgorithmA B C D E F G H0 ∞ ∞ ∞ ∞ ∞ ∞ ∞A B C D E F G H

0 4 6 8 7 7 7 9

Page 18: Shortest  path algorithm

Dijkstra’s AlgorithmA B C D E F G H0 ∞ ∞ ∞ ∞ ∞ ∞ ∞A B C D E F G H

0 4 6 8 7 7 7 9

All nodes are done now.

Page 19: Shortest  path algorithm

Dijkstra’s Algorithm • So , the shortest path from source node A to all

other nodes are –A – B = 4A – C = 6A – D = 8A – E = 7A – F = 7A – G = 7A – H = 9

Page 20: Shortest  path algorithm

Conclusion • Routing is a distributed algorithm

– React to changes in the topology– Compute the shortest paths

• Two main shortest-path algorithms– Dijkstra– Bellman-Ford

• Convergence process– Changing from one topology to another– Transient periods of inconsistency across routers