Sei sulla pagina 1di 40

Algorithms

Mathematical view on networking

dr. C. P. J. Koymans
Informatics Institute University of Amsterdam
(version 1.2, 2010/02/23 13:59:54)

Monday, February 22, 2010

dr. C. P. J. Koymans (UvA)

Algorithms

Monday, February 22, 2010

1 / 33

Distance vector algorithms A basic triangle Flooding Bellman-Ford Memorizing alternatives Counting to Algorithms based on global or centralized information Shortest Path Tree
Dijkstra Demos

Minimum Spanning Tree


Prim Kruskal Demos

Properties

dr. C. P. J. Koymans (UvA)

Algorithms

Monday, February 22, 2010

2 / 33

Distance vector algorithms

Outline
1

Distance vector algorithms A basic triangle Flooding Bellman-Ford Memorizing alternatives Counting to Algorithms based on global or centralized information Shortest Path Tree
Dijkstra Demos

Minimum Spanning Tree


Prim Kruskal Demos

Properties
dr. C. P. J. Koymans (UvA) Algorithms Monday, February 22, 2010 3 / 33

Distance vector algorithms

A basic triangle

Outline
1

Distance vector algorithms A basic triangle Flooding Bellman-Ford Memorizing alternatives Counting to Algorithms based on global or centralized information Shortest Path Tree
Dijkstra Demos

Minimum Spanning Tree


Prim Kruskal Demos

Properties
dr. C. P. J. Koymans (UvA) Algorithms Monday, February 22, 2010 4 / 33

Distance Vector

Origin From A From B From C

Distance to N 0 1 10

Via A A A

Origin From A From B From C

Distance to N 0

Via A

Distance Vector

Origin From A From B From C

Distance to N 0 1 10

Via A A A

Origin From A From B From C

Distance to N 0 1

Via A A

Distance Vector

Origin From A From B From C

Distance to N 0 1 10

Via A A A

Origin From A From B From C

Distance to N 0 1 2

Via A A B

Distance vector algorithms

Flooding

Outline
1

Distance vector algorithms A basic triangle Flooding Bellman-Ford Memorizing alternatives Counting to Algorithms based on global or centralized information Shortest Path Tree
Dijkstra Demos

Minimum Spanning Tree


Prim Kruskal Demos

Properties
dr. C. P. J. Koymans (UvA) Algorithms Monday, February 22, 2010 6 / 33

Distance vector algorithms

Flooding

Flooding

Origin A B C D

Distance to N 0 1 2 ?

Via A A A ?

Origin A B C D

Distance to N 0 1 2

Via A A A

dr. C. P. J. Koymans (UvA)

Algorithms

Monday, February 22, 2010

7 / 33

Distance vector algorithms

Flooding

Flooding

Origin A B C D

Distance to N 0 1 2 ?

Via A A A ?

Origin A B C D

Distance to N 0 1 2 3

Via A A A B or C

dr. C. P. J. Koymans (UvA)

Algorithms

Monday, February 22, 2010

7 / 33

Distance vector algorithms

Flooding

Flooding

Origin A B C D

Distance to N 0 1 2 ?

Via A A A ?

Origin A B C D

Distance to N 0 1 2 3

Via A A A B or C

The orange messages dont change anything and the algorithm has converged
dr. C. P. J. Koymans (UvA) Algorithms Monday, February 22, 2010 7 / 33

Distance vector algorithms

Bellman-Ford

Outline
1

Distance vector algorithms A basic triangle Flooding Bellman-Ford Memorizing alternatives Counting to Algorithms based on global or centralized information Shortest Path Tree
Dijkstra Demos

Minimum Spanning Tree


Prim Kruskal Demos

Properties
dr. C. P. J. Koymans (UvA) Algorithms Monday, February 22, 2010 8 / 33

Distance vector algorithms

Bellman-Ford

Undirected graphs

Given an undirected graph G =< V , E >


E is a subset of V V If < i , j > E then i j

Every edge < i , j > E has distance dij = dji


dij = if < i , j > E We assume that all distances are positive

dr. C. P. J. Koymans (UvA)

Algorithms

Monday, February 22, 2010

9 / 33

Distance vector algorithms

Bellman-Ford

Centralized shortest path calculation

We seek the shortest paths from(to) any node i to(from) node j Dn (i , j ) is the distance from i to j using no more than n steps

Denition (Bellmans equations (centralized)) D0 (i , i ) = 0


D0 (i , j ) = for i j Dn+1 (i , j ) = mink (Dn (i , k ) + dkj ) D (i , j ) = limn Dn (i , j ) D (i , j ) = mink (D (i , k ) + dkj ) in the limit case

dr. C. P. J. Koymans (UvA)

Algorithms

Monday, February 22, 2010

10 / 33

Distance vector algorithms

Bellman-Ford

Distributed shortest path calculation


Choose a xed target node t. We seek the shortest paths from any node i to target t Dn (i ) is the distance from i to t using no more than n steps

Denition (Bellmans equations (distributed)) D0 (t ) = 0


D0 (i ) = for i t

Dn+1 (i ) = minj (dij + Dn (j )) D (i ) = limn Dn (i ) D (i ) = minj (dij + D (j )) in the limit case


dr. C. P. J. Koymans (UvA) Algorithms Monday, February 22, 2010 11 / 33

Distance vector algorithms

Memorizing alternatives

Outline
1

Distance vector algorithms A basic triangle Flooding Bellman-Ford Memorizing alternatives Counting to Algorithms based on global or centralized information Shortest Path Tree
Dijkstra Demos

Minimum Spanning Tree


Prim Kruskal Demos

Properties
dr. C. P. J. Koymans (UvA) Algorithms Monday, February 22, 2010 12 / 33

Distance vector algorithms

Memorizing alternatives

Adding memory

You can also keep the information about distance to a certain node via (longer) backup paths In case of failure of best link, fall back to second best link This makes the algorithm dynamic But also introduces some quirks!

dr. C. P. J. Koymans (UvA)

Algorithms

Monday, February 22, 2010

13 / 33

Linear case

Origin A B C

Best to N 0 via A 1 via A 2 via B

Second best none none none

Origin A B C

Best to N 0 via A 1 via A 2 via B

Second best 2 via B 3 via C none

Linear case

Origin A B C

Best to N 0 via A 1 via A 2 via B

Second best 2 via B 3 via C none

Origin A B C

Best to N 0 via A /1//////////////// //// via/ A 2 via B

Second best /2//via///B/ //// //////// /// 3 via C none

Linear case

Origin A B C

Best to N 0 via A 3 via C 2 via B

Second best none none none

Origin A B C

Best to N 0 via A 3 via C /2//////////////// //// via/ B

Second best none none 4 via B

Linear case

Origin A B C

Best to N 0 via A 3 via C 4 via B

Second best none none none

Origin A B C

Best to N 0 via A /3//via//C //// ///////// //// 4 via B

Second best none 5 via C none

Distance vector algorithms

Counting to

Outline
1

Distance vector algorithms A basic triangle Flooding Bellman-Ford Memorizing alternatives Counting to Algorithms based on global or centralized information Shortest Path Tree
Dijkstra Demos

Minimum Spanning Tree


Prim Kruskal Demos

Properties
dr. C. P. J. Koymans (UvA) Algorithms Monday, February 22, 2010 15 / 33

Counting to (without memory)

Before A has a chance to tell B that its link to N is down B could have told A that it can reach network N with distance one, letting A start thinking it can (still) reach N (now with distance two.)

Distance vector algorithms

Counting to

Counting to solutions

Innity is in fact nite :)


Universal Truth in Computer Science

Split horizon
Dont advertise back to advertiser itself B does not report N back to A

Poison reverse
B reports innite distance to N back to A

dr. C. P. J. Koymans (UvA)

Algorithms

Monday, February 22, 2010

17 / 33

Still counting to

B and C keep fooling each other about a route to N, because they dont know that the others route is also via the blocked path through A. Split horizon doesnt help, because information is relayed via A.

Algorithms based on global or centralized information

Outline
1

Distance vector algorithms A basic triangle Flooding Bellman-Ford Memorizing alternatives Counting to Algorithms based on global or centralized information Shortest Path Tree
Dijkstra Demos

Minimum Spanning Tree


Prim Kruskal Demos

Properties
dr. C. P. J. Koymans (UvA) Algorithms Monday, February 22, 2010 19 / 33

Algorithms based on global or centralized information

Examples of global, centralized algorithms

Calculating the (Single Source) Shortest Path Tree (SPT)


Dijkstras algorithm

Calculating the Minimum Spanning Tree (MST)


Prims algorithm Kruskals algorithm

The complete graph needs to be known and is static

dr. C. P. J. Koymans (UvA)

Algorithms

Monday, February 22, 2010

20 / 33

Algorithms based on global or centralized information

Shortest Path Tree

Outline
1

Distance vector algorithms A basic triangle Flooding Bellman-Ford Memorizing alternatives Counting to Algorithms based on global or centralized information Shortest Path Tree
Dijkstra Demos

Minimum Spanning Tree


Prim Kruskal Demos

Properties
dr. C. P. J. Koymans (UvA) Algorithms Monday, February 22, 2010 21 / 33

Algorithms based on global or centralized information

Shortest Path Tree

SPT

Given a directed graph G =< V , E >


E is a subset of V V If < i , j > E then i j

Every edge < i , j > E has distance (weight) dij


dij = if < i , j > E We assume that all distances are positive

dr. C. P. J. Koymans (UvA)

Algorithms

Monday, February 22, 2010

22 / 33

Algorithms based on global or centralized information

Shortest Path Tree

Dijkstras algorithm (1)

Choose a start node s V Calculate tentative distance Di from s to all nodes i


Di Di 0 if i = s

if i

Make the node i with minimal tentative distance permanent


Put i in P (at rst i = s)

Mark node i as latest addition to P

dr. C. P. J. Koymans (UvA)

Algorithms

Monday, February 22, 2010

23 / 33

Algorithms based on global or centralized information

Shortest Path Tree

Dijkstras algorithm (2)

Let i be the latest addition to P Update tentative distances for nodes j not in P
Dj min{Dj , Di + dij } (relaxation)

Make the node j with minimal tentative distance permanent


Put j in P

Mark node j as latest addition to P Repeat until P = V

dr. C. P. J. Koymans (UvA)

Algorithms

Monday, February 22, 2010

24 / 33

Algorithms based on global or centralized information

Shortest Path Tree

Demo Dijkstra

http://www-b2.is.tokushima-u.ac.jp/~ikeda/suuri/ dijkstra/Dijkstra.shtml (Dijkstra 1) http://www.dgp.toronto.edu/people/JamesStewart/270/ 9798s/Laffra/DijkstraApplet.html (Dijkstra 2)

dr. C. P. J. Koymans (UvA)

Algorithms

Monday, February 22, 2010

25 / 33

Algorithms based on global or centralized information

Minimum Spanning Tree

Outline
1

Distance vector algorithms A basic triangle Flooding Bellman-Ford Memorizing alternatives Counting to Algorithms based on global or centralized information Shortest Path Tree
Dijkstra Demos

Minimum Spanning Tree


Prim Kruskal Demos

Properties
dr. C. P. J. Koymans (UvA) Algorithms Monday, February 22, 2010 26 / 33

Algorithms based on global or centralized information

Minimum Spanning Tree

MST

Given an undirected graph G =< V , E >


V is a set of vertices (nodes) E is a set of edges (arcs) between different nodes
E is a subset of V V If < i , j > E then i j and < j , i > E

Every edge < i , j > E has a distance (weight) dij = dji


dij = if < i , j > E

We always assume that G is connected

dr. C. P. J. Koymans (UvA)

Algorithms

Monday, February 22, 2010

27 / 33

Algorithms based on global or centralized information

Minimum Spanning Tree

Prims algorithm
Start constructing a tree < T , B > with an arbitrary node n V and no branches
T B

{n }

Add a new branch b to the tree of minimum distance (weight) connecting T with a new node m outside the tree
T B T {m } B {b }

Repeat until T = V : B is your MST! Why?


dr. C. P. J. Koymans (UvA) Algorithms Monday, February 22, 2010 28 / 33

Algorithms based on global or centralized information

Minimum Spanning Tree

Kruskals algorithm

Create a forest F by rst considering every node in isolation


F

{< {n}, > |n V }

Pick a minimal distance (weight) edge e that joins any two fragments < V1 , E1 > and < V2 , E2 > in F
F

(F {< V1 , E1 >, < V2 , E2 >}) < V1 V2 , E1 E2 {e } >

Why does this work?

dr. C. P. J. Koymans (UvA)

Algorithms

Monday, February 22, 2010

29 / 33

Algorithms based on global or centralized information

Minimum Spanning Tree

Demos

http://www-b2.is.tokushima-u.ac.jp/~ikeda/suuri/main/ index.shtml
http://www-b2.is.tokushima-u.ac.jp/~ikeda/suuri/ dijkstra/Prim.shtml (Prim) http://www-b2.is.tokushima-u.ac.jp/~ikeda/suuri/kruskal/ Kruskal.shtml (Kruskal)

dr. C. P. J. Koymans (UvA)

Algorithms

Monday, February 22, 2010

30 / 33

Algorithms based on global or centralized information

Properties

Outline
1

Distance vector algorithms A basic triangle Flooding Bellman-Ford Memorizing alternatives Counting to Algorithms based on global or centralized information Shortest Path Tree
Dijkstra Demos

Minimum Spanning Tree


Prim Kruskal Demos

Properties
dr. C. P. J. Koymans (UvA) Algorithms Monday, February 22, 2010 31 / 33

Algorithms based on global or centralized information

Properties

Properties

All algorithms generate spanning trees If there is a unique MST, Kruskal may be parallellised If all distances (weights) are different there is a unique MST Not every MST is automatically a SPT for all nodes

dr. C. P. J. Koymans (UvA)

Algorithms

Monday, February 22, 2010

32 / 33

MST is not SPT

The red tree is the shortest path tree, starting in A. This is denitely not a minimum spanning tree.

Potrebbero piacerti anche