TOM 50: Networking Theory & undamentals Lecture pril 6, 2003 Prof. Yannis. Korilis
2 Topics Routing in ata Network Graph Representation of a Network Undirected Graphs Spanning Trees and Minimum Weight Spanning Trees irected Graphs Shortest-Path lgorithms: ellman-ord ikstra loyd-warshall istributed synchronous ellman-ord lgorithm
3 Introduction to Routing What is routing? The creation of (state) information in the network to enable efficient delivery of packets to their intended destination Two main components Information acquisition: Topology, addresses Information usage: omputing good paths to all destinations Questions Where is? How to reach? How to best reach? How to best distribute all traffic (not only to )? G
4 Graph-Theoretic oncepts n Undirected Graph G = (N, ) consists of: a finite nonempty set of nodes N and a collection of arcs, interconnecting pairs of distinct nodes from N. If i and are nodes in N and (i, ) is an arc in, the arc is said to be incident on i and Walk: sequence of nodes (n, n 2,, n k ), where (n, n 2 ), (n 2, n 3 ),, (n k-, n k ) are arcs Path: a walk with no repeated nodes ycle: a walk (n, n 2,, n k ), with n =n k and no other repeated nodes onnected Graph: for all i, N, there exists a path (n, n 2,, n k ), with i=n, =n k G N = {, G,,,,, } = {(, ),(, ),(, ),(, ), (, ),( G, ),( G, )}
5 Spanning Tree graph G' = (N ', ' ), with N ' N and ' is called a subgraph of G Tree: a connected graph that contains no cycles Spanning tree of a graph G: a subgraph of G, that is a tree and contains all nodes of G, that is N ' = N G Lemma: Let G be a connected graph G = (N, ) and S a nonempty strict subset of the set of nodes N. Then, there exists at least one arc (i, ) such that i S, and S.
6 Spanning Tree lgorithm. Select arbitrary node n N, and initialize: G' = (N ', ' ), 2. If N' = N, STOP: G' = (N ', ' ) is a spanning tree LS: go to step 3 3. Let (i, ) with i N' and N-N' Update: N : = N { }, : = {( i, )} Go to step 2 N = {}, n = Proof of correctness: Use induction to establish that after a new node i is added, G' remains connected and does not contain any cycles therefore, it is a tree. fter N- iterations, the algorithm terminates, and G' contains N nodes and N- arcs.
7 onstruction of a Spanning Tree N'= {}; '= N'= {,}; '= {(,)} N'= {,,}; '= {(,),(,)} N'= {,,,}; '= {(,),(,),()} G N'= {,,,,}; '= {(,),(,),(),()} N'= {,,,,,}; '= {(,),(,),(),(),(,)} N'= {,,,,,,G}; '= {(,),(,),(),(),(,),(,G)}
8 Spanning Trees Proposition: Let G be a connected graph with N nodes and links. G contains a spanning tree 2. N- 3. G is a tree if and only if =N- Proof: The spanning tree construction algorithm starts with a single node and at each iteration augments the tree by one node and one arc. Therefore, the tree is constructed after N- iterations and has N- links. vidently N-. If =N-, the spanning tree includes all arcs of G, thus G is a tree. If >N-, there is a link (i, ) that does not belong to the tree. onsidering the path connecting nodes i and along the spanning tree, that path and link (i, ) form a cycle, thus G is not a tree.
9 Use of Spanning Trees Problem: how to distribute information to all nodes in a graph (network) e.g., address and topology information looding: each node forwards information to all its neighbors. Simple, but multiple copies of the same packet traverse each link and are received by each node Spanning tree: nodes forward information only along links that belong to the spanning tree. More efficient: Information reaches each node only once and traverses links at most once Note that spanning tree is bidirectional G
0 Minimum Weight Spanning Tree Weight w i is used to quantify the cost for using link (i, ) xamples: delay, offered load, distance, etc. Weight (cost) of a tree is the sum of the weights of all its links packets traverse all tree links once 5 2 3 6 7 4 2 3 G W = 2 efinition: Minimum Weight Spanning Tree (MST) is a spanning tree with minimum sum of link weights efinition: subtree of an MST is called a fragment. n arc with one node in a fragment and the other node not in this fragment is called an outgoing arc from the fragment. 5 2 3 6 7 4 2 G 3 W = 5
Minimum Weight Spanning Trees Lemma: Given a fragment, let e=(i, ) be an outgoing arc with minimum weight, where. Then extended by arc e and node is a fragment. Proof: Let T be the MST that includes fragment. If e T, we are done. ssume e T: then a cycle is formed by e and the arcs of T Since. there is an arc e e which belongs to the cycle and T, and is outgoing from. Let T =(T-{e }) {e}. This is subgraph with N- arcs and no cycles (since ), i.e., a spanning tree. Since w e w e, the weight of T is less than or equal to the weight of T Then T is an MST, and extended by arc e and node is a fragment. 4 e 4 3 6 7 e' 2 4 3 G
2 Minimum Weight Spanning Tree lgorithms Inductive algorithms based on the previous lemma Prim s lgorithm: Start with an arbitrary node as the initial fragmant nlarge current fragment by successively adding minimum weight outgoing arcs Kruskal s lgorithm: ll vertices are initial fragments Successively combine fragments using minimum weight arcs that do not introduce a cycle
3 Prim s lgorithm 2 3 9 7 5 6 8 4
4 Kruskall s lgorithm 2 3 9 7 5 6 8 4
5 Shortest Path lgorithms Problem: Given nodes and, find the best route for sending traffic from to est: the one with minimum cost where typically the cost of a path is equal to the sum of the costs of the links in the path Important problem in various networking applications Routing of traffic over network links need to distinguish direction of flow ppropriate network model: irected Graph
6 irected Graphs irected Graph or igraph G = (N, ) consists of: a finite nonempty set of nodes N and a collection of directed arcs, i.e., ordered pairs of distinct nodes from N. irected walks, directed paths and directed cycles can be defined to extend the corresponding definitions for undirected graphs Given a digraph G = (N, ), there is an associated undirected graph G' = (N ', ' ), with N '=N and (i, ) ' if (i, ), or (, i) digraph G = (N, ) is called connected if its associated undirected graph G' = (N ', ' ) is connected digraph G = (N, ) is called strongly connected if for every i, N, there exists a directed path (n, n 2,, n k ), with i=n, =n k
7 Shortest Path lgorithms Problem ormulation onsider an N vertex graph G = (N, ) with link lengths d i for edge (i,) (d i = if (i,) ) Problem: ind minimum distance paths from all vertices in N to vertex lternatively, find minimum weight paths from vertex to all vertices in N General approach is again iterative ( n+ ) ( n) = min{ + d i ifferences are in how the iterations proceed Three main algorithms i }
ellman-ord lgorithm Iterative step is over increasing hop count efine ih as a shortest walk from node i to that contains at most h edges h = 0 by definition for all h ellman-ord lgorithm h+ h efine i = min{ + di}, i Set initial conditions to 0 i = for i a The scalars h i are equal to the shortest walk lengths with less than h hops from node i to node b The algorithm terminates after at most N iterations if there are no negative length cycles without node, and it yields the shortest path lengths to node 8
Proof of ellman-ord () Proof is by induction on hop count h or h = we have i = d i for all i, so the result holds for i = ssume that the result holds for all k h. We need to show it still holds for h+ Two cases need to be considered The shortest ( h+) walk from i to has h edges Its length is then i h 2 The shortest ( h+) walk from i to has (h+) edges It consists of the concatenation of an edge (i,) followed by a shortest h hop walk from vertex to vertex This second case is the one we will focus on 9
Proof of ellman-ord (2) rom ase and ase 2, we have shortest ( rom induction hypothesis and initial conditions k i k- i for all k h so that h+ h h = min + d min + d = i h i = d i = d i + h ombining the two gives shortest ( = i min which completes the proof of part a { [ ]} h h, min d h + ) walk length = min + { h h+ } h+, = i h + ) i walk length i = min i [ ] [ ] h i i { [ ]} h h,min + d i i 20 i i
Proof of ellman-ord (3) ssume that the algorithm terminates after h steps This implies that i k = i h for all i and k h This means that adding more edges cannot decrease the length of any of those walks Hence, there cannot be negative length cycles that do not include node They could be repeated many times to make walk lengths arbitrarily small elete all such cycles This yields paths of less than or equal length So for all i we have a path of h hops or less to vertex and with length i h Since those paths have no cycles they contain at most N- edges,and therefore in = N- i for all i The algorithm terminates after at most N steps, which proves part b 2
ellman-ord omplexity Worst-case amount of computation to find shortest path lengths lgorithm iterates up to N times ach iteration is done for N- nodes (all i ) Minimization step requires considering up to N- alternatives omputational complexity is O(N 3 ) More careful accounting yields a computational complexity of O(hM) 22
onstructing Shortest Paths - algorithm yields shortest path lengths, but we are also interested in actual paths Start with - equation i = G [ + d ], i, and 0 min = i or all vertices i pick the edge (i,) that minimizes - equation This generates a subgraph with N- edges (a tree) or any vertex i follow the edges from vertex i along this subgraph until vertex is reached Note: In graphs without zero or negative length cycles, - equation defines a system of N- equations with a unique solution 23
onstructing Shortest Paths = 3 + = 4 + G G = 3 + = 3 = 2 + G = + = 6 + = 6 4 4 7 6 3 2 3 G 4 = --G- 24
ikstra s lgorithm () ifferent iteration criteria lgorithm proceeds by increasing path length instead of increasing hop count Start with closest vertex to destination, use it to find the next closest vertex, and so on Successful iteration requires non-negative edge weights ikstra s algorithm maintains two sets of vertices L: Labeled vertices (shortest path is known) : andidate vertices (shortest path not yet known) One vertex is moved from to L in each iteration 25
ikstra s lgorithm (2) Initialization L = {} and = G - L; (vertex is the destination) = 0 and = d for Iteration steps ind the next closest vertex not in L, i.e., ind the vertex i L such that i = min Update and L: L = L {i} and = - {i} 2 Update lengths of paths of vertices remaining in : = min[ + d lgorithm stops when L = G, i i L ], 26
Proof of ikstra s lgorithm () t the beginning of each step, we have a i for all i L and L b or any vertex, is the shortest distance from to for any path using vertices (except possibly ) only in L Proof of condition (a) (a) is satisfied initially We have d i 0 and i = min L so that condition (a) is preserved by the update equation : = min[, + d ], i non-negative edge weights i 27
Proof of ikstra s lgorithm (2) It remains to prove condition (b), which we proceed to do by induction (b) is satisfied initially Induction hypothesis (H) ondition (b) holds at the beginning of some step, where i is the vertex added to L at that step rom (H), condition (b) holds for vertex i as well as L from (a) onsider next a vertex L {i} 28
Proof of ikstra s lgorithm (3) Let be the length of the shortest path from L {i} to with all its vertices but in L {i} This path consists of an edge (,k), k L {i}, concatenated with the shortest path from k to with vertices in L {i} rom (H), k is the length of this shortest path from k to We have ' = min [ k + d k ] = min min[ k + d k ], i + d k L { i} k L nd from (H) we also have = min[ + d ] ombining the two gives k L Which completes the proof of the induction ' = min[, + d ] = k i k i i 29
omputational omplexity of ikstra s lgorithm s with ellman-ord we have up to N iterations, where N = G The maor saving is that in each iteration we consider each node only once ombination of step and step 2 looks first at nodes in L (step ) and then = G-L (step 2) Operations in each step have unit cost t most N iterations and N unit cost operations per iteration Total cost of O(N 2 ) (can be improved) 30
loyd-warshall lgorithm () Targeted at computing shortest paths between all pairs of vertices an accommodate positive and negative edge weights but requires no negative length cycles Iteration step is on set of vertices allowed as intermediate vertices in a path Initial condition is as for ellman-ord and ikstra, i.e., single edge paths for all vertices Next iteration allows only vertex as intermediate vertex lgorithm stops when all vertices can be used as intermediate vertices 3
loyd-warshall lgorithm (2) Initial conditions 0 i = di, i, and i n Let i be the shortest path length between vertices i and when intermediate vertices on the path are limited to vertices,2,...,n Iteration step is defined as n i + n = min[, + i i( n+ ) ( n+ ) n n ], i heck if distance between vertices i and is improved by using vertex (n+) as an intermediate vertex 32
Proof of loyd-warshall gain by induction or n=0 the initial conditions clearly give the shortest paths without intermediate vertices Induction hypothesis (H) n i or a given n, gives the shortest path length from i to with only vertices to n as intermediate vertices Shortest path from i to with only vertices to (n+) as intermediate vertices either contain vertex (n+) or does not If it does, the length of the path is the 2nd term of the iteration step If it does not, the length of the path is the st term of the iteration step 33
omplexity of loyd-warshall N iterations steps One for each possible set of intermediate vertices omputations in each iteration step involve a comparison for each pair of vertices There are N(N-) of them Total cost is O(N 3 ) quivalent to running N instances of ikstra s algorithm ach instance of ikstra gives shortest paths from all sources to one destination 34
Source ased Shortest Paths Only difference is that we want paths from a source node to all destinations instead of all sources to a destination asic approach remains the same Minor differences in defining initialization conditions and iterative steps We will consider the case of both ellman-ord and ikstra s algorithm 35
Source ased ellman-ord Source is vertex Initialization h = 0, h i0 = for i efine h+ = min{ i h + }, i distance from node to node i in at most h+ hops s before, iterate until no more progress d i 3 4 4 36 G = 5, 4 = 6, 4 = 5 3 = 3, = 3 2 = 3, 2 = 3, 2 = 4, 2 G = 7, 2 = 7 3 = 3, 3 = 3, 3 = 4, 3 G = 5, 3 = 7, 3 = 5 4 = 3, 4 = 3, 4 = 4, 3 G 4
Initialization Source ased ikstra 3 L = {} and = G - L; (vertex is the source) = 0 and i = d for Iteration steps ind next closest vertex in ind the vertex i L such that i = min L Update and L: L = L {i} and = - {i} 2 Update lengths of paths of vertices remaining in : = min[, i + d i ], 3 4 4 G 3 {}; =3, =3 {,}; =3; =3, G =7 {,,}; =3, =3; =4, G =7, =7 {,,,}; =3, =3, =4; G =5, =7, =5 {,,,,}; =3, =3, =4, =5; G =5, =6 {,,,,,G}; =3, =3, =4, =5, G =5; =6 {,,,,,G,}; =3, =3, 37 =4, =5, G =5, =6
Tree of Shortest Paths or the additive distance function we have assumed If the path p=i,i 2,...,i h, with i=i and = i h is a shortest path from i to, then for every k, 0 k h-, the subpath s=i,i 2,...,i k is a shortest path from i to i k If this did not hold, one could improve the shortest path between i and by picking the shorter path that exists between i and i k Let be the distance vector from vertex i, then a directed path p from vertex i to vertex is a shortest path iff k = l + d kl for all edges (k,l) p We can construct a shortest path tree from 38 vertex i to all other vertices
Shortest Path Tree vs Minimum Spanning Tree The two are NOT the same Minimum Spanning Tree Shortest Path Tree 3 3 2 G 3 Total weight: 0 = 6 4 3 3 2 G 3 Total weight: = 5 39 4