a new distributed breadth-first-search algorithm

5
Information Processing Letters 25 (1987) 329-333 10 July 1987 North-Holland A NEW DISTRIBUTED BREADTH-FIRST-SEARCH ALGORITHM * Yunzhou ZHU Department of Computer Science, University of Science and Technology of China, Hefei, Anhui, People's Republic of China To-Yat CHEUNG Department of Computer Science, University of Ottawa, Ottawa, Ontario, Canada KI N 9B4 Communicated by David Giles Received 16 June 1986 Revised 4 November 1986 and 8 December 1986 A new distributed breadth-first-search algorithm for graphs is presented. Its worst-case communication and time complexi- ties are both O( IV 12), where IV [ is the number of vertices. The existing algorithm, due to Cheung (1983), has communication and time complexities O( IV[ 3) and O( IV 1), respectively. Keywords: Distributed system, breadth-first-search, communication complexity, graph, algorithm 1. Introduction For many graph-related problems, traversing a graph is an essential part of the method of solu- tion. The strategies and efficiency of a solution often depend on the method of traversal. For instance, several algorithms for the recognition of chordality of graphs and acyclicity of database schemes make use of a special type of breadth- first-search on the relevant graphs [4,5]. In a dis- tributed environment, it has been shown that a traversal method has even greater effects on graph algorithms. For example, Cheung [3] shows that, for the maximum network flow problem, the max- imum-capacity-search method, which has been demonstrated to be the least efficient [2] (among several commonly-used traversal methods) in a * This research is supported by the Natural Sciences and Engineering Research Council of Canada under Grant No. A8963 and by a research scholarship from the People's Republic of China. nondistributed environment, turns out to have the best complexity in the distributed version of the algorithms. In a nondistributed environment, execution of most of the widely-used traversal methods does not have much variation. However, in a distrib- uted environment, the same traversal scheme may be achieved in many ways, often with different orders of complexity. Cheung [3] presented two distributed traversal algorithms, one for depth-first-search (DFS) and one for breadth-first-search (BFS). Algorithm DFS requires O( IE [) in both communication and time complexities; algorithm BFS requires O( IV [ 3) and O(IVl), respectively. Awerbuch [1] improved Cheung's DFS algorithm and gave a new distrib- uted DFS algorithm with communication and time complexities O( I E I) and O( IV [), respectively. In this paper, a new distributed BFS algorithm is presented. Its communication and time com- plexities are both O( IV I 2). This is worse in time complexity but better in communication complex- ity than Cheung's. This phenomenon is often a 0020-0190/87/$3.50 © 1987, Elsevier Science Publishers B.V. (North-Holland) 329

Upload: yunzhou-zhu

Post on 27-Aug-2016

218 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: A new distributed breadth-first-search algorithm

Information Processing Letters 25 (1987) 329-333 10 July 1987 North-Holland

A NEW DISTRIBUTED BREADTH-FIRST-SEARCH ALGORITHM *

Yunzhou ZHU Department of Computer Science, University of Science and Technology of China, Hefei, Anhui, People's Republic of China

To-Yat CHEUNG Department of Computer Science, University of Ottawa, Ottawa, Ontario, Canada KI N 9B4

Communicated by David Giles Received 16 June 1986 Revised 4 November 1986 and 8 December 1986

A new distributed breadth-first-search algorithm for graphs is presented. Its worst-case communication and time complexi- ties are both O( IV 12), where IV [ is the number of vertices. The existing algorithm, due to Cheung (1983), has communication and time complexities O( IV[ 3) and O( IV 1), respectively.

Keywords: Distributed system, breadth-first-search, communication complexity, graph, algorithm

1. Introduction

For many graph-related problems, traversing a graph is an essential part of the method of solu- tion. The strategies and efficiency of a solution often depend on the method of traversal. For instance, several algorithms for the recognition of chordality of graphs and acyclicity of database schemes make use of a special type of breadth- first-search on the relevant graphs [4,5]. In a dis- tributed environment, it has been shown that a traversal method has even greater effects on graph algorithms. For example, Cheung [3] shows that, for the maximum network flow problem, the max- imum-capacity-search method, which has been demonstrated to be the least efficient [2] (among several commonly-used traversal methods) in a

* This research is supported by the Natural Sciences and Engineering Research Council of Canada under Grant No. A8963 and by a research scholarship from the People's Republic of China.

nondistributed environment, turns out to have the best complexity in the distributed version of the a lgo r i t hms .

In a nondistributed environment, execution of most of the widely-used traversal methods does not have much variation. However, in a distrib- uted environment, the same traversal scheme may be achieved in many ways, often with different orders of complexity.

Cheung [3] presented two distributed traversal algorithms, one for depth-first-search (DFS) and one for breadth-first-search (BFS). Algorithm DFS requires O( I E [) in both communication and time complexities; algorithm BFS requires O( IV [ 3) and O(IVl) , respectively. Awerbuch [1] improved Cheung's DFS algorithm and gave a new distrib- uted DFS algorithm with communication and time complexities O( I E I) and O( IV [), respectively.

In this paper, a new distributed BFS algorithm is presented. Its communication and time com- plexities are both O( IV I 2). This is worse in time complexity but better in communication complex- ity than Cheung's. This phenomenon is often a

0020-0190/87/$3.50 © 1987, Elsevier Science Publishers B.V. (North-Holland) 329

Page 2: A new distributed breadth-first-search algorithm

Volume 25, Number 5 INFORMATION PROCESSING LETTERS 10 July 1987

trade-off between these two complexity measures in distributed computing.

The main reason for the higher order of com- munication complexity of Cheung's previous BFS algorithm is that as soon as a node has been labeled, it starts trying to label its neighbors. As a consequence, nodes at different levels of the BFS tree may be sending and receiving label messages simultaneously. Many nodes ar~: first temporarily labeled with a level number higher than the cor- rect one but relabeled to a lower level number later. Obviously, such simultaneity will result in a good time complexity O( IV l) but a relatively higher communication complexity O(IV 13).

2. The new distributed breadth-first-search algorithm

In this paper, undirected, connected graphs are considered. The model of computation is essen- tially the same as in [3]. Briefly, this means that:

(1) the graph is embedded in a communi- cations network and a process is located at each node of the graph,

(2) there is no node or link failure during ex- ecution of the algorithm,

(3) along a link, messages arrive at the destina- tion process in the order sent,

(4) processes do not share memory, and it takes unit time to send a message from one node to another, and

(5) every node only knows its neighbors. The main idea in the new algorithm is that a

BFS tree is created level by level. In fact, the algorithm can be considered as iterative. Each iteration creates a new level in two phases: a LABELing phase and an Echoing phase. In the LABELing phase, starting with the root, a LABEL message is broadcast over each edge of the BFS tree created in the previous iteration. Leaves of the tree then issue LABm. messages to their unex- plored neighbors so as to create another level of nodes. This ends the LABELing phase. The ECho-

ing phase starts with the new leaf nodes sending ECHO messages, again one along each edge, all the way back to the root. This terminates the current iteration. It is then decided by the root process whether another iteration is needed. Some details follow.

During a LABELing phase, a node may receive a LABEL message in three cases:

Case 1. It has never been labeled before. It then assigns to itself a permanent level number (one higher than its parent's) and the sender of the message is assigned as its permanent parent. Then, if it has no more unexplored neighbors, it informs its parent in an E c h o message with status = "end" that the path is ended. On the other hand, if it still has some unexplored neighbors, it informs its parent in an ECHO message with status = "keepon" that the path can be extended.

Case 2. It has already been labeled and the LABEL message is sent by its parent. It then relays the message to the next level, since the message is broadcast by the root for the purpose of extending the current tree.

Case 3. It has already been labeled and the LABEL message is sent by one of its nonparent neighbors. It returns an Echo message with status = "stop" to indicate that no further messages are necessary.

Every node keeps a record of the neighbors to which it has sent a LABEL message. When all these neighbors have echoed with either a "stop" or an "end" status, the node echos to its parent with an "end" status.

The algorithm is completed when the root has received an E c h o message with status = " e n d " from all its children.

A formal description of the algorithm is given below in Dijkstra's guarded command notation. The algorithm specifies the actions to be taken by the process at node i in response to the message it receives. Note that the process is a sequential program, i.e., no two fragments of it can be ex- ecuted simultaneously.

330

Page 3: A new distributed breadth-first-search algorithm

Volume 25, Number 5 INFORMATION PROCESSING LETTERS 10 July 1987

Messages

INIT: LABEL(k, lev): ECHo(k, status):

The algorithm uses three types of messages:

sent to the starting node to initiate a traversal, sent by node k to request node i to label itself with level number (lev + 1), a response message sent by node k; information about the possibility of extending the BFS tree through node k is conveyed through the following three possible values of parameter "status": (a) "keepon" :"node i can 'keep on' sending LABEL messages to node k, since some

neighbors of k may not have labels", (b) "stop" :"node i should 'stop' sending LABEL messages to node k, since node k

cannot be the child of node i", (c) "end" :"node k is the 'end' of extension, since it has no more unexplored

neighbors".

Local variables at node i z

Neighbor: Labeled: Parent: Level: SendTo: Child: Echoed(j):

the set of nodes adjacent to node i in the graph, a logical variable, with value "true" if and only if node i has been labeled, the parent of node i in the BFS tree; the root is its own parent, the level number of node i (if labeled) in the BFS tree, the subset of Neighbor: those neighbors to which node i sends LABEL messages, the set of children of node i in the BFS tree, a logical variable with value "false" if node i has sent to node j a LABEL message but has not received an ECHO message for it.

Algorithm BFS

Initiation: In each node, set Labeled := false. To start the algorithm, the message INIT is sent to the starting node of the traversal.

The process at node i: The process reacts according to the message it receives.

{ * On receiving message INIT * ) Labeled, Parent, Level "= true, i, 0; SendTo, Child := Neighbor - {i}, ~0; if SendTo = ~[ ~ COMPLETED

SendTo q: ~ ~ for each j in SendTo do [send LABEL(i, Level) to node j; Echoed(j):= false]

fi { * On receiving message LABeL(k, lev) from node k • } if --, Labeled --, Labeled, Parent, Level := true, k, lev + 1;

SendTo, Child := Neighbor - {k}, ~; if SendTo = ~ ~ send ECHO(i, 'end') to Parent [] SendTo 4= ~ ~ send ECHO(i, 'keepon') to Parent fi

331

Page 4: A new distributed breadth-first-search algorithm

Volume 25, Number 5 INFORMATION PROCESSING LEITERS 10 July 1987

[] Labeled --* if Parent = k ~ for each j in SendTo do [send LAnEL<i, Level) to node j; Echoed(j) .'= false]

[] Parent ~ k ---> send ECHO~i, 's top') to node k fi

fi ( * On receiving message ECHo~k, Status) from node k • } Echoed(k) := true; if Status = 'keepon' ~ Child := Child t2 {k} [] Status = ' s top ' ---> SendTo "= SendTo - {k} [] Status = 'end' ~ Child -= Child U (k}; SendTo := SendTo - {k) fi; if SendTo = ~ ~ if Parent = i ~ COMPLETED ~

[] Parent ~: i ~ send Ecno~i, 'end') to Parent fi

[] SendTo ~ --> if for all (j :j in SendTo: Echoed(j)) if Parent = i ~ for each j in SendTo do

[send LAn~L(i, Level) to node j; Echoed(j) := false] [] Parent #: i ---, send ECHO~i, 'keepon') to Parent fi

[] ~ for all (j :j in SendTo: Echoed(j)) ~ SKIP fi

fi

When the algorithm is completed, every node should have obtained a child set. These child sets together constitute a solution to the problem in the form of a distributed BFS tree rooted at the starting node. Note that, depending on the imple- mentation and application, the processes them- selves may or may not terminate at this time. For example, the root may broadcast a message to all the nodes to terminate their processes. However, this is a system programming problem and is irrelevant to the algorithm.

The validity of the algorithm is a consequence of the following facts.

Fact A. At completion, each node is labeled and has exactly one parent. The root is its own parent. This implies that the solution is a tree.

For the root, it labels itself and is its own parent (see the section of the INIT message).

For any other node, if it has not been labeled, it is always an unexplored node of its neighbors (i.e., it remains in the set SendTo of its neighbors).

Since the graph is connected and every labeled node tries to label its unexplored neighbors, it will eventually receive at least one LAnFL message and obtain one parent.

Furthermore, since the first statement in the section of the Lxnm. message is the only statement that assigns a parent to a node and it is executed only once throughout the entire algorithm, every node has at most one parent.

Fact B. The algorithm will be completed.

This follows from the observation that every node will be labeled (by Fact A) and that every labeled node responds to a LAa~L message with EcHo(i, 's top') if the sender is a nonparent neighbor, or 'eventually' with Ecno~i, 'end ' ) if the sender is its parent. (Note: 'eventually' is understood in the following context: When a node sends a LABE~ message to a child that has some neighbors to explore, that child does not respond with EcHO~i, 'end') immediately but responds with ECHO~i, 'keelson' ). However, when that child

332

Page 5: A new distributed breadth-first-search algorithm

Volume 25, Number 5 INFORMATION PROCESSING LETTERS 10 July 1987

has finished dealing with its neighbors, it sends ECHO(i, ' end ' ) to its parent as a 'delayed' re- sponse.) Hence, in a node, every LABEL message is echoed with a status of either "stop" or "end". This makes the set SendTo become null eventu- ally. In particular, at the starting node, this leads to completion stage of the algorithm.

Fact C. At completion, the child sets form a BFS tree.

This follows from the observation that a child's level is always 1 bigger than its parent's and that the nodes are labeled level by level.

Fact D. At completion, no message will still be underway.

When a node sends ECHO(i, 'end') to its parent, its set SendTo is empty. This means that the node has ceased sending out any LABEL messages to its neighbors, though it can still receive LABEL mes- sages and respond with ECHO messages. However, when the root has received ECHo(k, 'end') from all of its children, all nodes in the entire BFS tree must have sent an ECHO(i, 'end') message to their parents. This means that no node is sending a LABEL message and that, as a consequence, no node will send ECHO messages. That is, no more messages are underway.

Algorithm BFS has the following complexity.

Theorem. In the worst case, both the communica- tion and time complexities of Algorithm BFS are O(IVI 2).

Proof. Let G s = (V, Ee) be the resulting BFS tree of the given graph G = (V, E). Consider the edge set E ' = E - E n. Since four messages (one LABEL and one ECHo(k, 's top') in each direction) are transmitted over each edge of E ' throughout the entire process, the total number of messages trans- mitted over E ' is 4( IEI - lEE I)-

As for the BFS tree G e, assume that it has k levels. Let T i be the subtree containing only the first i levels of G B. Let t(T) and p(T) respectively denote the tree-length (i.e., the total number of edges) and path-length (i.e., the sum of lengths of all paths from the root to the leaves) of tree T. Obviously, t (T)~ p(T) for any tree T. As ex- plained before, in iteration i, a LABEL message and an ECHO message are transmitted over each edge of T i. Thus, the total number of messages throughout the entire process is 2Eik=lt(Ti). This quantity is bounded above by 2Elk= l p(Ti). In the worst case, G e degenerates to a linear tree, whose subtrees rooted at the same node as G e have a total path-length ½ IV I( I V I - 1). Hence, the al- gorithm has a worst-case communication complex- ity IVI(IVI-1)+4(IEI- IEel ) , or O(IV12).

It is obvious that the worst-case time complex- ity is the same as the worst-case communication complexity. []

Acknowledgment

The authors are grateful to the editor and an unknown referee for their suggestions, which greatly improved the presentation of the paper.

References

[1] B. Aweabuch, A new distributed depth-first-search al- gorithm, Inform. Process. l.¢tt. 20 (3) (1985) 147-150.

[2] T.-Y. Cheung, Computational comparison of eight methods for the maximum network flow problem, ACM Trans. Math. Software 6 (1) (1980) 1-16.

[3] T.-Y. Cheung, Graph traversal techniques and the maxi- mum flow problem in distributed computation, IEEE Trans. Software Engrg. SE-9 (4) (1983) 504-512.

[4] D.J. Rose, R.E. Tarjan and G.S. Lueker, Algorithmic aspects of vertex elimi,ation on graphs, SIAM J. Comput. 5 (2) (1976) 266-283.

[5] Y. Zhu, Line graph of gamma-acyclic database schemes and its recognition algorithm, Proc. 10th Conf. on VLDB, Singapore (1984) 218-221.

333