Part I Fundamental Algorithms
5.3 Depth-First-Search Algorithms
5.3.3 Distributed DFS with Neighbor Knowledge
The DFS algorithm Neigh_DFS uses a token to traverse the nodes of the network in a sequential manner as in the previous algorithms. Since we need a way to know which nodes have been visited so that they are not visited again, a token may be used for this purpose. The token includes the visited node list which is appended by the node identifier of a node that is visited for the first time. The algorithm Neigh_DFS is depicted in Algorithm5.5, where node i chooses a neighbor j to send the token only if it is not included in the list (vislist) of already visited nodes of the token.
5.3.3.1 Analysis
Theorem 5.5 Neigh_DFS algorithm constructs a DFS tree in 2n−2 times using 2n−2 messages.
Proof The final spanning tree will haven−1 edges, and only the edges of this tree will have been traversed twice in each direction resulting in a total of 2n−2 token transfers among the nodes resulting in 2n−2 messages. Since there is a single ac-tivity at any time, each message delivery action corresponds to a time unit resulting
in 2n−2 times.
Figure5.5 shows the operation of Neigh_DFS in a sample network, where n equals 8, and edges of the tree are labeled by the time frame token traverses them.
The contents of the token when it is first received by a node and the final token as received by the root node 4 are also shown. The formed DFS tree takes 14 messages
5.3 Depth-First-Search Algorithms 65 Algorithm 5.5 Neigh_DFS
1: int parent←⊥
2: set of int vislist←∅ 3: message types token 4:
5: if i=root then root starts the algorithm
6: parent←i, choosej∈Γ (i) 7: send token({i})toj 8: end if
9:
10: while true do
11: receive token(j,vislist)
12: if parent=⊥then token received first time
13: parent←j 14: end if
15: if∃j∈Γ (i)\ {vislist} then choose an unsearched node if any 16: choosej∈Γ (i)\ {vislist}
17: send token(vislist∪ {i})to j 18: else ifi=root then
19: exit if all searched and root, terminate
20: else if all searched and not root, return token to parent 21: send token(vislist∪ {i})to parent
22: exit all nodes except root terminate
23: end if 24: end while
Fig. 5.5 Neigh_DFS execution example
(2·8−2)and also 14 time units as shown. The bit complexity of this algorithm is O(nlogn), assuming that lognbits are used to represent a single node identity. For a large network wheren1, this high bit complexity is disadvantageous as token has to be transferred 2n−2 times. For this example network, the bit complexity is O(8·3)=O(24).
66 5 Graph Traversals Table 5.1 BFS and DFS
algorithm complexities Algorithm Time Comp. Msg. Comp.
BFS Synch_BFS O(d2) O(nd+m)
Asynch_BFS O(d) O(nm)
DFS Classical_DFS 2m 2m
Awerbuch_DFS 4n−2 4m
Neigh_DFS 2n−2 2n−2
Fig. 5.6 Example graph for Exercise4
5.4 Chapter Notes
We have reviewed fundamental BFS and DFS algorithms. Comparison of BFS and DFS Algorithms is shown in Table5.1. For BFS, Synch_BFS has a better message complexity, and Asynch_BFS has a better time complexity. A challenge, therefore, is to design distributed BFS algorithms that optimize both time and message com-plexities. For DFS, the Neigh_DFS performs better than the other two algorithms as in general,mn; however, the token has to hold the identifiers of nodes, which requires a space complexity ofO(nlogn)bits, which may not be trivial for largen values. Cidon [2] provided a further decrease in time by abolishing the ack messages in Awerbuch’s Algorithm resulting in 2n−2 times usingO(4m)messages.
5.4.1 Exercises
1. Provide an FSM-based solution for Algorithm5.2by drawing the FSM and writ-ing the pseudocode.
2. Modify Algorithm5.2so that a counter, sometimes called Time To Live (TTL) field, in each message is used, which is initialized to the diameter of the network by the root. Each node receiving the layer message now decrements TTL value, and if this reaches zero, the layer message is not forwarded to any neighbors.
Show the operation on the sample graph of Fig.5.2.
3. Provide the pseudocode for the synchronous version of Update_BFS algorithm and work out its time and message complexities.
4. Show the execution of the sequential BFS and DFS algorithms in the sample graph of Fig.5.6starting from node 1. The DFS algorithm always selects the highest identifier node from the unsearched nodes.
References 67 Fig. 5.7 Example graph for
Exercise4
Fig. 5.8 Example graph for Exercise5
5. Show the execution of Asynch_BFS Algorithm in the example graph of Fig.5.7 starting from node 3.
6. Describe and show the messages in a possible execution of Neigh_DFS Algo-rithm in the example graph of Fig.5.8starting from node 6 and assuming highest identifier is always selected to transfer the token. Show also the contents of the token in each iteration.
7. Describe how ack messages in Awerbuch_DFS Algorithm may be prevented (Cidon’s Algorithm). Also, show that this algorithm achieves 2n−2 times using at most 4mmessages.
References
1. Awerbuch A (1985) A new distributed depth first search algorithm. Inf Process Lett 20:147–
150
2. Cidon I (1988) Yet another distributed depth-first-search algorithm. Inf Process Lett 26:301–
305
3. Peleg D (2000) Distributed computing: a locality-sensitive approach, Chap. 5. SIAM, Philadel-phia. ISBN 0-89871-464-8
4. Tary G (1895) Le problème des labyrinthes. Nouv Ann Math 14
5. Tel G (2000) Introduction to distributed algorithms, 2nd edn. Cambridge University Press, Cambridge
Chapter 6
Minimum Spanning Trees
Abstract A minimum spanning tree of a weighted graph is its spanning treeT with a minimum total cost of edges inT of all possible spanning trees. Minimum span-ning trees have many applications in computer networks. In this chapter, we inves-tigate synchronous and asynchronous distributed algorithms to construct minimum spanning trees.
6.1 Introduction
A minimum spanning tree (MST) of a weighted graphG(V , E, w), wherew:E→ R, is a spanning tree such that the sum of the weights of edges of this tree is min-imum among all possible spanning trees of the graph G. If Gis unconnected, a minimum spanning forest ofGis the union of all its such trees. Formally:
Definition 6.1 Given a weighted graphG(V , E, w), MST(G)=(V , E, w)with E⊂Ethat minimizes
ewe∈E.
MSTs can be used in constructing networks between nodes using the least amount of communication wire, in smaller electronic circuits, and for clustering.
MST of a graph may be also used for more complicated algorithms and protocols.
The MST algorithm also solves the leader election problem in general graphs, where the leader is simply the last root. In this chapter, we first describe two sequential al-gorithms and then analyze distributed implementations based on these alal-gorithms.