You are on page 1of 18

Wave and Traversal Algorithms

Slides: Edited from slides of Prof. Pallabh Dasgupta

Content: Distributed Algorithms by Gerald Tel


Chapter 6:: 6.2.3, 6.2.4, 6.4.1, 6.4.2

1
Motivation
Broadcasting information
Triggering some event in every process
Achieving global synchronisation

Plays a fundamental role as a subtask in many complicated problems like


leader election
Mutual exclusion etc

2
Assumptions
Network topology is fixed
Graph is undirected (channel carries msgs in both directions)
Connected (path btwn any two processes) ..however depends on underlying
topology that is assumed

3
Time complexity of Distributed Algorithm
Time complexity of a distributed algorithm is the maximum time
taken by a computation of the algorithm under following assumptions

-A process can execute any finite number of events in zero time

-The time between sending and receipt of a message is at most one time unit.

For traversal algorithms the time complexity equals the message complexity. (The messages are
exchanged serially and each can take one time unit)

4
The Echo Algorithm – a wave algorithm
var recp : integer init 0; // Counts no of recvd mesgs
fatherp : process init udef;

For the initiator


begin forall q  Neighp do send  tok  to q ;
while recp < #Neighp do
begin receive  tok  ; recp = recp + 1 end ;
decide
end

For non-initiators
begin receive  tok  from neighbor q ; fatherp = q ; recp = recp + 1 ;
forall q  Neighp, q  fatherp do send  tok  to q ;
while recp < #Neighp do
begin receive  tok  ; recp = recp + 1 end ;
send  tok  to fatherp

5
Questions
Consider a triangle with nodes a, b and c. Say a is the initiator.
Node a sends the token to b and c and b further sends to c. However, before a’s token reaches c,
the token of b reaches c. Will the count of responses from people sent to now go wrong as a is
expecting a response from c which it wont get and c has got a msg from a which is not its parent.

Ans: a wont get response from c for the token sent but will get token msg from c. c gets msg from
b with token and a too with token. His received msg count is 2. He responds to b when received
msg count is 2. When a counts received msgs it has 2 (one which is the response msg from b and
second is the token msg from c) .

Issue: c could have responded to b without receiving a’s token msg but now has to wait until a’s
token too is received though it has no influence.

6
Note: it creates a tree if we allow each node to be connected only to its parent.
Can a node identify its son ? What can we do to allow this.

Complexity :
2|E| messages..one msg to every neighbor leaves the node and you get a msg back
from every neighbor (or vice versa)
Time complexity : Diameter of the graph (the greatest distance among the shortest
distances between any pair of vertices)- time btwn the two nodes which are farthest
away

7
Classical Depth-first Search

var usedp[q] : boolean init false for each q  Neighp ;


fatherp : process init udef ;

// For the initiator only – execute once


begin
fatherp = p ;
choose q  Neighp ;
usedp[q] = true ;
send  tok  to q ; //only one msg sent
end

8
Classical Depth-first Search contd..
For each process p, upon receipt of  tok  from q0:
// A node q0 is the father only if p is receiving the token for the first time from q0
if fatherp = udef then fatherp = q0 ; //q0 is my father
if q  Neighp: usedp[q] then decide //only initiator will have all neighbours are used.
Other will have father as unused
else{ if q  Neighp: (q  fatherp  usedp[q]) //this could be q0 itself too
{ if fatherp  q0  usedp[q0] then q = q0 //q0 not my father but the token I have sent out through
some neighbour has come back ,so this is a cycle,

else choose q  Neighp \ { fatherp } with usedp[q] ;


usedp[q] = true ;
send  tok  to q
}
else {
usedp[ fatherp ] = true ;
send  tok  to fatherp

9
Questions
Why is a token returned back immediately if it has come via an unused neighbour?
Line: “if fatherp  q0  usedp[q0] then q = q0”

How many steps does the token take?

Consider a clique: Out of the 2|E| =2n2 edges, in how many steps, does the algorithm
actually visit all nodes? –how many tree edges are there?

10
Classical Depth-first Search Algorithm

 Distributed DFS terminates when the initiator gets the token back

 The classical depth-first search algorithm computes a depth-first search


spanning tree using 2|E| messages and 2|E| time units

 Because along every edge the token goes once in one direction and once
back

11
Awerbuch’s DFS Algorithm
 Prevents the transmission of the token through a frond (non tree) edge

 When process p is first visited by the token


– p informs each neighbor r, except its father, of the visit by sending a vis message to
r
– The forwarding of the token is suspended until p has received an ack message from
each neighbor

 When later, the token arrives at r, r will not forward the token to p as r is aware of the token
have reached p. The token is sent to p only if p is r’s father and all neighbours of r have
been marked as used.
Consider the clique example

12
Why does a node send vis to a node from whom it has already received a vis.
Node a got the token and sent vis to c. When token reaches c, then node c knows
that he does not have to send the token to a. But why does c send vis to a?

Can a visited node receive a token from a neighbour q which is not father and not
used given that the node had already sent a vis to q ?

13
Why does a node send vis to a node from whom it has already received a vis.
Node a got the token and sent vis to c. When token reaches c, then node c knows that he does
not have to send the token to a. But why does c send vis to a?
To inform a to mark c as used so that a wont send the token to c

Can a visited node p receive a token from a neighbour q which is not father and not used given
that the node had already sent a vis to q ?
No, because p being visited had received the token at some point. Then, p would have forwarded
the token to someone only after receiving an ack from all its neighbours including q. so q is aware
of p being its neighbour and wont forward a token to p.

14
Complexity
Awerbuch’s algorithm computes a depth-first search tree in 4N – 2 time units and uses 4.|E| messages

Messages: Being an undirected graph you have tree edges and backedges.

Tree edges: Token goes to child and back during backtracking. Also a vis and acks passes. Hence 4 msgs
Non tree edge a-b: vis and ack from a to b and again vis and acks also from b to a. . Hence 4 mgs
Messages: 4E

Time units:
Number of time stamps: Token travels only n-1 steps.
Token msgs are only 2(n-1)
Vis and ack msgs are one round before forwarding the token
so 2(n-1) time steps for token + 2n for vis and for ack
Time steps : 4N

15
Cidon’s DFS Algorithm
 The token is forwarded immediately. Eliminates ack msgs
 The following situation is important:
– Process p has been visited by the token and has sent a vis message to its neighbor r
– The token reaches r before the vis message from p
– In this case r may forward the token to p along a frond edge

 The situation is handled as follows:


– Process p records to which neighbor it most recently sent the token – normally it expects
to get it back from the same
– If it gets it back from some other neighbor it ignores the token, but marks the edge rp as
used, as if it received a vis message from p
– When r eventually receives the vis message from p it behaves as if it never had sent the
token to p. It regenerates the token and continues
 Cidon’s algorithm computes a DFS tree in 2 N – 2 time units and uses 4.|E| messages

16
Complexity

Distributed systems counts one time unit as max time of message from source to destination.

Messages: 4E (2 token and 2 vis per channel ) as per original algorithm where you send vis to all
(even to neighbour you are going to send the token to and your father). Else 2E messages(either vis
both directions or token both directions)
Time units: 2(N-1) ( token movement). Here the vis sent is not to be waited upon for receipt so one
time unit is only time for token to reach next process. By definition of time unit for distributed systems,
finite operations take 0 unit time so sending out vis takes 0 unit time. We do not wait on vis to reach.
Note: the UTMOST time for token to pass is one time unit. So a token can makes 10 movements to
10 new processes by the time the vis of the initiator reaches a process . That is by one time unit (vis
took), token travelled 10 moves(as each move could have taken 1/10th of time unit. The maximum
time in 1 time unit. Token need not have taken that much time)

17
Steps Messages
Classical 2E 2E
Awerbuch 4N-2 4E
Cidon 2(N-1) 4E

18

You might also like