Distributed Algorithms - mk.cs.msu.ru

Post on 17-Apr-2022

12 views 0 download

Transcript of Distributed Algorithms - mk.cs.msu.ru

Distributed Algorithms

LECTURER: V.A. ZAKHAROV

Lecture 5.

Routing problem.

Destination-based routing.

The all-pairs shortest-path problem.

Floyd�Warshall algorithm.

Toueg's shortest-path algorithm.

Merlin�Segall algorithm.

Chandy�Misra algorithm.

Routing problem

A process (a node in a computer network) is in general notconnected directly to every other process by a channel.

A node can send packets of information directly only to a subset ofneighbors of the node.

Routing is a decision procedure by which a node selects one (or,sometimes, more) of its neighbors to forward a packet on its way toan ultimate destination..

The objective in designing a routing algorithm is to provide eachnode with a decision-making procedure to perform this functionand guarantee delivery of each packet.

Routing problem

Some information about the topology of the network must be storedin each node as a working basis for the (local) decision procedure.

This information will be referred as routing table . The routingproblem can be algorithmically divided into two parts:

1. Table computation. The routing tables must be computedwhen the network is initialized and must be brought up to dateif the topology of the network changes.

2. Packet forwarding. When a packet is to be sent through thenetwork it must be forwarded using the routing tables.

Routing problem

Some information about the topology of the network must be storedin each node as a working basis for the (local) decision procedure.

This information will be referred as routing table . The routingproblem can be algorithmically divided into two parts:

1. Table computation. The routing tables must be computedwhen the network is initialized and must be brought up to dateif the topology of the network changes.

2. Packet forwarding. When a packet is to be sent through thenetwork it must be forwarded using the routing tables.

Routing problem

Some information about the topology of the network must be storedin each node as a working basis for the (local) decision procedure.

This information will be referred as routing table . The routingproblem can be algorithmically divided into two parts:

1. Table computation. The routing tables must be computedwhen the network is initialized and must be brought up to dateif the topology of the network changes.

2. Packet forwarding. When a packet is to be sent through thenetwork it must be forwarded using the routing tables.

Routing problem

Criteria for estimating the qualities of routing procedures includethe following.

1. Correctness.

2. E�ciency.

3. Complexity.

4. Robustness.

5. Adaptivity.

6. Fairness.

Routing problem

Criteria for estimating the qualities of routing procedures includethe following.

1. Correctness.

2. E�ciency.

3. Complexity.

4. Robustness.

5. Adaptivity.

6. Fairness.

Routing problem

Criteria for estimating the qualities of routing procedures includethe following.

1. Correctness. The algorithm must deliver every packet o�eredto the network to its ultimate destination.

2. E�ciency.

3. Complexity.

4. Robustness.

5. Adaptivity.

6. Fairness.

Routing problem

Criteria for estimating the qualities of routing procedures includethe following.

1. Correctness.

2. E�ciency. The algorithm must send packets through optimalpaths, e.g., paths that su�er only a small delay and ensurehigh throughput of the entire network. An algorithm is calledoptimal if it uses the optimal paths.

3. Complexity.

4. Robustness.

5. Adaptivity.

6. Fairness.

Routing problem

Criteria for estimating the qualities of routing procedures includethe following.

1. Correctness.

2. E�ciency.

3. Complexity. The algorithm for the computation of the tablesmust use as few messages, time, and storage as possible.

4. Robustness.

5. Adaptivity.

6. Fairness.

Routing problem

Criteria for estimating the qualities of routing procedures includethe following.

1. Correctness.

2. E�ciency.

3. Complexity.

4. Robustness. In the case of a topological change (the additionor removal of channels or nodes) the algorithm updates therouting tables in order to perform the routing function in themodi�ed network.

5. Adaptivity.

6. Fairness.

Routing problem

Criteria for estimating the qualities of routing procedures includethe following.

1. Correctness.

2. E�ciency.

3. Complexity.

4. Robustness.

5. Adaptivity. The algorithm balances the load of channels andnodes by adapting the tables in order to avoid paths throughchannels or nodes that are very busy, preferring channels andnodes with a currently light load.

6. Fairness.

Routing problem

Criteria for estimating the qualities of routing procedures includethe following.

1. Correctness.

2. E�ciency.

3. Complexity.

4. Robustness.

5. Adaptivity.

6. Fairness. The algorithm must provide service to every user inthe same degree.

Routing problem

A network is represented as a graph, where the nodes of the graphare the nodes of the network, and there is an edge between twonodes if they have a communication channel between them. Theoptimality of paths can be de�ned di�erently.

1. Minimum hops.

2. Shortest paths.

3. Minimal delay.

Routing problem

A network is represented as a graph, where the nodes of the graphare the nodes of the network, and there is an edge between twonodes if they have a communication channel between them. Theoptimality of paths can be de�ned di�erently.

1. Minimum hops.

2. Shortest paths.

3. Minimal delay.

Routing problem

A network is represented as a graph, where the nodes of the graphare the nodes of the network, and there is an edge between twonodes if they have a communication channel between them. Theoptimality of paths can be de�ned di�erently.

1. Minimum hops. The cost of using a path is measured as thenumber of hops (traversed channels or steps from node tonode) of the path. A minimum-hop routing algorithm uses apath with the smallest possible number of hops.

2. Shortest paths.

3. Minimal delay.

Routing problem

A network is represented as a graph, where the nodes of the graphare the nodes of the network, and there is an edge between twonodes if they have a communication channel between them. Theoptimality of paths can be de�ned di�erently.

1. Minimum hops.

2. Shortest paths. Each channel is statically assigned a(non-negative) weight , and the cost of a path is measured asthe sum of the weights of the channels in the path. Ashortest-path algorithm uses a path with lowest possible cost.

3. Minimal delay.

Routing problem

A network is represented as a graph, where the nodes of the graphare the nodes of the network, and there is an edge between twonodes if they have a communication channel between them. Theoptimality of paths can be de�ned di�erently.

1. Minimum hops.

2. Shortest paths.

3. Minimal delay. Each channel is dynamically assigned a weight,depending on the tra�c on the channel. A minimum-delayalgorithm repeatedly revises the tables in such a way thatpaths with a (near) minimal total delay are always chosen.

Destination-based routing

The routing decision made when forwarding a packet is usuallybased only on the destination of the packet (and the contents ofthe routing tables), and is independent of the original sender (thesource) of the packet.

The following assumptions must hold.

A1. The cost of sending a packet via a path P is independent ofthe use of edges of P by other messages. Therefore, the costC (P) of using path P as a function of the path.

A2. The cost of the concatenation of two paths equals the sum ofthe costs of the concatenated paths, i.e.C (〈u0, u1, . . . , uk〉) = C (〈u0, . . . , ui 〉) + C (〈ui , . . . , uk〉).The cost of an empty path 〈u0〉 equals 0.

A3. The graph does not contain any cycles of negative cost.

A path from u to v is called optimal , if there are no paths from uto v of lower cost.

Destination-based routing

The routing decision made when forwarding a packet is usuallybased only on the destination of the packet (and the contents ofthe routing tables), and is independent of the original sender (thesource) of the packet.

The following assumptions must hold.

A1. The cost of sending a packet via a path P is independent ofthe use of edges of P by other messages. Therefore, the costC (P) of using path P as a function of the path.

A2. The cost of the concatenation of two paths equals the sum ofthe costs of the concatenated paths, i.e.C (〈u0, u1, . . . , uk〉) = C (〈u0, . . . , ui 〉) + C (〈ui , . . . , uk〉).The cost of an empty path 〈u0〉 equals 0.

A3. The graph does not contain any cycles of negative cost.

A path from u to v is called optimal , if there are no paths from uto v of lower cost.

Destination-based routing

The routing decision made when forwarding a packet is usuallybased only on the destination of the packet (and the contents ofthe routing tables), and is independent of the original sender (thesource) of the packet.

The following assumptions must hold.

A1. The cost of sending a packet via a path P is independent ofthe use of edges of P by other messages. Therefore, the costC (P) of using path P as a function of the path.

A2. The cost of the concatenation of two paths equals the sum ofthe costs of the concatenated paths, i.e.C (〈u0, u1, . . . , uk〉) = C (〈u0, . . . , ui 〉) + C (〈ui , . . . , uk〉).The cost of an empty path 〈u0〉 equals 0.

A3. The graph does not contain any cycles of negative cost.

A path from u to v is called optimal , if there are no paths from uto v of lower cost.

Destination-based routing

The routing decision made when forwarding a packet is usuallybased only on the destination of the packet (and the contents ofthe routing tables), and is independent of the original sender (thesource) of the packet.

The following assumptions must hold.

A1. The cost of sending a packet via a path P is independent ofthe use of edges of P by other messages. Therefore, the costC (P) of using path P as a function of the path.

A2. The cost of the concatenation of two paths equals the sum ofthe costs of the concatenated paths, i.e.C (〈u0, u1, . . . , uk〉) = C (〈u0, . . . , ui 〉) + C (〈ui , . . . , uk〉).The cost of an empty path 〈u0〉 equals 0.

A3. The graph does not contain any cycles of negative cost.

A path from u to v is called optimal , if there are no paths from uto v of lower cost.

Destination-based routing

The routing decision made when forwarding a packet is usuallybased only on the destination of the packet (and the contents ofthe routing tables), and is independent of the original sender (thesource) of the packet.

The following assumptions must hold.

A1. The cost of sending a packet via a path P is independent ofthe use of edges of P by other messages. Therefore, the costC (P) of using path P as a function of the path.

A2. The cost of the concatenation of two paths equals the sum ofthe costs of the concatenated paths, i.e.C (〈u0, u1, . . . , uk〉) = C (〈u0, . . . , ui 〉) + C (〈ui , . . . , uk〉).The cost of an empty path 〈u0〉 equals 0.

A3. The graph does not contain any cycles of negative cost.

A path from u to v is called optimal , if there are no paths from uto v of lower cost.

Destination-based routing

The routing decision made when forwarding a packet is usuallybased only on the destination of the packet (and the contents ofthe routing tables), and is independent of the original sender (thesource) of the packet.

The following assumptions must hold.

A1. The cost of sending a packet via a path P is independent ofthe use of edges of P by other messages. Therefore, the costC (P) of using path P as a function of the path.

A2. The cost of the concatenation of two paths equals the sum ofthe costs of the concatenated paths, i.e.C (〈u0, u1, . . . , uk〉) = C (〈u0, . . . , ui 〉) + C (〈ui , . . . , uk〉).The cost of an empty path 〈u0〉 equals 0.

A3. The graph does not contain any cycles of negative cost.

A path from u to v is called optimal , if there are no paths from uto v of lower cost.

Destination-based routing

Lemma 5.1. (about simple paths).

Let u and v be nodes of a graph G . If there is a path from u to vin G then there is an optimal simple path from u to v .

Proof. Obvious.

Simple questions (check yourself).

1. Is it true that every optimal path is a simple path?

2. What the assumptions A1�A3 does this lemma depend on?

Destination-based routing

Lemma 5.1. (about simple paths).

Let u and v be nodes of a graph G . If there is a path from u to vin G then there is an optimal simple path from u to v .

Proof. Obvious.

Simple questions (check yourself).

1. Is it true that every optimal path is a simple path?

2. What the assumptions A1�A3 does this lemma depend on?

Destination-based routing

Lemma 5.1. (about simple paths).

Let u and v be nodes of a graph G . If there is a path from u to vin G then there is an optimal simple path from u to v .

Proof. Obvious.

Simple questions (check yourself).

1. Is it true that every optimal path is a simple path?

2. What the assumptions A1�A3 does this lemma depend on?

Destination-based routing

Theorem 5.1. (about tree of optimal paths).

For every node u ∈ V of a connected graph G there exists such atree Tu = (V , Eu), Eu ⊆ E that for every node v ∈ V the onlypath from v in u in the tree Tu is an optimal path from v to u inthe graph G .

Proof.Let V = {v1, . . . , vN} . We will inductively construct a series oftrees Ti = (Vi , Ei ), i = 0, . . . , N, such that

1. Every tree Ti is a subgraph of G .

2. Every tree Ti is a subtree of Ti+1 .

3. vi ∈ Vi and u ∈ Vi hold for every i > 0 .

4. For every node w ∈ Vi a path from w to u in the tree Ti is anoptimal path from w to u in the graph G .

These properties imply that TN satis�es the requirements for Tu .

Destination-based routing

Theorem 5.1. (about tree of optimal paths).

For every node u ∈ V of a connected graph G there exists such atree Tu = (V , Eu), Eu ⊆ E that for every node v ∈ V the onlypath from v in u in the tree Tu is an optimal path from v to u inthe graph G .

Proof.Let V = {v1, . . . , vN} . We will inductively construct a series oftrees Ti = (Vi , Ei ), i = 0, . . . , N, such that

1. Every tree Ti is a subgraph of G .

2. Every tree Ti is a subtree of Ti+1 .

3. vi ∈ Vi and u ∈ Vi hold for every i > 0 .

4. For every node w ∈ Vi a path from w to u in the tree Ti is anoptimal path from w to u in the graph G .

These properties imply that TN satis�es the requirements for Tu .

Destination-based routing

Theorem 5.1. (about tree of optimal paths).

For every node u ∈ V of a connected graph G there exists such atree Tu = (V , Eu), Eu ⊆ E that for every node v ∈ V the onlypath from v in u in the tree Tu is an optimal path from v to u inthe graph G .

Proof.Let V = {v1, . . . , vN} . We will inductively construct a series oftrees Ti = (Vi , Ei ), i = 0, . . . , N, such that

1. Every tree Ti is a subgraph of G .

2. Every tree Ti is a subtree of Ti+1 .

3. vi ∈ Vi and u ∈ Vi hold for every i > 0 .

4. For every node w ∈ Vi a path from w to u in the tree Ti is anoptimal path from w to u in the graph G .

These properties imply that TN satis�es the requirements for Tu .

Destination-based routing

Theorem 5.1. (about tree of optimal paths).

For every node u ∈ V of a connected graph G there exists such atree Tu = (V , Eu), Eu ⊆ E that for every node v ∈ V the onlypath from v in u in the tree Tu is an optimal path from v to u inthe graph G .

Proof.Let V = {v1, . . . , vN} . We will inductively construct a series oftrees Ti = (Vi , Ei ), i = 0, . . . , N, such that

1. Every tree Ti is a subgraph of G .

2. Every tree Ti is a subtree of Ti+1 .

3. vi ∈ Vi and u ∈ Vi hold for every i > 0 .

4. For every node w ∈ Vi a path from w to u in the tree Ti is anoptimal path from w to u in the graph G .

These properties imply that TN satis�es the requirements for Tu .

Destination-based routing

Theorem 5.1. (about tree of optimal paths).

For every node u ∈ V of a connected graph G there exists such atree Tu = (V , Eu), Eu ⊆ E that for every node v ∈ V the onlypath from v in u in the tree Tu is an optimal path from v to u inthe graph G .

Proof.Let V = {v1, . . . , vN} . We will inductively construct a series oftrees Ti = (Vi , Ei ), i = 0, . . . , N, such that

1. Every tree Ti is a subgraph of G .

2. Every tree Ti is a subtree of Ti+1 .

3. vi ∈ Vi and u ∈ Vi hold for every i > 0 .

4. For every node w ∈ Vi a path from w to u in the tree Ti is anoptimal path from w to u in the graph G .

These properties imply that TN satis�es the requirements for Tu .

Destination-based routing

Theorem 5.1. (about tree of optimal paths).

For every node u ∈ V of a connected graph G there exists such atree Tu = (V , Eu), Eu ⊆ E that for every node v ∈ V the onlypath from v in u in the tree Tu is an optimal path from v to u inthe graph G .

Proof.Let V = {v1, . . . , vN} . We will inductively construct a series oftrees Ti = (Vi , Ei ), i = 0, . . . , N, such that

1. Every tree Ti is a subgraph of G .

2. Every tree Ti is a subtree of Ti+1 .

3. vi ∈ Vi and u ∈ Vi hold for every i > 0 .

4. For every node w ∈ Vi a path from w to u in the tree Ti is anoptimal path from w to u in the graph G .

These properties imply that TN satis�es the requirements for Tu .

Destination-based routing

Theorem 5.1. (about tree of optimal paths).

For every node u ∈ V of a connected graph G there exists such atree Tu = (V , Eu), Eu ⊆ E that for every node v ∈ V the onlypath from v in u in the tree Tu is an optimal path from v to u inthe graph G .

Proof.Let V = {v1, . . . , vN} . We will inductively construct a series oftrees Ti = (Vi , Ei ), i = 0, . . . , N, such that

1. Every tree Ti is a subgraph of G .

2. Every tree Ti is a subtree of Ti+1 .

3. vi ∈ Vi and u ∈ Vi hold for every i > 0 .

4. For every node w ∈ Vi a path from w to u in the tree Ti is anoptimal path from w to u in the graph G .

These properties imply that TN satis�es the requirements for Tu .

Destination-based routing

Proof.Let V0 = {u} and E0 = ∅ .

The tree Ti+1 is de�ned as follows.Choose an optimal simple path P = 〈u0, . . . , uk〉 from vi+1 to u .Suppose that ` the smallest index such that u` ∈ Ti .Then de�ne

Vi+1 = Vi ∪ {uj : j < `} and Ei+1 = Ei ∪ {(uj , uj+1) : j < `}.

Clearly, Ti is a subtree of Ti+1 , and vi+1 ∈ Vi+1 .Graph Ti+1 is a tree since by de�nition of Ti+1 it is a connectedgraph, and the number of nodes exceeds the number of edges byone.

Destination-based routing

Proof.Let V0 = {u} and E0 = ∅ .The tree Ti+1 is de�ned as follows.Choose an optimal simple path P = 〈u0, . . . , uk〉 from vi+1 to u .Suppose that ` the smallest index such that u` ∈ Ti .Then de�ne

Vi+1 = Vi ∪ {uj : j < `} and Ei+1 = Ei ∪ {(uj , uj+1) : j < `}.

Clearly, Ti is a subtree of Ti+1 , and vi+1 ∈ Vi+1 .Graph Ti+1 is a tree since by de�nition of Ti+1 it is a connectedgraph, and the number of nodes exceeds the number of edges byone.

Destination-based routing

Proof.Let V0 = {u} and E0 = ∅ .The tree Ti+1 is de�ned as follows.Choose an optimal simple path P = 〈u0, . . . , uk〉 from vi+1 to u .Suppose that ` the smallest index such that u` ∈ Ti .Then de�ne

Vi+1 = Vi ∪ {uj : j < `} and Ei+1 = Ei ∪ {(uj , uj+1) : j < `}.

Clearly, Ti is a subtree of Ti+1 , and vi+1 ∈ Vi+1 .Graph Ti+1 is a tree since by de�nition of Ti+1 it is a connectedgraph, and the number of nodes exceeds the number of edges byone.

Destination-based routing

vvvv

vv

v v vvvv

vv

v . .. .. .. ... . . . . . . . ..

........�

��

��

����

�����

HHHHH

!!!!

!!

`````̀

AAAAA d

vi+1

u`

. . . .

Ti

P

Ti+1

Ðèñ.: Tree Ti+1.

Destination-based routing

Proof.Let us show that for every node w ∈ Vi+1 a path from w to u inthe tree Ti+1 is an optimal path from w to u in the graph G .

For the nodes w ∈ Vi ⊂ Vi+1 this is true, since Ti is a subtree ofTi+1 .

Suppose that w = uj , j < ` , is in Vi+1 \ Vi , and let Q ′′ is a pathfrom u` to u in the tree Ti .

Then there is a path in the tree Ti+1 from uj to u which isconcatenation of the path Q ′ = 〈uj , . . . , u`〉 and the path Q ′′ .

It remains to show that the path Q = Q ′Q ′′ is an optimal path inthe graph G .

Destination-based routing

Proof.Let us show that for every node w ∈ Vi+1 a path from w to u inthe tree Ti+1 is an optimal path from w to u in the graph G .

For the nodes w ∈ Vi ⊂ Vi+1 this is true, since Ti is a subtree ofTi+1 .

Suppose that w = uj , j < ` , is in Vi+1 \ Vi , and let Q ′′ is a pathfrom u` to u in the tree Ti .

Then there is a path in the tree Ti+1 from uj to u which isconcatenation of the path Q ′ = 〈uj , . . . , u`〉 and the path Q ′′ .

It remains to show that the path Q = Q ′Q ′′ is an optimal path inthe graph G .

Destination-based routing

Proof.Let us show that for every node w ∈ Vi+1 a path from w to u inthe tree Ti+1 is an optimal path from w to u in the graph G .

For the nodes w ∈ Vi ⊂ Vi+1 this is true, since Ti is a subtree ofTi+1 .

Suppose that w = uj , j < ` , is in Vi+1 \ Vi , and let Q ′′ is a pathfrom u` to u in the tree Ti .

Then there is a path in the tree Ti+1 from uj to u which isconcatenation of the path Q ′ = 〈uj , . . . , u`〉 and the path Q ′′ .

It remains to show that the path Q = Q ′Q ′′ is an optimal path inthe graph G .

Destination-based routing

Proof.Let us show that for every node w ∈ Vi+1 a path from w to u inthe tree Ti+1 is an optimal path from w to u in the graph G .

For the nodes w ∈ Vi ⊂ Vi+1 this is true, since Ti is a subtree ofTi+1 .

Suppose that w = uj , j < ` , is in Vi+1 \ Vi , and let Q ′′ is a pathfrom u` to u in the tree Ti .

Then there is a path in the tree Ti+1 from uj to u which isconcatenation of the path Q ′ = 〈uj , . . . , u`〉 and the path Q ′′ .

It remains to show that the path Q = Q ′Q ′′ is an optimal path inthe graph G .

Destination-based routing

vvvv

vv

v v vvvv

vv

v . .. .. .. ... . . . . . . . ..

........�

��

��

����

�����

HHHHH

!!!!

!!

`````̀

AAAAA d

uj

u`Q ′

Q ′′P ′′

. . . .

Ti

P

Ti+1

Ðèñ.: Tree Ti+1.

Destination-based routing

Proof.Notice that the su�x P ′′ = 〈u`, . . . , uk〉 of the path P is anoptimal path from u` to u .This conclusion follows from the optimality of every su�x of anoptimal path and from the additive property of path costs.Therefore, C (P ′′) = C (Q ′′) (since both paths are optimal).

Suppose that there exists a path R from uj to u which has the costless than that of Q ′Q ′′ .Then the cost of R is less than the cost of Q ′P ′′ , and this means(taking into account the additive property) that the path obtainedby joining the path R to the path 〈u0, . . . , uj〉 has the cost lessthan the optimal path P , contradicting the optimality of P . �

Simple question: check yourself.

What conditions must be met by the additive path cost functionC (P) so that for any node u in the graph G there is a single treeTu as de�ned in Theorem 5.1?

Destination-based routing

Proof.Notice that the su�x P ′′ = 〈u`, . . . , uk〉 of the path P is anoptimal path from u` to u .This conclusion follows from the optimality of every su�x of anoptimal path and from the additive property of path costs.Therefore, C (P ′′) = C (Q ′′) (since both paths are optimal).

Suppose that there exists a path R from uj to u which has the costless than that of Q ′Q ′′ .Then the cost of R is less than the cost of Q ′P ′′ , and this means(taking into account the additive property) that the path obtainedby joining the path R to the path 〈u0, . . . , uj〉 has the cost lessthan the optimal path P , contradicting the optimality of P . �

Simple question: check yourself.

What conditions must be met by the additive path cost functionC (P) so that for any node u in the graph G there is a single treeTu as de�ned in Theorem 5.1?

Destination-based routing

A spanning tree rooted towards u is called a sink tree for u , and atree with the property given in Theorem 5.1. is called an optimalsink tree .

The existence of optimal sink trees implies that it is no compromiseto optimality if only routing algorithms are considered for which theforwarding mechanism is as in the local procedure table_lookupv .

The procedure table_lookupv (u) has a single argument u and itchooses one neighbor of v (after consulting the routing tables)relying on the following principles.

1. All packets addressed to the node u can be routed optimally overa spanning tree Tu .

2. Forwarding is optimal if, for all v 6= u the proceduretable_lookupv (u) returns the farther of the node v in the spanningtree Tu .

Destination-based routing

A spanning tree rooted towards u is called a sink tree for u , and atree with the property given in Theorem 5.1. is called an optimalsink tree .

The existence of optimal sink trees implies that it is no compromiseto optimality if only routing algorithms are considered for which theforwarding mechanism is as in the local procedure table_lookupv .

The procedure table_lookupv (u) has a single argument u and itchooses one neighbor of v (after consulting the routing tables)relying on the following principles.

1. All packets addressed to the node u can be routed optimally overa spanning tree Tu .

2. Forwarding is optimal if, for all v 6= u the proceduretable_lookupv (u) returns the farther of the node v in the spanningtree Tu .

Destination-based routing

(* A packet with destination u, was received or generatedat node u *)

if v = uthen deliver the packet locallyelse send the packet to table_lookupv (u)

Destination-based forwarding (to the node u).

Destination-based routingBut ¾little trouble¿ is quite possible: di�erent nodes may meandi�erent sink trees. Could it be so that the packet will be ¾transmitted in a circle¿?

The following result is useful to prove the correctness of routingtables.The routing tables are said to contain a cycle (for destination u ), ifthere are such nodes u1, . . . , uk , that

I ui 6= u for all i ,

I table_lookupui (u) = ui+1 for all i < k , and

I table_lookupuk (u) = u1 .

The tables are said to be cycle-free , if they do not contain a cyclefor any u .

Lemma 5.2. (about cycle-free tables)

The forwarding mechanism delivers every packet at its destination ifand only if the routing tables are cycle-free.

Destination-based routingBut ¾little trouble¿ is quite possible: di�erent nodes may meandi�erent sink trees. Could it be so that the packet will be ¾transmitted in a circle¿?

The following result is useful to prove the correctness of routingtables.The routing tables are said to contain a cycle (for destination u ), ifthere are such nodes u1, . . . , uk , that

I ui 6= u for all i ,

I table_lookupui (u) = ui+1 for all i < k , and

I table_lookupuk (u) = u1 .

The tables are said to be cycle-free , if they do not contain a cyclefor any u .

Lemma 5.2. (about cycle-free tables)

The forwarding mechanism delivers every packet at its destination ifand only if the routing tables are cycle-free.

Destination-based routingBut ¾little trouble¿ is quite possible: di�erent nodes may meandi�erent sink trees. Could it be so that the packet will be ¾transmitted in a circle¿?

The following result is useful to prove the correctness of routingtables.The routing tables are said to contain a cycle (for destination u ), ifthere are such nodes u1, . . . , uk , that

I ui 6= u for all i ,

I table_lookupui (u) = ui+1 for all i < k , and

I table_lookupuk (u) = u1 .

The tables are said to be cycle-free , if they do not contain a cyclefor any u .

Lemma 5.2. (about cycle-free tables)

The forwarding mechanism delivers every packet at its destination ifand only if the routing tables are cycle-free.

Destination-based routing

ProofIf the tables contain a cycle for some destination u , a packet for uis never delivered if its source is a node in the cycle.Assume the tables are cycle-free and let a packet with destination uand source u0 be forwarded via u0, u1, u2, . . . . If the same nodeoccurs twice in this sequence then the tables contain a cyclecontradicting the assumption that the tables are cycle-free.Thus, each node occurs at most once, which implies that thissequence is �nite, ending, say, in node uk (k < N ).According to the forwarding procedure the sequence can only end inu .

Destination-based routing

Simple question: check yourself.

Assume that routing tables are updated after each changes in thetopological structure of the network in such a way that they remainacyclic during the update.Can this guarantee that the packages are always delivered to thedestination?Prove that no routing algorithm is capable of provide packetdelivery to the destination if the topology of the networkpermanently changes.

The all-pairs shortest-path problem

For every pair of nodes (u, v) this algorithm must compute thelength of the shortest path from u to v and stores the �rst channelof such a path in the node u .

We will study Toueg's distributed algorithm for this problem isbased on the centralized Floyd�Warshall algorithm for computingshortest paths between all pairs of nodes.

The all-pairs shortest-path problem

For every pair of nodes (u, v) this algorithm must compute thelength of the shortest path from u to v and stores the �rst channelof such a path in the node u .

We will study Toueg's distributed algorithm for this problem isbased on the centralized Floyd�Warshall algorithm for computingshortest paths between all pairs of nodes.

Floyd-Warshall algorithm

Let G = (V , E ) be a weighted graph, and every its edge uv has aweight ωuv .

It is not necessary to assume that ωuv = ωvu , but it will beassumed that the graph contains no cycles of total negative weight.

The weight of a path 〈u0, . . . , uk〉 is de�ned as∑k−1

i=0 ωuiui+1 .

The distance between nodes u and v is the lowest weight d(u, v)of any path from u to v (if there no such paths exist thend(u, v) =∞ ).

The all-pairs shortest-path problem is to compute d(u, v) forevery pair of nodes u and v .

Floyd-Warshall algorithm

To compute all distances, the Floyd�Warshall algorithm uses thenotion of S-paths , these are paths in which all intermediate nodesbelong to a subset S of V .

De�nition 5.1. (S -distance)

Let S be a subset of V . A path 〈u0, . . . , uk〉 is called S -path ifui ∈ S for each i , 0 < i < k .S-distance from u to v (in symbols, dS(u, v) ) is the lowestweight of any S -path from u to v (if no such paths exist thendS(u, v) =∞ ).

The algorithm starts by considering all ∅ -paths, and incrementallycomputes S -paths for larger subsets S , until all V -paths havebeen considered.

Floyd-Warshall algorithm

To compute all distances, the Floyd�Warshall algorithm uses thenotion of S-paths , these are paths in which all intermediate nodesbelong to a subset S of V .

De�nition 5.1. (S -distance)

Let S be a subset of V . A path 〈u0, . . . , uk〉 is called S -path ifui ∈ S for each i , 0 < i < k .S-distance from u to v (in symbols, dS(u, v) ) is the lowestweight of any S -path from u to v (if no such paths exist thendS(u, v) =∞ ).

The algorithm starts by considering all ∅ -paths, and incrementallycomputes S -paths for larger subsets S , until all V -paths havebeen considered.

Floyd-Warshall algorithm

Theorem 5.2. (about S-paths)

dS(u, u) = 0 holds for every node u and a subset S .If u 6= v then S -paths comply with the following rules.

1. ∅-path from u to v exists i� uv ∈ E .

2. If uv ∈ E then d∅(u, v) = ωuv , otherwise d∅(u, v) =∞ .

3. If S ′ = S ∪ {w} then a simple S ′ -path from u to v is either aS -path from u to v , or a concatenation of two S -paths: onefrom u to w and another from w to v .

4. If S ′ = S ∪ {w} thendS ′(u, v) = min ( dS(u, v), dS(u, w) + dS(w , v) ) .

5. There is a path from u to v i� u and v are connected by a V-path.

6. d(u, v) = dV (u, v) ,

Floyd-Warshall algorithm

Theorem 5.2. (about S-paths)

dS(u, u) = 0 holds for every node u and a subset S .If u 6= v then S -paths comply with the following rules.

1. ∅-path from u to v exists i� uv ∈ E .

2. If uv ∈ E then d∅(u, v) = ωuv , otherwise d∅(u, v) =∞ .

3. If S ′ = S ∪ {w} then a simple S ′ -path from u to v is either aS -path from u to v , or a concatenation of two S -paths: onefrom u to w and another from w to v .

4. If S ′ = S ∪ {w} thendS ′(u, v) = min ( dS(u, v), dS(u, w) + dS(w , v) ) .

5. There is a path from u to v i� u and v are connected by a V-path.

6. d(u, v) = dV (u, v) ,

Floyd-Warshall algorithm

Theorem 5.2. (about S-paths)

dS(u, u) = 0 holds for every node u and a subset S .If u 6= v then S -paths comply with the following rules.

1. ∅-path from u to v exists i� uv ∈ E .

2. If uv ∈ E then d∅(u, v) = ωuv , otherwise d∅(u, v) =∞ .

3. If S ′ = S ∪ {w} then a simple S ′ -path from u to v is either aS -path from u to v , or a concatenation of two S -paths: onefrom u to w and another from w to v .

4. If S ′ = S ∪ {w} thendS ′(u, v) = min ( dS(u, v), dS(u, w) + dS(w , v) ) .

5. There is a path from u to v i� u and v are connected by a V-path.

6. d(u, v) = dV (u, v) ,

Floyd-Warshall algorithm

Theorem 5.2. (about S-paths)

dS(u, u) = 0 holds for every node u and a subset S .If u 6= v then S -paths comply with the following rules.

1. ∅-path from u to v exists i� uv ∈ E .

2. If uv ∈ E then d∅(u, v) = ωuv , otherwise d∅(u, v) =∞ .

3. If S ′ = S ∪ {w} then a simple S ′ -path from u to v is either aS -path from u to v , or a concatenation of two S -paths: onefrom u to w and another from w to v .

4. If S ′ = S ∪ {w} thendS ′(u, v) = min ( dS(u, v), dS(u, w) + dS(w , v) ) .

5. There is a path from u to v i� u and v are connected by a V-path.

6. d(u, v) = dV (u, v) ,

Floyd-Warshall algorithm

Theorem 5.2. (about S-paths)

dS(u, u) = 0 holds for every node u and a subset S .If u 6= v then S -paths comply with the following rules.

1. ∅-path from u to v exists i� uv ∈ E .

2. If uv ∈ E then d∅(u, v) = ωuv , otherwise d∅(u, v) =∞ .

3. If S ′ = S ∪ {w} then a simple S ′ -path from u to v is either aS -path from u to v , or a concatenation of two S -paths: onefrom u to w and another from w to v .

4. If S ′ = S ∪ {w} thendS ′(u, v) = min ( dS(u, v), dS(u, w) + dS(w , v) ) .

5. There is a path from u to v i� u and v are connected by a V-path.

6. d(u, v) = dV (u, v) ,

Floyd-Warshall algorithm

Theorem 5.2. (about S-paths)

dS(u, u) = 0 holds for every node u and a subset S .If u 6= v then S -paths comply with the following rules.

1. ∅-path from u to v exists i� uv ∈ E .

2. If uv ∈ E then d∅(u, v) = ωuv , otherwise d∅(u, v) =∞ .

3. If S ′ = S ∪ {w} then a simple S ′ -path from u to v is either aS -path from u to v , or a concatenation of two S -paths: onefrom u to w and another from w to v .

4. If S ′ = S ∪ {w} thendS ′(u, v) = min ( dS(u, v), dS(u, w) + dS(w , v) ) .

5. There is a path from u to v i� u and v are connected by a V-path.

6. d(u, v) = dV (u, v) ,

Floyd-Warshall algorithm

Theorem 5.2. (about S-paths)

dS(u, u) = 0 holds for every node u and a subset S .If u 6= v then S -paths comply with the following rules.

1. ∅-path from u to v exists i� uv ∈ E .

2. If uv ∈ E then d∅(u, v) = ωuv , otherwise d∅(u, v) =∞ .

3. If S ′ = S ∪ {w} then a simple S ′ -path from u to v is either aS -path from u to v , or a concatenation of two S -paths: onefrom u to w and another from w to v .

4. If S ′ = S ∪ {w} thendS ′(u, v) = min ( dS(u, v), dS(u, w) + dS(w , v) ) .

5. There is a path from u to v i� u and v are connected by a V-path.

6. d(u, v) = dV (u, v) ,

Floyd-Warshall algorithm

ProofRules (1)�(3) and (5)�(6) � are easy for proving, check yourselves..

Rule (4). By Lemma 5.1. (about simple paths) one can show thatif there is a S ′ -path from u to v then there exists a simple S ′ -pathof the weight dS ′(u, v) from u to v . Then, by rule (3), it followsthat dS ′(u, v) = min ( dS(u, v), dS(u, w) + dS(w , v) ) . �

Floyd-Warshall algorithm

ProofRules (1)�(3) and (5)�(6) � are easy for proving, check yourselves..

Rule (4). By Lemma 5.1. (about simple paths) one can show thatif there is a S ′ -path from u to v then there exists a simple S ′ -pathof the weight dS ′(u, v) from u to v . Then, by rule (3), it followsthat dS ′(u, v) = min ( dS(u, v), dS(u, w) + dS(w , v) ) . �

Floyd-Warshall algorithm

begin(* Initialize S with ∅ and D with ∅-distances *)S := ∅ ;forall u, v do

if u = v then D[u, v ] := 0else if uv ∈ E then D[u, v ] := ωuv else D[u, v ] :=∞ ;

(* Add to S a pivot node *)while S 6= V do

(* Loop invariant: ∀u, v : D[u, v ] = dS(u, v) *)begin pick w from V \ S ;

(* Global processing of a pivot node w *)forall u ∈ V do

(* Local processing of a pivot node w at u *)forall v ∈ V do

D[u, v ] := min (D[u, v ], D[u, w ] + D[w , v ] ) ;S := S ∪ {w}

end (* ∀u, v : D[u, v ] = d(u, v) *)end

Floyd-Warshall algorithm

Theorem 5.3. (about Floyd-Warshall algorithm)

The algorithm computes the distance between each pair of nodes inΘ(N3) steps.

Proof.Initially D[u, v ] = 0 if u = v , and D[u, v ] = ωuv if uv ∈ E , andD[u, v ] =∞ in all other cases. Also at the beginning S = ∅ . Bythe rules (1) and (2) from the Theorem 5.2. about S -paths weconclude that ∀u, v : D[u, v ] = dS(u, v) . If S is extended with anode w then, by the rules (3) and (4) assignment statements,which udate D[u, v ] , preserve the loop invariant∀u, v : D[u, v ] = dS(u, v) . The algorithm terminates whenS = V . By taking into account the rules (5) and (6), and the loopinvariant, we arrive at the conclusion that the computedS-distances equal the distances.The main loop is executed N times and contain N2 operations. �

Floyd-Warshall algorithm

Theorem 5.3. (about Floyd-Warshall algorithm)

The algorithm computes the distance between each pair of nodes inΘ(N3) steps.

Proof.Initially D[u, v ] = 0 if u = v , and D[u, v ] = ωuv if uv ∈ E , andD[u, v ] =∞ in all other cases. Also at the beginning S = ∅ . Bythe rules (1) and (2) from the Theorem 5.2. about S -paths weconclude that ∀u, v : D[u, v ] = dS(u, v) . If S is extended with anode w then, by the rules (3) and (4) assignment statements,which udate D[u, v ] , preserve the loop invariant∀u, v : D[u, v ] = dS(u, v) . The algorithm terminates whenS = V . By taking into account the rules (5) and (6), and the loopinvariant, we arrive at the conclusion that the computedS-distances equal the distances.The main loop is executed N times and contain N2 operations. �

Toueg's algorithm (simple variant)

Basic assumptions.

A1. Every cycle in the net has a positive weight.

A2. Each node in the network initially knows the IDs (names) of allnodes from the set V .

A3. Each node knows which of the nodes are its neighbors (storedin the list neighu for node u ) and the weights of its outgoingchannels.

The correctness of Toueg's algorithm will be more easilyunderstood if we �rst consider a preliminary version of it, the¾simple algorithm¿.

Toueg's algorithm (simple variant)

Basic assumptions.

A1. Every cycle in the net has a positive weight.

A2. Each node in the network initially knows the IDs (names) of allnodes from the set V .

A3. Each node knows which of the nodes are its neighbors (storedin the list neighu for node u ) and the weights of its outgoingchannels.

The correctness of Toueg's algorithm will be more easilyunderstood if we �rst consider a preliminary version of it, the¾simple algorithm¿.

Toueg's algorithm (simple variant)

Basic assumptions.

A1. Every cycle in the net has a positive weight.

A2. Each node in the network initially knows the IDs (names) of allnodes from the set V .

A3. Each node knows which of the nodes are its neighbors (storedin the list neighu for node u ) and the weights of its outgoingchannels.

The correctness of Toueg's algorithm will be more easilyunderstood if we �rst consider a preliminary version of it, the¾simple algorithm¿.

Toueg's algorithm (simple variant)

Basic assumptions.

A1. Every cycle in the net has a positive weight.

A2. Each node in the network initially knows the IDs (names) of allnodes from the set V .

A3. Each node knows which of the nodes are its neighbors (storedin the list neighu for node u ) and the weights of its outgoingchannels.

The correctness of Toueg's algorithm will be more easilyunderstood if we �rst consider a preliminary version of it, the¾simple algorithm¿.

Toueg's algorithm (simple variant)

I The variables and operations of the Floyd-Warshall algorithmare distributed across di�erent nodes of the network. Everyvariable D[u, v ] is assigned to the node u ; for the sake ofsimplicity we will write Du[v ] instead of D[u, v ] .

I All operations over Du[v ] are executed at the node u ; if somevariable assigned to a node w is involved in an operation at anode u then the required value must be delivered to u .

I In Floyd-Warshall algorithm, all nodes must use informationfrom the pivot node, which sends this informationsimultaneously via ¾virtual broadcasting¿ .

I The algorithm will be augmented with an operation tomaintain not only the lengths of shortest S -paths (as in thevariable Du[v ] ), but also the �rst channel of such a path (inthe variable Nbu[v ] ).

Toueg's algorithm (simple variant)

I The variables and operations of the Floyd-Warshall algorithmare distributed across di�erent nodes of the network. Everyvariable D[u, v ] is assigned to the node u ; for the sake ofsimplicity we will write Du[v ] instead of D[u, v ] .

I All operations over Du[v ] are executed at the node u ; if somevariable assigned to a node w is involved in an operation at anode u then the required value must be delivered to u .

I In Floyd-Warshall algorithm, all nodes must use informationfrom the pivot node, which sends this informationsimultaneously via ¾virtual broadcasting¿ .

I The algorithm will be augmented with an operation tomaintain not only the lengths of shortest S -paths (as in thevariable Du[v ] ), but also the �rst channel of such a path (inthe variable Nbu[v ] ).

Toueg's algorithm (simple variant)

I The variables and operations of the Floyd-Warshall algorithmare distributed across di�erent nodes of the network. Everyvariable D[u, v ] is assigned to the node u ; for the sake ofsimplicity we will write Du[v ] instead of D[u, v ] .

I All operations over Du[v ] are executed at the node u ; if somevariable assigned to a node w is involved in an operation at anode u then the required value must be delivered to u .

I In Floyd-Warshall algorithm, all nodes must use informationfrom the pivot node, which sends this informationsimultaneously via ¾virtual broadcasting¿ .

I The algorithm will be augmented with an operation tomaintain not only the lengths of shortest S -paths (as in thevariable Du[v ] ), but also the �rst channel of such a path (inthe variable Nbu[v ] ).

Toueg's algorithm (simple variant)

I The variables and operations of the Floyd-Warshall algorithmare distributed across di�erent nodes of the network. Everyvariable D[u, v ] is assigned to the node u ; for the sake ofsimplicity we will write Du[v ] instead of D[u, v ] .

I All operations over Du[v ] are executed at the node u ; if somevariable assigned to a node w is involved in an operation at anode u then the required value must be delivered to u .

I In Floyd-Warshall algorithm, all nodes must use informationfrom the pivot node, which sends this informationsimultaneously via ¾virtual broadcasting¿ .

I The algorithm will be augmented with an operation tomaintain not only the lengths of shortest S -paths (as in thevariable Du[v ] ), but also the �rst channel of such a path (inthe variable Nbu[v ] ).

Toueg's algorithm (simple variant)

Lemma 5.3. (on the absence of cycles)

Let S and w be given and suppose that

1. Du[w ] = dS(u, w) holds for all nodes u ,

2. if dS(u, w) <∞ and u 6= w then the value of Nbu[w ] is the�rst channel of a shortest S -path to the node w .

Then a di-graph Tw = (Vw , Ew ) , where

Vw = {u : Du[w ] <∞} and Ew = {ux : u 6= w∧Nbu[w ] = x},

is a tree rooted towards w .

Toueg's algorithm (simple variant)

Proof.First, observe that if Du[w ] <∞ holds for a node u 6= w thenNbu[w ] 6= udef and DNbu [w ][w ] <∞ . Hence, for every nodeu ∈ Vw , u 6= w , there exists such a node x ∈ Vw for whichNbu[w ] = x holds.

For every node u ∈ Vw , u 6= w there is oneedge in the set Ew , and, therefore, the number of nodes in Tw

exceeds the number of edges by 1. It su�ces to show that Tw

contains no cycle. Since dS(u, w) = ωux + dS(x , w) holds forevery ux ∈ Ew , the existence of cycle 〈u0, u1, . . . , uk〉 in Tw

would bring an equality

dS(u0, w) = ωu0u1 + ωu1u2 + · · ·+ ωuk−1u0 + dS(u0, w),

which implies 0 = ωu0u1 + ωu1u2 + · · ·+ ωuk−1u0 , . in contrast tothe assumption that each cycle has positive weight. �

Toueg's algorithm (simple variant)

Proof.First, observe that if Du[w ] <∞ holds for a node u 6= w thenNbu[w ] 6= udef and DNbu [w ][w ] <∞ . Hence, for every nodeu ∈ Vw , u 6= w , there exists such a node x ∈ Vw for whichNbu[w ] = x holds. For every node u ∈ Vw , u 6= w there is oneedge in the set Ew , and, therefore, the number of nodes in Tw

exceeds the number of edges by 1. It su�ces to show that Tw

contains no cycle.

Since dS(u, w) = ωux + dS(x , w) holds forevery ux ∈ Ew , the existence of cycle 〈u0, u1, . . . , uk〉 in Tw

would bring an equality

dS(u0, w) = ωu0u1 + ωu1u2 + · · ·+ ωuk−1u0 + dS(u0, w),

which implies 0 = ωu0u1 + ωu1u2 + · · ·+ ωuk−1u0 , . in contrast tothe assumption that each cycle has positive weight. �

Toueg's algorithm (simple variant)

Proof.First, observe that if Du[w ] <∞ holds for a node u 6= w thenNbu[w ] 6= udef and DNbu [w ][w ] <∞ . Hence, for every nodeu ∈ Vw , u 6= w , there exists such a node x ∈ Vw for whichNbu[w ] = x holds. For every node u ∈ Vw , u 6= w there is oneedge in the set Ew , and, therefore, the number of nodes in Tw

exceeds the number of edges by 1. It su�ces to show that Tw

contains no cycle. Since dS(u, w) = ωux + dS(x , w) holds forevery ux ∈ Ew , the existence of cycle 〈u0, u1, . . . , uk〉 in Tw

would bring an equality

dS(u0, w) = ωu0u1 + ωu1u2 + · · ·+ ωuk−1u0 + dS(u0, w),

which implies 0 = ωu0u1 + ωu1u2 + · · ·+ ωuk−1u0 , . in contrast tothe assumption that each cycle has positive weight. �

Toueg's algorithm (simple variant)

var Su : set of nodes ;Du : array of weights ; Nbu : array of nodes ;

begin Su := ∅ ;forall v ∈ V do

if v = u then begin Du[v ] := 0 ; Nbu[v ] := udef endelse if v ∈ Neighu

then begin Du[v ] := ωuv ; Nbu[v ] := v endelse begin Du[v ] :=∞ ; Nbu[v ] := udef end;

while Su 6= V dobegin pick w from V \ Su ;

(* All processes choose the same pivot node w *)if u = w then �broadcast Dw � else �receive Dw � ;forall v ∈ V doif Du[w ] + Dw [v ] < Du[v ] thenbegin Du[v ] := Du[w ] + Dw [v ] ; Nbu[v ] := Nbu[w ] end;Su := Su ∪ {w}

endend

Toueg's algorithm (simple variant)

Theorem 5.4. (on the correctness of simpli�ed Toueg'salgorthm)

The simpli�ed Toueg's algorithm terminates at every node after Niteration of the main cycle. When the algorithm terminates at thenode u , Du[v ] = d(u, v) holds for every node v ; if there is a pathfrom u to v then Nbu[v ] is evaluated to the �rst channel of ashortest path from u to v ; otherwise Nbu[v ] = udef .

Proof.Termination and partial correctenss of the algorithm follows fromthe partial correctenss of Floyd�Warshall algorithm (Theorem 5.3.).The statement about the value of Nbu[v ] , because Nbu[v ] isupdated every time when Du[v ] is assigned. �

Toueg's algorithm (simple variant)

Theorem 5.4. (on the correctness of simpli�ed Toueg'salgorthm)

The simpli�ed Toueg's algorithm terminates at every node after Niteration of the main cycle. When the algorithm terminates at thenode u , Du[v ] = d(u, v) holds for every node v ; if there is a pathfrom u to v then Nbu[v ] is evaluated to the �rst channel of ashortest path from u to v ; otherwise Nbu[v ] = udef .

Proof.Termination and partial correctenss of the algorithm follows fromthe partial correctenss of Floyd�Warshall algorithm (Theorem 5.3.).The statement about the value of Nbu[v ] , because Nbu[v ] isupdated every time when Du[v ] is assigned. �

Toueg's algorithm (simple variant)

It is necessary to have means for broadcasting information, whileeach process has the ability to communicate only with its neighbors.

For this purpose wave algorithms are very much suitable.Toueg observes that a node u for which Du[w ] =∞ at the start ofthe w -pivot round does not change its tables during the w -pivotround. Therefore, the routing tables Dw should be deliverd only tothose nodes which belongs to the tree Tw (at the beginning of thew -pivot round), and broadcasting can be performed e�ciently bysending the table Dw only via those channels which belong to thetree Tw . To this end w sends the table Dw to its successors in thetree Tw , and every node in Tw , after receiving this table from theparent node in Tw , forwards it to its sons in Tw .

Toueg's algorithm (simple variant)

It is necessary to have means for broadcasting information, whileeach process has the ability to communicate only with its neighbors.For this purpose wave algorithms are very much suitable.

Toueg observes that a node u for which Du[w ] =∞ at the start ofthe w -pivot round does not change its tables during the w -pivotround. Therefore, the routing tables Dw should be deliverd only tothose nodes which belongs to the tree Tw (at the beginning of thew -pivot round), and broadcasting can be performed e�ciently bysending the table Dw only via those channels which belong to thetree Tw . To this end w sends the table Dw to its successors in thetree Tw , and every node in Tw , after receiving this table from theparent node in Tw , forwards it to its sons in Tw .

Toueg's algorithm (simple variant)

It is necessary to have means for broadcasting information, whileeach process has the ability to communicate only with its neighbors.For this purpose wave algorithms are very much suitable.Toueg observes that a node u for which Du[w ] =∞ at the start ofthe w -pivot round does not change its tables during the w -pivotround.

Therefore, the routing tables Dw should be deliverd only tothose nodes which belongs to the tree Tw (at the beginning of thew -pivot round), and broadcasting can be performed e�ciently bysending the table Dw only via those channels which belong to thetree Tw . To this end w sends the table Dw to its successors in thetree Tw , and every node in Tw , after receiving this table from theparent node in Tw , forwards it to its sons in Tw .

Toueg's algorithm (simple variant)

It is necessary to have means for broadcasting information, whileeach process has the ability to communicate only with its neighbors.For this purpose wave algorithms are very much suitable.Toueg observes that a node u for which Du[w ] =∞ at the start ofthe w -pivot round does not change its tables during the w -pivotround. Therefore, the routing tables Dw should be deliverd only tothose nodes which belongs to the tree Tw (at the beginning of thew -pivot round), and broadcasting can be performed e�ciently bysending the table Dw only via those channels which belong to thetree Tw .

To this end w sends the table Dw to its successors in thetree Tw , and every node in Tw , after receiving this table from theparent node in Tw , forwards it to its sons in Tw .

Toueg's algorithm (simple variant)

It is necessary to have means for broadcasting information, whileeach process has the ability to communicate only with its neighbors.For this purpose wave algorithms are very much suitable.Toueg observes that a node u for which Du[w ] =∞ at the start ofthe w -pivot round does not change its tables during the w -pivotround. Therefore, the routing tables Dw should be deliverd only tothose nodes which belongs to the tree Tw (at the beginning of thew -pivot round), and broadcasting can be performed e�ciently bysending the table Dw only via those channels which belong to thetree Tw . To this end w sends the table Dw to its successors in thetree Tw , and every node in Tw , after receiving this table from theparent node in Tw , forwards it to its sons in Tw .

Toueg's algorithm (full variant)

At the beginning of the w -pivot round every node u , for whichDu[w ] <∞ holds, knows who its farther in Tw is, but does notknow which nodes are its successors.

Therefore, every node v must send a message to every its neighboreu to inform u whether v is a successor of u in the tree Tw .

A node can participate in the forwarding of w 's table when itknows which of its neighbors are its sons in Tw .

Toueg's algorithm (full variant)

At the beginning of the w -pivot round every node u , for whichDu[w ] <∞ holds, knows who its farther in Tw is, but does notknow which nodes are its successors.

Therefore, every node v must send a message to every its neighboreu to inform u whether v is a successor of u in the tree Tw .

A node can participate in the forwarding of w 's table when itknows which of its neighbors are its sons in Tw .

Toueg's algorithm (full variant)

Initialization

var Su : set of nodes ;Du : array of weights ;Nbu : array of nodes ;

begin Su := ∅ ;forall v ∈ V do

if v = uthen begin Du[v ] := 0 ; Nbu[v ] := udef endelse if v ∈ Neighu

then begin Du[v ] := ωuv ; Nbu[v ] := v endelse begin Du[v ] :=∞ ; Nbu[v ] := udef end;

Toueg's algorithm (full variant)

Detecting the son nodes

while Su 6= V dobegin pick w from V \ Su ;

(* Ïîñòðîèòü äåðåâî Tw *)forall x ∈ Neighu do

if Nbu[w ] = x then send 〈ys,w〉 to xelse send 〈nys,w〉 to x ;

recu := 0 ; (* u must receive |Neighu| messages *)while recu < |Neighu| do

begin receive 〈ys,w〉 or 〈nys,w〉; recu := recu + 1 end;

Toueg's algorithm (full variant)

Updating routing tables

if Du[w ] <∞ then (*participate in w -pivot round*)begin if u 6= w then receive 〈dtab,w ,D〉 from Nbu[w ] ;

forall x ∈ Neighu doif 〈ys,w〉 was received from xthen send 〈dtab,w ,D〉 to x ;

forall v ∈ V do (*local processing of a pivot node w*)if Du[w ] + D[v ] < Du[v ] thenbegin Du[v ] := Du[w ] + D[v ]; Nbu[v ] := Nbu[w ] end

end;Su := Su ∪ {w}endend

Toueg's algorithm (full variant)

There are three types of messages Toueg's algorithm:

1. Messages 〈ys,w〉 (ys means ¾your son¿) are sent from u to xat the beginning of w -pivot round, if x is the parent of u inthe tree Tw .

2. Messages 〈nys,w〉 (nys means ¾not your son¿) are sent fromu to x the beginning of w -pivot round, if x is not the parentof u in the tree Tw .

3. Messages 〈dtab,w ,D〉 are sent during w -pivot round viaevery channel in the tree Tw to deliver the table Dw to eachnode that must use this value.

Toueg's algorithm (full variant)

There are three types of messages Toueg's algorithm:

1. Messages 〈ys,w〉 (ys means ¾your son¿) are sent from u to xat the beginning of w -pivot round, if x is the parent of u inthe tree Tw .

2. Messages 〈nys,w〉 (nys means ¾not your son¿) are sent fromu to x the beginning of w -pivot round, if x is not the parentof u in the tree Tw .

3. Messages 〈dtab,w ,D〉 are sent during w -pivot round viaevery channel in the tree Tw to deliver the table Dw to eachnode that must use this value.

Toueg's algorithm (full variant)

There are three types of messages Toueg's algorithm:

1. Messages 〈ys,w〉 (ys means ¾your son¿) are sent from u to xat the beginning of w -pivot round, if x is the parent of u inthe tree Tw .

2. Messages 〈nys,w〉 (nys means ¾not your son¿) are sent fromu to x the beginning of w -pivot round, if x is not the parentof u in the tree Tw .

3. Messages 〈dtab,w ,D〉 are sent during w -pivot round viaevery channel in the tree Tw to deliver the table Dw to eachnode that must use this value.

Toueg's algorithm (full variant)

There are three types of messages Toueg's algorithm:

1. Messages 〈ys,w〉 (ys means ¾your son¿) are sent from u to xat the beginning of w -pivot round, if x is the parent of u inthe tree Tw .

2. Messages 〈nys,w〉 (nys means ¾not your son¿) are sent fromu to x the beginning of w -pivot round, if x is not the parentof u in the tree Tw .

3. Messages 〈dtab,w ,D〉 are sent during w -pivot round viaevery channel in the tree Tw to deliver the table Dw to eachnode that must use this value.

Toueg's algorithm (full variant)

Let W is a number of bits which is necessary to represent pathweights.

Theorem 5.5. (on the correctness and complexity of Toueg'salgorithm)

For every pair of nodes u and v Toueg's algorithm computes thedistance from u to v . If such a distance is �nite then it computesalso the �rst channel in the shortest path from u to v .

The algorithm exchanges O(N) messages and O(N2W ) bit ofinformation per channel, and O(N · |E |) messages and O(N3 ·W )bits in total.The algorithm requires O(N ·W ) bits of storage per node.

Toueg's algorithm (full variant)

Proof.The full version of Toueg's algorithm is based on its simpli�edvariant, and, therefore, it is correct.

At every w -pivot round twomessages 〈ys,w〉 or 〈nys,w〉 (one at every direction) and no morethan one message of the type 〈dtab,w ,D〉 are forwarded via everychannel. Hence, totally 3N messages at the most are sent via everychannel. Messages of the type 〈ys,w〉 or 〈nys,w〉 contain O(W )bits, and a message of the type 〈dtab,w ,D〉 contains O(NW ) bits.This implies the upper bound on the bit complexity of messageexchange via every channel. In the course of an execution of thealgorithm at most N2 messages of the type 〈dtab,w ,D〉 and2N · |E | messages of the type 〈ys,w〉 and 〈nys,w〉 are sent, whichtotals to O(N2 · NW + 2N · |E | ·W ) = O(N3W ) bits altogether.To store the tables Du and Nbu every process u needs O(NW ) bitsof memory.

Toueg's algorithm (full variant)

Proof.The full version of Toueg's algorithm is based on its simpli�edvariant, and, therefore, it is correct. At every w -pivot round twomessages 〈ys,w〉 or 〈nys,w〉 (one at every direction) and no morethan one message of the type 〈dtab,w ,D〉 are forwarded via everychannel. Hence, totally 3N messages at the most are sent via everychannel. Messages of the type 〈ys,w〉 or 〈nys,w〉 contain O(W )bits, and a message of the type 〈dtab,w ,D〉 contains O(NW ) bits.This implies the upper bound on the bit complexity of messageexchange via every channel.

In the course of an execution of thealgorithm at most N2 messages of the type 〈dtab,w ,D〉 and2N · |E | messages of the type 〈ys,w〉 and 〈nys,w〉 are sent, whichtotals to O(N2 · NW + 2N · |E | ·W ) = O(N3W ) bits altogether.To store the tables Du and Nbu every process u needs O(NW ) bitsof memory.

Toueg's algorithm (full variant)

Proof.The full version of Toueg's algorithm is based on its simpli�edvariant, and, therefore, it is correct. At every w -pivot round twomessages 〈ys,w〉 or 〈nys,w〉 (one at every direction) and no morethan one message of the type 〈dtab,w ,D〉 are forwarded via everychannel. Hence, totally 3N messages at the most are sent via everychannel. Messages of the type 〈ys,w〉 or 〈nys,w〉 contain O(W )bits, and a message of the type 〈dtab,w ,D〉 contains O(NW ) bits.This implies the upper bound on the bit complexity of messageexchange via every channel. In the course of an execution of thealgorithm at most N2 messages of the type 〈dtab,w ,D〉 and2N · |E | messages of the type 〈ys,w〉 and 〈nys,w〉 are sent, whichtotals to O(N2 · NW + 2N · |E | ·W ) = O(N3W ) bits altogether.

To store the tables Du and Nbu every process u needs O(NW ) bitsof memory.

Toueg's algorithm (full variant)

Proof.The full version of Toueg's algorithm is based on its simpli�edvariant, and, therefore, it is correct. At every w -pivot round twomessages 〈ys,w〉 or 〈nys,w〉 (one at every direction) and no morethan one message of the type 〈dtab,w ,D〉 are forwarded via everychannel. Hence, totally 3N messages at the most are sent via everychannel. Messages of the type 〈ys,w〉 or 〈nys,w〉 contain O(W )bits, and a message of the type 〈dtab,w ,D〉 contains O(NW ) bits.This implies the upper bound on the bit complexity of messageexchange via every channel. In the course of an execution of thealgorithm at most N2 messages of the type 〈dtab,w ,D〉 and2N · |E | messages of the type 〈ys,w〉 and 〈nys,w〉 are sent, whichtotals to O(N2 · NW + 2N · |E | ·W ) = O(N3W ) bits altogether.To store the tables Du and Nbu every process u needs O(NW ) bitsof memory.

Toueg's algorithm (full variant)

Simple questions: check yourself.

1. Why is it necessary to send in every message a name of acurrent pivot node w? What happens when this named ismissed? Is it possible to modify the algorithm so as not totransmit the name of the pivot node in some messages?

2. A shrew student proposed to exclude message sending fromTuega algorithm 〈nys,w〉. This studen reasons: the node willlearn that its neighbor is not a son node if it receives nomessages 〈ys,w〉 from this neighbor .Is it possible to modify the algorithm in this way? Will it becorrect? What will be the complexity of such an algorithm?

Toueg's algorithm (discussion)

Advantages. Simple, has low complexity, builds optimal paths.

Shortcomings.

I Weak robustness: when changing the network topology, allcomputations must be carried out again.

I The consistent choice of the next pivot node (w ) by all nodesof the network suggests that all processes involved in thealgorithm are known in advance.

I Toueg's algorithm is based on repeated application of thetriangle inequality d(u, v) ≤ d(u, w) + d(w , v) . To computethe right-hand side of this inequality (in a node u ) one needsa ¾global¿ information d(w , v) which may be inavailableneither to u , nor to its neighbors. Dependence on remote datanecessitates the transport of information to remote nodes.

Toueg's algorithm (discussion)

Advantages. Simple, has low complexity, builds optimal paths.

Shortcomings.

I Weak robustness: when changing the network topology, allcomputations must be carried out again.

I The consistent choice of the next pivot node (w ) by all nodesof the network suggests that all processes involved in thealgorithm are known in advance.

I Toueg's algorithm is based on repeated application of thetriangle inequality d(u, v) ≤ d(u, w) + d(w , v) . To computethe right-hand side of this inequality (in a node u ) one needsa ¾global¿ information d(w , v) which may be inavailableneither to u , nor to its neighbors. Dependence on remote datanecessitates the transport of information to remote nodes.

Toueg's algorithm (discussion)

Advantages. Simple, has low complexity, builds optimal paths.

Shortcomings.

I Weak robustness: when changing the network topology, allcomputations must be carried out again.

I The consistent choice of the next pivot node (w ) by all nodesof the network suggests that all processes involved in thealgorithm are known in advance.

I Toueg's algorithm is based on repeated application of thetriangle inequality d(u, v) ≤ d(u, w) + d(w , v) . To computethe right-hand side of this inequality (in a node u ) one needsa ¾global¿ information d(w , v) which may be inavailableneither to u , nor to its neighbors. Dependence on remote datanecessitates the transport of information to remote nodes.

Toueg's algorithm (discussion)An alternative equation for building the shortest paths is

d(u, v) =

{0 if u = v

minw∈Neighu

(ωuw + d(w , v)) otherwise (1)

Two properties of this equations are useful.

1. Data locality. To compute the right-hand side of theequation (1) at u one needs only information which locallyavailable to the node (namely, ωuw ) or to its neighbors(namely, d(w , v) ). The transportation of data betweenremote nodes is avoided.

2. Destination independence. To compute the distance betweenthe nodes u and v it is necessary to know only the distanced(w , v) between v and all neighbors w of u . Thus, thecomputation of all distances to a �xed destination v0 canproceed independently of the computation of distances toother nodes, and also, can be studied in isolation.

Toueg's algorithm (discussion)An alternative equation for building the shortest paths is

d(u, v) =

{0 if u = v

minw∈Neighu

(ωuw + d(w , v)) otherwise (1)

Two properties of this equations are useful.

1. Data locality. To compute the right-hand side of theequation (1) at u one needs only information which locallyavailable to the node (namely, ωuw ) or to its neighbors(namely, d(w , v) ). The transportation of data betweenremote nodes is avoided.

2. Destination independence. To compute the distance betweenthe nodes u and v it is necessary to know only the distanced(w , v) between v and all neighbors w of u . Thus, thecomputation of all distances to a �xed destination v0 canproceed independently of the computation of distances toother nodes, and also, can be studied in isolation.

Toueg's algorithm (discussion)An alternative equation for building the shortest paths is

d(u, v) =

{0 if u = v

minw∈Neighu

(ωuw + d(w , v)) otherwise (1)

Two properties of this equations are useful.

1. Data locality. To compute the right-hand side of theequation (1) at u one needs only information which locallyavailable to the node (namely, ωuw ) or to its neighbors(namely, d(w , v) ). The transportation of data betweenremote nodes is avoided.

2. Destination independence. To compute the distance betweenthe nodes u and v it is necessary to know only the distanced(w , v) between v and all neighbors w of u . Thus, thecomputation of all distances to a �xed destination v0 canproceed independently of the computation of distances toother nodes, and also, can be studied in isolation.

Toueg's algorithm (discussion)An alternative equation for building the shortest paths is

d(u, v) =

{0 if u = v

minw∈Neighu

(ωuw + d(w , v)) otherwise (1)

Two properties of this equations are useful.

1. Data locality. To compute the right-hand side of theequation (1) at u one needs only information which locallyavailable to the node (namely, ωuw ) or to its neighbors(namely, d(w , v) ). The transportation of data betweenremote nodes is avoided.

2. Destination independence. To compute the distance betweenthe nodes u and v it is necessary to know only the distanced(w , v) between v and all neighbors w of u . Thus, thecomputation of all distances to a �xed destination v0 canproceed independently of the computation of distances toother nodes, and also, can be studied in isolation.

Merlin�Segall algorithm

Merlin�Segall algorithm computes routing table for everydestination node separately.

The computations for di�erent destinations do not in�uence eachother.

For every destination node v the algorithm builds a tree Tv rootedtoward v , and repeatedly updates this tree so as to become anoptimal sink tree for destination v .

Merlin�Segall algorithm

Every node u stores an estimation of the distance Du[v ] to thenode v and a neighbor in the tree Tv to which a packet v must beforward.In an update round each node u sends its estimated distance〈mydist, v ,Du[v ]〉 to all its neighbors but Nbu[v ] .If a node u receives from its neighbor w a message 〈mydist, v , d〉and �nds that d + ωuw < Du[v ] , then it changes Nbu[v ] to w ,and Du[v ] to d + ωuw .

The update round is controlled by v and requires the exchange oftwo messages of W bits on each channel.After i update rounds all shortest paths of at most i hops havebeen correctly computed, so that after at most N rounds allshortest paths to v are computed. Shortest paths to eachdestination are computed by executing the algorithm independentlyfor each destination.

Merlin�Segall algorithm

Every node u stores an estimation of the distance Du[v ] to thenode v and a neighbor in the tree Tv to which a packet v must beforward.In an update round each node u sends its estimated distance〈mydist, v ,Du[v ]〉 to all its neighbors but Nbu[v ] .If a node u receives from its neighbor w a message 〈mydist, v , d〉and �nds that d + ωuw < Du[v ] , then it changes Nbu[v ] to w ,and Du[v ] to d + ωuw .The update round is controlled by v and requires the exchange oftwo messages of W bits on each channel.

After i update rounds all shortest paths of at most i hops havebeen correctly computed, so that after at most N rounds allshortest paths to v are computed. Shortest paths to eachdestination are computed by executing the algorithm independentlyfor each destination.

Merlin�Segall algorithm

Every node u stores an estimation of the distance Du[v ] to thenode v and a neighbor in the tree Tv to which a packet v must beforward.In an update round each node u sends its estimated distance〈mydist, v ,Du[v ]〉 to all its neighbors but Nbu[v ] .If a node u receives from its neighbor w a message 〈mydist, v , d〉and �nds that d + ωuw < Du[v ] , then it changes Nbu[v ] to w ,and Du[v ] to d + ωuw .The update round is controlled by v and requires the exchange oftwo messages of W bits on each channel.After i update rounds all shortest paths of at most i hops havebeen correctly computed, so that after at most N rounds allshortest paths to v are computed. Shortest paths to eachdestination are computed by executing the algorithm independentlyfor each destination.

Merlin�Segall algorithm

The algorithm can also adapt to changes in the topology and theweight of channels.

An important property of the algorithm is that during updaterounds also the routing tables are cycle-free.

Theorem 5.6. (on the correctness and complexity ofMerlin-Segall algorithm)

Merlin-Segall algorithm computes shortest-path routing tables byexchanging O(N2) messages and sending O(N2 ·W ) bits via everychannel; thus, its message complexity is O(N2 · |E |) and bitcomplexity O(N2 · |E |W ) .

Merlin�Segall algorithm

HOMETASK 1.

1. Write the pseudo-code for the Merlin-Seagall algorithm. Provethat it is correct.

2. Show that the (intermediate) routing tables computed by theMerlin-Segall algorithm always remain acyclic throughout theoperation of the algorithm

3. Prove Theorem 5.6.

Chandy�Misra algorithm

The algorithm proposed by Chandy and Misra computes all shortestpaths towards one destination using the paradigm of di�usingcomputations , that is, a distributed computation that is initiatedby a single node, and joined by other nodes only after receiving amessage.

To compute distances from every node to a given destination v0(and the corresponding channels) every node u initializeDu[v0] =∞ and waits for the receipt of messages..A node v0 forwards a message 〈mydist, v0, 0〉 to all its neighbors.As soon as u receives a message 〈mydist, v0, d〉 from w and checksthe inequality d + ωuw < Du[v0] , it assigns d + ωuw to Du[v0] ,and sends the message 〈mydist, v0,Du[v0]〉 to all its neighbors.

Chandy�Misra algorithm

The algorithm proposed by Chandy and Misra computes all shortestpaths towards one destination using the paradigm of di�usingcomputations , that is, a distributed computation that is initiatedby a single node, and joined by other nodes only after receiving amessage.To compute distances from every node to a given destination v0(and the corresponding channels) every node u initializeDu[v0] =∞ and waits for the receipt of messages..

A node v0 forwards a message 〈mydist, v0, 0〉 to all its neighbors.As soon as u receives a message 〈mydist, v0, d〉 from w and checksthe inequality d + ωuw < Du[v0] , it assigns d + ωuw to Du[v0] ,and sends the message 〈mydist, v0,Du[v0]〉 to all its neighbors.

Chandy�Misra algorithm

The algorithm proposed by Chandy and Misra computes all shortestpaths towards one destination using the paradigm of di�usingcomputations , that is, a distributed computation that is initiatedby a single node, and joined by other nodes only after receiving amessage.To compute distances from every node to a given destination v0(and the corresponding channels) every node u initializeDu[v0] =∞ and waits for the receipt of messages..A node v0 forwards a message 〈mydist, v0, 0〉 to all its neighbors.As soon as u receives a message 〈mydist, v0, d〉 from w and checksthe inequality d + ωuw < Du[v0] , it assigns d + ωuw to Du[v0] ,and sends the message 〈mydist, v0,Du[v0]〉 to all its neighbors.

Chandy�Misra algorithm

var Du[v0] : weight init ∞ ;Nbu[v0] : node init udef ;

Only for v0:begin Dv0 [v0] := 0 ;

forall w ∈ Neighv0 do send 〈mydist, v0, 0〉 to wend

Processing of the message 〈mydist, v0, d〉,received by u from w :

{ 〈mydist, v0, d〉 ∈ Mwu }begin receive 〈mydist, v0, d〉 from w ;

if d + ωuw < Du[v0] thenbegin Du[v0] := d + ωuw ; Nbu[v0] := w ;

forall x ∈ Neighu do send 〈mydist, v0,Du[v0]〉 to xend

end

Chandy�Misra algorithm

HOMETASK 2.

1. Prove that the formula below de�nes the invariant ofChandy�Misra algorithm computing the paths to a node v0.

∀u, w : 〈mydist, v0, d〉 ∈ Mwu =⇒ d(w , v0) ≤ d∧ ∀u : d(u, v0) ≤ Du[v0]

Using the invariant prove that the value Du[v0] is always anupper bound of d(u, v0), ò.å. d(u, v0) ≤ Du[v0].

2. Assuming that every sent message will be eventually delivered,prove that every execution of Misra-Chandy algorithm reachessuch a con�guration that in every node u inequalityDu[v0] ≤ d(u, v0) holds. This implies correctness of thealgorithm.

Chandy�Misra algorithm

HOMETASK 2.

3 The description of the Chandy�Misra algorithm does notindicate a termination condition for a process. Prove that inevery reachable con�guration the routing tables of the networkare acyclic. What needs to be added to the Chandy�Misraalgorithm so that each process can �nd out that theconstruction of routing tables in the network is complete?

END OF LECTURE 5.