1. Flooding Algorithm and building a spanning
Tree
• The communication network does not have a spanning tree from
before.
• Root initiates a message broadcast.
• Root sends message to all its neighbors.
• And sets the seen flag to true.
7. Basic Flooding Algorithm
• Each process maintains a single bit of state: seen-message.
• At time 0, root sets seen-message to true and sends M to all
neighbors except pj.
• Upon receiving M:
• If seen-message = false,
• seen-message ← true
• send M to all neighbors
• Else do nothing
8. Message complexity of flooding
• m = total number of communication channels
• When a processor receives a message for the first time from some
neighboring processor pj it sends the message <M> to all its neighbors
except pj.
• A processor will not send <M> more than once on any communication
channel.
• This <M> is sent at most twice on each communication channel. [hint:See
the channel between P1 and P2 in slide 9 and 10 and between P5 and P6].
• Note there are executions in which the message <M> is sent twice on all
communication channels except those on which <M> is received for the
first time.
• Thus it is possible that 2m- (n-1) messages are sent . This can be as high as
(n(n - 1))/2
9. Home work and Discussion
Refer Distributed Computing book page 17,18 [Difficulty level : easy ]
Question: Write the following Lemmas in your homework sheet along with
their proof
• Lemma 2.1
• Lemma 2.2l
• Lemma 2.3
• Lemma 2.4
And bring to next class. I will choose one person from each group to go over
the proof. First 15-20 minutes of the class will be spent in discussion.
The answers have to be written paper sheets in ink/pencil. No copy pasting
in word document and bringing printouts.
10. Modified flooding algorithm
• Each process maintains a single pointer parent, initially ⊥.
• Neighbors of a Processor need not be children but children will be its
neighbor.
• Each process has two lists - children and other [neighbors which are
not children
• In the earlier algorithm a spanning tree is not explicitly constructed.
• Use <parent> and <already>messages.
11. //Initially parent = ⊥ children = nil, other = nil . Other U children = all the neighbors
//Wake up root to send <M>. At this point root has not sent message
Upon receiving no message:
If pi = pr and parent = ⊥ then
Send <M> to all neighbors
Parent = pi
//Pj has not received <M> before.
Upon receiving <m> from neighbor pj:
If parent == ⊥then
Parent = pj
Send <parent> to pj
Send <M> to all neighbors except pj
Else send <already> to pj
Modified Flooding algorithm to construct a spanning tree. Code for processor pi 0<= I <= n-1
12. Upon receiving <parent> from neighbor pj:
Add pj to children
If children U other contains all neighbors except parent then
Terminate
Upon receiving <already> from neighbor pj:
Add pj to other
If children U other contains all neighbors except parent then
Terminate
15. • It will continue and broadcast the message and eventually the
algorithm will build a spanning tree.
• Question: (Bonus Points )
Prove that this algorithm will build a spanning tree
[Hint : Lemma 2.6 ]
16. Depth First Spanning Tree
• The previous flooding algorithm created a BFS spanning tree because
it sent messages to all the neighbors.
• It was done level by level .
• In DFS Each processor has two sets associated with it
• A set of children
• A set of all neighbors which is called unexplored set
• Processors send <M> , <already> , and <parent> messages to each
other
• The set of children gets populated by the recipient when <parent>
message is sent
17. Depth search spanning tree algorithm for a
specified root. Code for processor pi,0<=i<= n-1
//Initially parent = ⊥ children = nil, unexplored= all neighbors of pi
//Wake up root to send <M>. At this point root has not sent message
Upon receiving no message:
If pi = pr and parent = ⊥ then
parent = pi
explore()
//Pj has not received <M> before.
Upon receiving <m> from neighbor pj:
If parent == ⊥then
Parent = pj
Remove pj from unexplored
explore()
else
send <already> to pj
Remove pj from unexplored
18. Upon receiving <already> from pj:
explore()
Upon receiving <parent> from pj:
add pj to children
explore()
Procedure explore():
if unexplored # nil then
let pk be a processor in unexplored
remove pk from unexplored
send <M> to pk
else
if parent #pi then //This is important because the only case
//when the parent of a processor is in the
// case of root
send <parent> to parent
35. DFS Spanning tree without a specified root
• Three different types of messages are sent each message is tagged
with either of the following
• leader
• already
• parent
leader
already
leader
36. Spanning tree construction: code for
processor pi 0<= i <= n-1
Initially parent = ⊥ children = nil, unexplored= all neighbors of pi
//Wake up all nodes spontaneously
Upon receiving no message:
If parent = ⊥ then
leader = id
parent = pi
explore()
37. Spanning tree construction: code for
processor pi 0<= i <= n-1
//Switch to new tree
Upon receiving <leader, new-id> from pj:
If leader < new-id then
leader = new-id
parent = pj
children = nil
unexplored = all neighbors of pj except pj
explore()
else if leader == new-id then
send <already, leader> to pj //this processor is already in the same tree
//otherwise leader > new-id and the DFS for the new-id is stalled.
38. Spanning tree construction: code for
processor pi 0<= i <= n-1
//Switch to new tree
Upon receiving <already, new-id> from pj:
If new-id == leader then
explore()
39. Spanning tree construction: code for
processor pi 0<= i <= n-1
//Switch to new tree
Upon receiving <parent, new-id> from pj:
If new-id == leader then
Add pj to children
explore()
40. Spanning tree construction: code for
processor pi 0<= i <= n-1
//Switch to new tree
procedure explore() :
If unexplored != nil then
let pk be a processor in unexplored
remove pk from unexplored
send <leader, leader> to pk
else
If parent != pi then send <parent, leader> to parent
else
terminate as root of spanning tree
43. 34
55
23
34 11
29
20 19
55
24
already
leader
Upon receiving <leader, new-id> from pj :
If leader < new-id then
leader = new-id
parent = pj
children = nil
unexplored = all neighbors of pi
except pj
explore()
else if leader == new-id then
send <already, leader> to pj
44. 34
54
23
34 11
29
20 19
55
24
already
leader
procedure explore() :
If unexplored != nil then
let pk be a processor in
unexplored
remove pk from unexplored
send <leader, leader> to pk
else
If parent != pi then send
<parent, leader> to parent
else
terminate as root of
spanning tree
The node with leader 34
belongs to a DFS with id
smaller than the maximal
identifier seen so far.
Do nothing. Stall the DFS
creation for this DFS