Assigning labels in an unknown anonymous network with a leader

51

Transcript of Assigning labels in an unknown anonymous network with a leader

Assigning labels in an unknown anonymous networkwith a leaderPierre Fraigniaud �([email protected]) Andrzej Pelc y{([email protected]) David Peleg z([email protected])St�ephane P�erennes x([email protected])AbstractWe consider the task of assigning distinct labels to nodes of an unknown anonymousnetwork in a distributed manner. A priori, nodes do not have any identities, exceptfor one distinguished node, called the source, and do not know the topology or the sizeof the network. They execute identical algorithms, apart from the source which playsthe role of a leader and starts the labeling process. Our goal is to assign short labels,as fast as possible. The quality of a labeling algorithm is measured by the range fromwhich the algorithm picks the labels, or alternatively, the length of the assigned labels.Natural e�ciencymeasures are the time, i.e., the number of rounds required for the labelassignment, and the message and bit complexities of the label assignment protocol, i.e.,the total number of messages (resp., bits) circulating in the network. We present labelassignment algorithms whose time and message complexity are asymptotically optimaland which assign short labels. On the other hand, we establish inherent trade-o�sbetween quality and e�ciency for labeling algorithms.�Laboratoire de Recherche en Informatique - CNRS, Universit�e Paris-Sud, 91405 Orsay, France.yD�epartement d'Informatique, Universit�e du Qu�ebec �a Hull, Hull, Qu�ebec J8X 3X7, Canada.Supported in part by NSERC grant OGP 0008136.zDepartment of Computer Science and Applied Mathematics, The Weizmann Institute, Rehovot 76100,Israel. Supported in part by grants from the Israel Science Foundation and the Israel Ministry of Science andArt.xSLOOP I3S-CNRS/INRIA, Universit�e de Nice-Sophia Antipolis, 2004 Route des Lucioles, BP 93, F-06902Sophia Antipolis Cedex, France.{Research done during this author's visit at INRIA Sophia Antipolis.

1 Introduction1.1 The problemDesigning network algorithms without complete information about the network is an impor-tant problem whose many variations have been extensively studied. Of particular interest arecomputations in anonymous networks (cf. [2, 3, 4, 8, 10, 12, 13, 16, 17, 18, 19]), in whichprocessors do not have distinct identities and execute identical algorithms. The impossibilityof distinguishing processors yields symmetry in computations and restricts the computationalpower of the network.The situation is even more drastic if the topology of the network and even its size areunknown, and the only knowledge available to a node is its own degree. Such is, e.g., thesituation when a robot has to explore an unknown graph, in order to draw a map of it (cf.[1, 9, 15]), or when a node has to broadcast information to all nodes of an unknown network[7, 11].Known characterizations of the attainable and unattainable tasks in unknown anonymousnetworks reveal that assuming no means of symmetry breaking, little can be done. In par-ticular, it is impossible to select a unique leader, or to assign unique labels (or ID's) to thenetwork nodes. This impossibility result (characterized in [14] as \ancient folklore") is ofrather general scope, and it applies in virtually every model of communication, including theasynchronous FIFO model studied in many of the papers cited above, as well as the commonsynchronous model (cf. [14, Chapt. 3] or [5, Chapt. 3]).On the other hand, it is equally well known (see, for example, [16, 19] and the referencestherein) that even in an unknown anonymous network, the existence of a unique leader in thenetwork makes it computationally equivalent to a full-knowledge environment, in which uniquenode labels exist, and every node in the network knows the entire topology. This equivalencewas shown in [16, 19] for the asynchronous FIFO model, but this clearly implies the same alsofor the common all-port synchronous model. The current paper studies a number of models,some of which do not fall under this category. However, the results presented in the currentpaper e�ectively prove that in all of our models as well, the existence of a unique leader inthe network is computationally at least as strong as the existence of unique node labels.From a complexity-oriented point of view, however, there is a rather signi�cant di�erencebetween the two environments, in the sense that the cost of transforming from the formerenvironment (of an unknown anonymous network with a distinguished leader) to the latter(of a network with unique node labels) may be expensive.In this paper we consider the cost of this transformation, namely, the task of assigningdistinct labels to nodes of an unknown anonymous network in which there is a distinguished1

node playing the role of a leader. Thus the initial state is that of complete ignorance; nodesdo not know the topology or even the size of the network, and they do not have any labels.The only knowledge available to a node is its own degree. (We assume a model in which eachnode has the ability to distinguish between its outgoing links. In a model where nodes lackthis capability, namely, a broadcast medium, the existence of a leader is still insu�cient forenabling distinct label assignment [18].) Asymmetry is provided by postulating the existenceof a unique node s, called the source, which e�ectively acts as the leader and initiates thelabeling process. All other nodes execute identical algorithms.We assume a synchronous model, where communication between nodes is executed inrounds controlled by a global clock. A message sent by a node to its neighbor in a given roundbecomes available at the neighbor in the next round. The goal of a labeling protocol is toassign distinct labels to all nodes of the network.1.2 Models and complexity measuresThe natural measure for the quality of the solution is the range from which the algorithmpicks the labels, or alternatively, the length of the assigned labels. The signi�cance of thisparameter is that in any subsequent use of the labels within any distributed algorithm, thelabel length will directly a�ect the size of the messages sent by the algorithm. Hence it isdesirable to assign labels which are as short as possible.On the other hand, the natural e�ciency measures are the time, i.e., the number of roundsrequired for the label assignment, and the message and bit complexities of the label assignmentprotocol, i.e., the total number of messages (resp., bits) circulating in the network. As onemight expect, our results imply that there are inherent tradeo�s between the quality ande�ciency parameters for the label assignment problem.It turns out that the precise communication model used signi�cantly impacts the results.We consider three natural models. In the all-port model, every node can send a message toeach of its neighbors, as well as receive a message from each neighbor, in each round. At theother extreme, the one-port model allows each node, in each round, to send only one messageto a single neighbor, or to receive a single message from a neighbor, but not both. Finally,in the intermediate (or mixed) model, every node is allowed to send only a single message (toone neighbor) per round, but it may receive messages from many neighbors simultaneously.Since nodes are ignorant of network topology, they cannot distinguish between yet unusedadjacent links. Consequently, the local decision made by a node, regarding which of itsoutgoing links it should use to send a message in a particular round, can be thought of as�xed by an adversary, as in [1, 9, 11, 15]. We adopt the worst-case approach, i.e., we areinterested in the performance of the protocol resulting from the most detrimental behavior of2

the adversary.For a given labeling algorithm A, and a network G with source s, let �(A;G; s) denote thetime required by A to labelG starting at s, under the worst-case behavior of the adversary. Thetime complexity of the labeling problem on G and s is de�ned as �(G; s) = minf�(A;G; s)g,where the minimum is taken over all labeling algorithms A.The time complexity of a labeling algorithm A for a class G of networks is de�ned as�(A;G) = maxf�(A;G; s) j G 2 G; s 2 V (G)g. In particular, �(A; n;m) = �(A;G), whereG is the class of networks with n nodes and m links. The time complexity of the labelingproblem on networks from the class G is de�ned as�(G) = minA f�(A;G)g:In particular, �(n;m) = �(G), where G is the class of networks with n nodes and m links.Our �rst performance measure for a labeling algorithm A is �(A; n;m), and we compareit to �(n;m). Thus we compare the performance of the algorithm on the worst-case networkwith n nodes and m links, to the time complexity of the labeling problem on such networks.We carry analogous comparisons for n-node trees.In contrast, our second type of comparison looks at every network separately. We saythat an algorithm A has optimality ratio R if �(A;G; s)=�(G; s) � R, for all networks G andsources s. A similar notion is de�ned w.r.t. trees. An algorithm A has asymptotically optimaltime if it has constant optimality ratio, i.e., if �(A;G; s) = O(�(G; s)), for any network G andsource s. We seek algorithms with asymptotically optimal time which assign small labels. Wealso show tradeo�s establishing that this is hard to achieve.To illustrate the di�culties of the problem, let us �rst present two naive algorithms forit on a tree. The �rst algorithm is based on a single message (the \token"), that traversesthe graph in depth-�rst fashion, starting at the source s and visiting one vertex at a time,assigning a distinct label to each visited node. (See Figure 1.) While this algorithm assignsthe smallest possible labels (from the range [1; n]), its time requirements are 2n on any n-nodetree, which is about twice the lower bound for the worst case, and more importantly, very farfrom optimal on many trees (e.g., complete binary trees).A second naive algorithm, named 0-1-Split, is best illustrated on a binary tree. Thesource labels itself by the empty sequence ", and every non-leaf node labeled L assigns thelabels L0 and L1 to its left and right children, respectively. This algorithm clearly achievesoptimal time in the all-port model on any tree, and in particular, its worst-case time is n� 1,but on the other hand it generates very long (potentially (n)-bit) labels (see Figure 2).Note that both the DFS based algorithm and the 0-1-Split algorithm terminate in thefollowing sense. For every node v, there is a time tv such that, at time tv, v has a label and v3

1

7

5

643

2

Figure 1: Labeling using a DFS based algorithm.

ε

1

0

1111

1110

111

110

11

10

Figure 2: Labeling using the 0-1-Split algorithm.4

knows that it will not be involved in the algorithm anymore (namely, v will neither send norreceive any more messages within the algorithm). All the algorithms described hereafter inthis paper terminate.1.3 ResultsWhile we have developed a number of algorithms for the labeling problem, our main positiveresults revolve around variants of one main algorithm, named Wake & Label, which seems tofare rather well (in fact, near-optimally) w.r.t. all of our quality and e�ciency measures.For presenting our results in more detail, it is convenient to start with the intermediatemixed model, and then describe the way the results change when we deviate to either of thetwo extreme models.We �rst consider the situation when the network is an unknown tree. The tree is a priorinon-rooted, but for our purposes it can be viewed as rooted at the source s, as the sourceoriginates the labeling process. The main variant of Algorithm Wake & Label operates inthis setting. For n-node trees, it assigns labels of size O(logn) bits and its worst-case timecomplexity is n+1 (while the worst-case lower bound on time is obviously n� 1, e.g., for thepath). Its message and bit complexities are also asymptotically optimal: O(n) messages andO(n logn) bits, respectively.Another signi�cant advantage of this algorithm reveals itself when one considers the ques-tion of time optimality. Let us �rst introduce an important parameter a�ecting the timerequired for label assignment. For any network G, de�ne bb(G; s) to be the worst-case timeof broadcasting a message from a source s to all nodes of G in the mixed model. (The no-tation bb stands for \blind broadcast," as nodes do not know to whom they send messages.)Alternatively, for a tree T rooted at s, bb(T; s) is the maximum sum of node out-degrees ina branch (i.e., root-to-leaf path), taken over all branches of T . A central observation for thepurposes of the current paper is that for any graph G and source s, the time required for labelassignment is lower bounded by bb(G; s), namely, �(G; s) � bb(G; s).Returning to our Algorithm Wake & Label, we note that it runs in asymptotically optimaltime, namely, it uses 3 � bb(T; s) time, which is at most 3 times larger than worst-case optimalfor any given tree.Two other protocols presented for the problem are also fast in the worst case, but havecontrasting qualities and drawbacks. In particular, our second algorithm (Label-Passing)assigns the shortest possible labels to all nodes, i.e., labels 1; : : : ; n, but on the other hand,it has large message and bit complexities: O(n2) messages and O(n2 logn) bits, respectively,and its time is always n (regardless of the tree), hence it is far from being time-optimal. Our5

third algorithm (Fastest) achieves the optimal time �(T; s) for any given tree T and sources, and uses O(n) messages, but its only guarantee on label size is O(pn) bits.To complete the picture, we show two lower bounds for labeling trees. One says that anyalgorithm working in optimal time �(T; s) for any given tree T and source s, requires labelsof size (pn), hence Algorithm Fastest is the best possible in this sense. The second is alower bound on the size of labels produced by protocols whose message complexity is strictlyoptimal, i.e., those using exactly n� 1 messages. We prove that such protocols must producelabels of length (n), on some n-node trees.For general unknown n-node networks, a variant of Wake & Label named Wake & LabelGBassigns labels from the range [1; n] in time 3n. We also present a slightly faster protocol (withworst-case time 2n) but this protocol assigns labels of size up to (n) in some cases. Thisis complemented by observing that there are networks for which labeling in [1; n] cannot bedone faster than in time 2n� o(n). We then present a variant of Algorithm Wake & LabelGBassigning shortest possible labels, and working in asymptotically optimal time for any givennetwork.Finally, we discuss the changes in our results when we consider the problem in the all-portor the one-port models.In the all-port model we give another variant of Algorithm Wake & Label (named Algo-rithm All-port 3-Phase) which assigns optimal labels, and works in asymptotically optimaltime 3 � ecc(G; s), where ecc(G; s) denotes the eccentricity of the source s in the network G,namely, the maximum distance between s and any other node of the network. This algorithmis proved to be strictly optimal for trees: We show that any algorithm assigning labels fromthe range [1; n] to all n-node trees must use time at least 3 � ecc(T; s) � 2 for some tree Tand some source s. On the other hand, any algorithm working in optimal time (namely, timeequal to the eccentricity of the tree w.r.t. the source) must assign labels of size (n). Wealso show another (DFS-based) algorithm which also assigns labels from the range [1; n]. Thisalgorithm works in time 2n on any n-node network, hence it is slightly better in the worstcase (the worst-case lower bound on time is n� 1), but is not asymptotically optimal.In the one-port model the DFS-based algorithm works in asymptotically optimal time 2mfor any m-edge network, as it can be proven that for general networks, m is a lower boundon time. On the other hand, if we restrict attention to trees, another algorithm works inasymptotically optimal time, namely, it uses time at most 3 times larger than worst-caseoptimal, for any given tree. (It should be noted that if the network is known to be a tree,m = n � 1 is not a lower bound on time any more: as in the mixed model, the lower boundbecomes bb(T; s).)Our results are summarized in the table of Figure 3.6

Model Networks Algorithm Time- Time- Label size Messagesworst per graphMixed Trees Label-Passing n n dlog ne O(n2)Wake & Label n+ 1 3 � bb(T; s) O(log n) O(n)3-Phase 3 � bb(T; s) dlog ne O(n)Fastest bb(T; s) O(pn) O(n)Lower bounds n� 1 bb(T; s) dlog ne n� 1Tradeo� (n) ( n� 1Tradeo� bb(T; s) ) (pn)Graphs Wake & LabelGB 3n dlog ne O(m)Wake & LabelGA 4 � bb(G; s) + 1 dlog ne O(m)Lower bounds 2n� o(n) bb(G; s) dlog ne mAll-Port Trees Mixed Alg's same same same sameAll-port 3-Phase 3n 3 � ecc(T; s) � 2 dlog ne O(n)Lower bounds n� 1 ecc(T; s) dlog ne n� 1Tradeo� ecc(T; s) ) (n)Tradeo� 3 � ecc(T; s)� 2 ( dlog neGraphs Mixed Alg's same same same sameDFS+ 2n 2n dlog ne O(m)All-port 3-Phase 3n 3 � ecc(G; s) + 1 dlog ne O(m)Lower bounds n� 1 ecc(G; s) dlog ne mOne-Port Trees DFS 2n� 3 2n� 3 dlog ne 2n� 3Time-Slots 3n 3 � bb(T; s) dlog ne O(n)Lower bounds n� 1 bb(T; s) dlog ne n� 1Graphs DFS 2m 2m dlog ne O(m)Lower bounds m m dlog ne mFigure 3: Summary of results: Algorithms, lower bounds and tradeo�s.7

The main open problem remaining is to establish the precise tradeo� between executiontime of a labeling algorithm and the size of assigned labels, for general networks. In partic-ular, it would be interesting to �nd the minimum worst-case execution time of an algorithmassigning labels of logarithmic size, in any of the considered models. Another interesting openproblem concerns obtaining complexity bounds on the problem of distributing labels in ananonymous network without a leader. This is not always possible (cf. [19]), and could be arather challenging task in cases where it is possible. Finally, observe that our algorithms makeheavy use of the bidirectionality of the communication links. It would be interesting to studythe problem in the directed case.The paper is organized as follows. Sections 2 and 3 deal with the intermediate mixedmodel. In Section 2 we present our results for trees, and in Section 3 we discuss labelinggeneral networks. Section 4 addresses the all-port and one-port models.2 Labeling treesIn this section we study the label assignment problem for trees, in the mixed model. Weconsider an n-node tree T . Our algorithms view the tree as rooted at the source s, and usethe terms parent, child, ancestor, descendant and leaf with respect to this rooted tree. Thetree T and the integer n are unknown to the nodes.A natural �rst question to be considered regarding the tree labeling problem is whetherquality and e�ciency can both be optimized in the worst-case, i.e., whether it is possibleto label any n-node tree in n � 1 or fewer rounds using the minimal possible labels, [1; n].Curiously, it turns out that the answer to this question is positive, as shown next.2.1 Algorithm Label-PassingIn this subsection we present an algorithm which assigns labels from the optimal range [1; n].The algorithm completes the label assignment within n� 1 rounds, and requires time n alto-gether. Its message and bit complexities are O(n2) messages and O(n2 logn) bits, respectively.2.1.1 The algorithmThe main idea of the algorithm is that each node v receives from its parent a stream of labels,one at a time, and passes them to its children, so as to �ll the entire subtree rooted at v. Amore detailed description now follows. 8

The source distributes the labels 1; 2; : : : to its children in Round-Robin (R-R) fashion.A leaf receiving a label responds immediately with a \full" message to its parent. If a childresponds with a \full" message, then the source skips it in the following rounds. Once a singlenon-full child remains, with the next unassigned label being `, the source assigns the label `to itself, and passes the entire range of remaining labels, [` + 1;1), to the remaining child.Each intermediate node v acts very similarly to the source. It gets from its parent a streamof (increasing) labels, possibly followed by �nal message containing a range of labels [`;1).While v receives a stream of labels, it simply distributes the arriving labels among itsnon-full children in R-R fashion. If during this process all its children become full, it waits toget one last label for itself, and then informs its parent that it is full.If at some point during this process v gets a range [`;1) from its parent, then it essentiallystarts behaving as the source. More speci�cally, it continues as follows. As long as it has twoor more non-full children, it continues to distribute labels from the range, one by one, amongits non-full children in R-R fashion. Once a single non-full child remains, with the nextunassigned label in the range being `0, v assigns the label `0 to itself, and passes the entirerange of remaining labels, [`0 + 1;1), to the remaining child.2.1.2 AnalysisIt is obvious that the algorithm Label-Passing terminates, so we concentrate on analyzingits performances.Fact 2.1 For every node v, at least two rounds elapse between the arrival of every two con-secutive labels in its incoming stream.(Note that this claim does not apply to the �nal range message, if it exists; this message mayimmediately follow the last label in the stream.)We refer to a node v whose input of labels consisted of a stream only as an SO-node, andto a node v whose input of labels consisted of a stream and a �nal range as an SR-node.For a node v, let tv denote the round when v got the last message from its parent. Thismessage can be either a label `v or a range [`v;1). Let Tv denote the subtree rooted at v,and let nv denote the number of nodes in Tv. Let t̂v denote the round when all the nodes inTv are labeled.Lemma 2.1 For an SO-node v, t̂v = tv. Moreover, it receives exactly nv labels in its incomingstream. 9

Proof. By induction on the tree structure, from the leaves up. For an SO-leaf, the fact thatt̂v = tv is trivial. Also, note that by Fact 2.1 the incoming labels arrive at a rate of at mostone label per two rounds, and therefore v has enough time to send a \full" message to itsparent u before u attempts to send it another label.Now consider an intermediate (non-leaf) SO-node, and suppose that the claims of thelemma hold for each of its children w1; : : : ; wd. The stream of labels reaching v is split intosubstreams directed at the children, hence all children end up being SO-nodes as well. Bythe inductive hypothesis, the stream directed at wi consists of exactly nwi labels. Moreover,Pdi=1 nwi = nv � 1, so v learns that all its children are full just before receiving the nvth labelin round tv, which it can subsequently assign to itself. Again, v sends a \full" message to itsparent u in round tv + 1, thus preventing u from sending it another label. 2Observe that the SR-nodes form a chain in the tree, starting at the source s and going down(but possibly not all the way to a leaf, as illustrated by the execution depicted in Figure 4).Moreover, whenever a node v becomes the current SR-node, all nodes outside Tv are alreadyassigned labels. Note also that by the previous lemma, no labels were wasted in subtrees Turooted at SO-nodes u. In addition, a single label was left for each ancestor SR-node of v. Thisimplies the following.1 3

F

1

2 3v v vF

F

1

2

v

4

1

2

R

Round 4Round 3Round 2Round 1

Figure 4: An execution of Algorithm Label-Passing. SR-nodes are marked by bold circles; bothleaves are SO-nodes. The downward message \R" stands for the range [5;1), and the upwardmessage \F" stands for \Full." The numbers on the nodes indicate the assigned labels.Lemma 2.2 Whenever an SR-node v receives the �nal range message [`v;1) following thearrival of a stream of k labels, the number of labels still missing in Tv is exactly nv � k =n� `v + 1.Lemma 2.3 For an SR-node v, t̂v = tv + n� `v.10

Proof. By induction on the tree structure, from the lowest SR-node up. For the lowestSR-node, there are two possibilities. The �rst possibility is that the stream preceding therange message was of length k = nv � 1. Then by Lemma 2.2, the arriving range has `v = n,and the claim follows. The second possibility is that the stream preceding the range messagecontained k = nv labels, the last of which has arrived in round t0. (This is what happens, forinstance, at node v in the execution depicted in Figure 4.) Then the label assignment processin Tv has in fact completed in round t̂v = t0. Since v has responded on the kth label with a\full" message immediately in the next round t0 + 1, the range message must have been sentin round tv = t0+1 (or v's parent would not have sent it at all). Hence t̂v = tv�1. By Lemma2.2, the arriving range has `v = n+ 1, and the claim follows.Now consider an intermediate (non-lowest) SR-node, with children w1; : : : ; wd. Let usseparate v's activity during the process into two stages:(a) the period while v has at least two non-full children, and(b) the period when v has only one non-full child.Let tbv denote the time in which the transition from stage (a) to stage (b) took place, ormore precisely, the �rst round of stage (b).During stage (a), v performs an R-R among its children, and by an argument similar tothat of Lemma 2.1, those children wi that become full during this stage do so at the righttime, t̂wi = twi, and inform v in time for it to preclude them from the R-R process.Let us now consider stage (b), in which a single non-full child w remains. The transitionfrom stage (a) to stage (b) can happen either while v is still receiving a stream (i.e., tbv < tv),or after v has already received a range [`v;1) (i.e., tbv � tv).In the former case, all labels arriving at v in the stream are directly passed to w, and whenthe range [`v;1) arrives at v in round tv, it takes the label `v to itself, and passes the range[`w;1) = [`v + 1;1) to w. As w gets this range in round tw = tv + 1, and since w is also anSR-node, we have by the inductive hypothesist̂w = tw + n� `w = (tv + 1) + n� (`v + 1) = tv + n� `v :In the latter case (tbv � tv), let p = tbv� tv. Then after v has received the range message [`v;1)in round tv, it performed p R-R steps until w has remained the only non-full node, and thenpassed the remaining range [`w;1) = [`v + p + 1;1) to w, after keeping the label `v + p toitself. This range has arrived at w in round tw = tv + p+ 1. By the inductive hypothesis,t̂w = tw + n� `w = (tv + p+ 1) + n� (`v + p+ 1) = tv + n� `v : 211

Applying the lemma to the source, interpreted as an SR-node with ts = 0 and `s = 1, andusing Lemma 2.1 for the SO-nodes, we get the following result.Lemma 2.4 After n� 1 rounds, all nodes are labeled.Moreover, we note that the execution time of Algorithm Label-Passing is at most n. Tosee this, let t be the time at which the label assignment is completed, t � n � 1. Let v be anode that has received its label at time t. If v got a range of labels, then v stops activity attime t. On the other hand, if v got a single label, then v sends a \full" message at time t+1,and stops its activity.Note that it is possible that (at most) two more messages can still be sent in round n.This may occur in the following scenario. Suppose that node v holds a range of labels [`;1)which it uses to distribute labels among its children. Suppose that at the end of round n� 3,only two non-full children w0 and w remain, with each missing a single label (for themselves).However, this fact is of course not known to v. In round n� 2, v sends the label n� 2 to w0.In round n� 1, w0 replies with a \full" message to v, and at the same time, v sends the labeln � 1 to w. At the end of round n� 1, as v gets the \full" message from w0, it realizes thatnow w is its only remaining non-full child, and therefore it can assign the smallest free label,n, to itself. However, v does not know at this stage that w is already full. Hence in round n,two more messages will be sent, namely, a \full" message from w to v, and a range message[n+ 1;1) from v to w.As each label travels through at most n � 1 edges, the total number of messages sentthroughout the process is O(n2). In summary, we haveTheorem 2.1 Given an n-node tree and a source s, Algorithm Label-Passing assigns dis-tinct labels from the range [1; n] to all the nodes. The label assignment completes in n � 1rounds. The time, message and bit complexities of the algorithm are n rounds, O(n2) messagesand O(n2 logn) bits, respectively.2.2 Algorithm Wake & LabelOur main algorithm, Algorithm Wake & Label, is slightly inferior to Algorithm Label-Passingwith respect to worst-case time complexity and label size. Speci�cally, it assigns labels ofasymptotically optimal length O(logn), and works in worst-case time at most n + 1. Onthe positive side, its message and bit complexities are far better, namely, O(n) messages andO(n logn) bits, respectively. But most importantly, Algorithm Wake & Label works in asymp-totically optimal time. This overcomes the main disadvantage of Algorithm Label-Passing,which is that its execution time is always at least n� 1, regardless of the tree structure.12

2.2.1 Three simpli�ed variantsThe idea of Algorithm Wake & Label signi�cantly di�ers from that of Algorithm Label-Passing.As the algorithm and its analysis are rather complex, it is convenient to �rst presenta succession of three simpli�ed variants of the algorithm, of increasing complexity. Thesevariants are slightly weaker, but somewhat more intuitive.All variants of Algorithm Wake & Label operate in three phases and use three types ofmessages: wakeup, count and allocation. Moreover, in the �rst three variants we describe, the�rst two phases are similar.In the �rst (wakeup) phase, the source wakes up all the nodes by broadcasting a wakeupmessage. Wakeup messages go top-down, from the source towards the leaves. I.e., the sourcesends wakeup messages to its children (in arbitrary order), and every node that receives awakeup message sends wakeup messages to all of its children in consecutive time units.Let Tv denote the subtree of the tree T , rooted at v. The second (counting) phase is startedby the leaves of the tree T , and provides every node v with a count of the number of nodesin its subtree Tv. This is done in a bottom-up convergecast fashion, using count messages ofsize at most logn which travel bottom-up in T . Speci�cally, the process operates as follows.Immediately after being woken up by a wakeup message, each leaf of the tree sends up a countmessage \my subtree has size 1" to its parent. A non-leaf node v that got count messages \mysubtree has size xi" from all of its children vi, i = 1; : : : ; r, sends a count message containingthe sum of its children's count plus one, \my subtree has size x1 + � � �+ xr +1," to its parentin the next time unit. Note that once all leaves in a subtree Tv have started the counting, thetime to complete the count on Tv is at most ecc(Tv; v) � nv� 1, where nv denotes the numberof nodes in Tv.The di�erences between the �rst three variants of Algorithm Wake & Label are manifestedin the third (allocation) phase, whose task is to distribute the labels via allocation messages.Algorithm Wake & LabelAIn our �rst variant, named Algorithm Wake & LabelA, the allocation phase is straightforward.It is started by the source immediately upon receiving count messages from all its children. Thesource assigns itself label 1, and sends to each child a disjoint integer interval correspondingto the size of the subtree rooted at this child, so that the beginning of a given interval is thesuccessor of the end of the preceding one; the beginning of the interval sent to the �rst childis 2. Likewise, any node that got interval [a; b] assigns itself label a and sends to each child adisjoint integer interval corresponding to the size of the subtree rooted at this child, startingat a + 1 for the �rst child, similarly as above.13

An obvious lower bound on the labeling time for any T and s is bb(T; s). (Recall that, fora tree T rooted at s, bb(T; s) has an easy characterization: it is the maximum sum of nodeout-degrees, taken over all branches of T .) Hence we have the following.Theorem 2.2 Given an n-node tree T and a source s, Algorithm Wake & LabelA assignsdistinct labels from the range [1; n] to all the nodes. Its time complexity is at most 3bb(T; s),hence it is asymptotically optimal. Its message and bit complexities are O(n) messages andO(n logn) bits, respectively.Proof. It is obvious that the algorithm Wake & LabelA terminates, with distinct labels fromthe range [1; n]. After time bb(T; s) all leaves have got wakeup messages. After ecc(T; s)additional rounds, the source gets count messages from all of its children. Sending allocationmessages, and thus completing the execution of the algorithm, takes at most bb(T; s) additionalrounds. Hence the time is at most 2bb(T; s) + ecc(T; s) � 3bb(T; s). Since at most 3 messagesof size O(logn) bits travel along each link of the tree, the message and bit complexities are asclaimed. 2Hence this algorithm assigns labels from the optimal range [1; n], and has asymptoticallyoptimal time, message and bit complexities, but its worst-case time complexity is three timesgreater than the optimal, namely, 3(n � 1). This worst case is realized on the n-node pathwith the source residing at one of the endpoints. Hence our e�orts focus on reducing theworst-case time complexity to n+ 1 while preserving the above qualities as much as possible.Algorithm Wake & LabelBThe second variant, named Wake & LabelB, is based on observing that the source does notnecessarily need to wait until receiving a count from all of its children. Rather, it can startthe label distribution once it knows the counts of all its children but one. In this case, itassigns consecutive blocks of labels to the children for which it knows the count, and thenpasses the remaining in�nite (semi-open) block of labels to the remaining child. This child, inturn, behaves the same. It can be shown that this idea is su�cient for reducing the worst-casetime complexity of the algorithm to 3n=2. The worst example is, e.g., the n-node path wherethe source resides at the middle node.Algorithm Wake & LabelCThe third variant, Wake & LabelC , assigns labels of length O(logn log d) bits, where d is themaximum degree of the tree, and has time complexity n+d and bit complexity O(n logn log d)14

bits. The labels of all nodes are of the form (p; y), where p is a sequence of integers smallerthan d, called the pre�x, and y is a natural number smaller than n, called the value.The �rst two phases of Algorithm Wake & LabelC are as described earlier. However, the�nal allocation phase is more elaborate, and the allocation messages it uses for assigninglabels to nodes have more complex structure. These allocation messages travel top-down andtheir size is O(logn log d) bits. In order to describe them, we introduce the crucial notionsof initial and �nal capital at node v. These are natural numbers denoted by c0(v) and c00(v),respectively. Initially c0(s) = 1. For v 6= s, c0(v) will be set to c00(u), where u is v's parent(c00(v) is set by the protocol as the execution develops). Intuitively, capital is de�ned in sucha way that node v can wait c0(v) rounds between sending the last wakeup message and the�rst allocation message, without violating the overall deadline for algorithm completion in thesubtree rooted at v.After sending all wakeup messages, node v starts a waiting period which continues (at least)until it receives an allocation message from its parent u. The allocationmessage contains c00(u),and v sets c0(v) c00(u). If v received the allocation message while it was sending wakeupmessages, then v will wait c0(v) rounds after it will have �nished sending wakeup messages. If,on the other hand, v received the allocation message after it has already �nished sending itswakeup messages (say, t0 rounds later), then v acts as follows. If c0(v) > t0, then v continuesits waiting period for c0(v)� t0 additional rounds. Otherwise, the waiting period is over. Thesource behaves as if receiving \from its parent" an allocation message with capital 1 at time0, that is the source will wait one round after having sent all its wakeup messages.At the end of this waiting period, there are two possibilities:1. v got count messages from all of its children except possibly one,2. v did not get count messages from at least two children.The �rst situation is called normal, the second is called special. We �rst describe theactions for each situation when v = s is the source. Note that s has waited c0(s) = 1 timeunit after having sent the last wakeup message. It now assigns itself the label ("; 0), where "denotes the empty sequence.In the normal situation, c00(s) 1 (= c0(s)) and s sends allocation messages to its children,in consecutive time units, in the same order in which it sent wakeup messages. Children fromwhich s got a count message get a closed allocation message, and the (at most one) child fromwhich no count message arrived gets an open allocation message. Suppose, without loss ofgenerality, that vi, i = 1; : : : ; r, are those children of s from which count messages arrivedsaying that the subtree rooted at vi has size xi, and no count message arrived from child vr+1.Then the closed messages sent to vi, i = 1; : : : ; r, consist of the pre�x " (the empty sequence)15

and of intervals Ii, i = 1; : : : ; r, of natural numbers, such that the left end of I1 is 1, the leftend of Ii+1 is the successor of the right end of Ii, and jIij = xi. The open message sent tovr+1 consists of the �nal capital c00(s), the pre�x " and of the half-line [t;1), where t is thesuccessor of the right end of Ir. Integers from these intervals will be used to construct labelsof nodes in respective subtrees. (Intervals are coded by pairs of their ends and the half-line[t;1) is coded by t.)In the special situation, c00(s) 2 (= c0(s) + dc0(s)=2e), and the source sends specialallocation messages to its children, in the same order in which it sent wakeup messages. Aspecial message sent to child vi consists of a marker special, of the �nal capital c00(s) and ofthe pre�x which is the one-term sequence (i).Let v 6= s and let u be v's parent. At the end of the waiting period, v acts in the followingway. There are three possible cases.� The received allocation message was closed, consisting of the pre�x p and the interval[a; b]. In this case, node v assigns itself the label (p; a) and sends to its children vi,i = 1; : : : ; r, a closed allocation message consisting of the pre�x p and of intervals Ii,i = 1; : : : ; r of natural numbers, such that the left end of I1 is a+ 1, the left end of Ii+1is the successor of the right end of Ii, and jIij = xi, where xi is the size of the subtreerooted at vi (reported to v by a count message).� The received allocation message was open, consisting of the �nal capital c00(u), pre�x p,and half-line [t;1). In this case, node v assigns itself the label (p; t). It sets c0(v) c00(u). At the end of the waiting period there are two possibilities, as described abovefor the source s: normal and special. In the normal situation, c00(v) c0(v), and nodev acts as did the source, except that the pre�x sent is p rather than " (the emptysequence), and the left end of interval I1 is t+ 1 rather than 1. In the special situation,c00(v) c0(v) + dc0(v)=2e, and v sends special allocation messages to its children, in thesame order in which it sent wakeup messages. (As will be clari�ed later, this formulais motivated by the fact that in the special situation, a child w of v has at least c0(v)nodes in its subtree Tw.) A special message sent to child vi consists of a marker special,of the �nal capital c00(v) and of the pre�x p0 which is the concatenation of the sequencep and the one-term sequence (i).� The obtained allocation message was special, consisting of a marker special, �nal capitalc00(u), and pre�x p. In this case node v assigns itself the label (p; 0) and acts as in theprevious case, with t = 0.This completes the description of Algorithm Wake & LabelC , except for handling \late"count messages. A node v may get count messages from its children after it started send-16

ing them allocation messages. In this case incoming count messages are ignored and vdoes not send any count message to its parent. This ensures, in particular, that AlgorithmWake & LabelC terminates.The proof of correctness and the performance analysis of Algorithm Wake & LabelC relyon the following lemmas.Lemma 2.5 Algorithm Wake & LabelC assigns distinct labels to all nodes.Proof. Let u and v be distinct nodes. We will show that they get distinct labels. If at leastone of them is the source, the statement is obvious. Otherwise, u and v receive allocationmessages. Let w be the least common ancestor of u and v, such that the paths wv and wuare disjoint. (In particular w can be one of u or v). If some node on the path wv has sent aspecial allocation message but all the nodes on the path wu have not, then the labels assignedto u and v have di�erent pre�xes. If some node on wv and some node on wu have sentspecial allocation messages, then necessarily w has also sent a special allocation message, andagain the labels assigned to u and v have di�erent pre�xes. In the remaining case, the labelsassigned to u and v have the same pre�x but di�erent values. 2For any node v, de�ne d̂(v) as the maximum degree of all nodes on the path between vand the source (including both ends).Lemma 2.6 For any node v and any of its children w, the delay between the time when vsends a wakeup message to w and the time when it sends an allocation message to w, is atmost c0(v) + d̂(v).Proof. The lemma is true for the source s, since s waits one time unit before sending theallocation message. Suppose it is true for a node u and its child v. We will prove it for thenode v and any of its children w. Let t be the time unit when u sends a wakeup message to v.By the hypothesis, u sends an allocation message to v on or before time unit t+ c0(u) + d̂(u).Let w be the ith child of v in the order of sending wakeup and allocation messages. It followsthat v sends a wakeup message to w in time unit t + i and v sends an allocation message tow in time unit at most maxft+ c0(u) + d̂(u)+ i; t+ d(v)+ c0(v) + ig, where d(v) is the degreeof v. There are two cases:1. c0(u) + d̂(u) � d(v) + c0(v).Then v sends an allocation message to w by the time unit t + c0(u) + d̂(u) + i. Sincec0(u) � c0(v) and d̂(u) � d̂(v), this is no later than t + c0(v) + d̂(v) + i and the conclusionfollows. 17

2. c0(u) + d̂(u) < d(v) + c0(v).Then v sends an allocation message to w by the time unit t + d(v) + c0(v) + i. Sinced(v) � d̂(v), we get the conclusion. 2For any node v, a node w is called foreign to v, if it is neither v, nor an ancestor of v, nora child of an ancestor of v, nor a descendant of v.Lemma 2.7 For any node v, there exist at least c0(v)� 1 nodes foreign to v.Proof. The lemma is true when v is the source since c0(s) = 1. Suppose it is true for a nodev. We prove it for a child w of v. If c0(v) = c0(w), the conclusion follows from the fact thatany node foreign to v is foreign to w. Hence suppose that c0(w) = c00(v) = c0(v) + dc0(v)=2e,i.e., that v was in a special situation. Let u be a child of v di�erent from w, from which v didnot get a count message by the end of the waiting period. This implies that the size of thesubtree rooted at u is larger than dc0(v)=2e, i.e., u has at least dc0(v)=2e descendants. All ofthem are foreign to w but not foreign to v. Since there are at least c0(v)� 1 nodes foreign tov, and c0(w) = c0(v) + dc0(v)=2e, it follows that there exist at least c0(w)� 1 nodes foreign tow. 2Lemma 2.8 The execution time of Algorithm Wake & LabelC , working in an n-node tree ofmaximum degree d, is at most n+ d.Proof. It su�ces to prove that the last allocation message is sent by time unit n+d. Considerany node w and its parent v. Let p be the number of nodes foreign to v. Hence w gets awakeup message by time unit at most n� p� 1, because nodes foreign to v do not contributeto the delay of the wakeup message. In view of Lemma 2.6, it gets an allocation message bythe time unit n� p� 1 + c0(v) + d̂(v). In view of Lemma 2.7 we getn� p� 1 + c0(v) + d̂(v) � n� c0(v) + 1� 1 + c0(v) + d̂(v) = n+ d̂(v) � n+ d: 2Lemma 2.9 All labels given to nodes by Algorithm Wake & LabelC and all messages sentduring its execution in an n-node tree of maximum degree d, are of size O(logn log d) bits.Proof. It is enough to prove that for every label assigned, its value is at most n and its pre�xhas length at most O(logn) bits. The �rst statement is obvious, as values are consecutive18

integers starting from 0. In order to prove the second statement it su�ces to show that, for anybranch of the tree, the number of nodes in this branch which are in a special situation duringthe execution of the algorithm, is O(logn). Take any branch of the tree and let v1; : : : ; vk,be nodes in a special situation in it, listed top-down. Thus c0(vi+1) � 32c0(vi) and c0(v1) = 1.Hence c0(vk) � (32)k�1. By Lemma 2.7, the number of nodes foreign to vk is at least (32)k�1. Itis also at most n� 1. Thus k is O(logn). 2Note that Algorithm Wake & LabelC is no longer asymptotically optimal. However, thefollowing trivial modi�cation of Algorithm Wake & LabelC keeps all its worst-case qualities,while achieving the same optimality ratio as Algorithms Wake & LabelA and Wake & LabelB.Algorithm Wake & Label+C behaves like Wake & LabelC , except in the situation when anode got count messages from all of its children. Then, even if the waiting period is not yetover, the node starts sending allocation messages, as in Wake & LabelA. All previous featuresare preserved. On the other hand, the same argument as for Algorithm Wake & LabelA showsthat Algorithm Wake & Label+C works in time at most 3bb(T; s), for any tree T and source s.Lemma 2.10 Algorithm Wake & Label+C working in an n-node tree of maximum degree d,assigns distinct labels of size O(logn log d) bits to all nodes of the tree. Its worst-case executiontime in such a tree is minfn + d; 3bb(T; s)g, and its message and bit complexities are O(n)messages and O(n logn log d) bits, respectively.2.2.2 Algorithm Wake & LabelThe improvements introduced to Algorithm Wake & Label aim at decreasing time from n+dto n+ 1 and label sizes from O(logn log d) to O(logn) bits. The �rst is achieved by carryingout the processes of waking up and of labeling partly concurrently. The second is achievedby introducing another waiting period for each node, during which the number of childrenthat have not reported is reduced to at most 3. This permits us to use only integers 0, 1, or2, instead of 0; 1; : : : ; d when forming pre�xes of labels. As in the simpli�ed algorithms, thelabels of all nodes are of the form (p; y), except that now, the pre�x p is a sequence whoseterms are integers 0, 1, or 2.We now proceed with the detailed description of the protocol. Algorithm Wake & Labelstill uses the same three types of phases and messages, namely, wakeup, count and allocation.However, only the second phase remains the same as in the earlier variants, while the �rstand third phases are modi�ed. In particular, wakeup messages may now be used also forimmediately assigning labels to some of the nodes. Consequently, wakeup messages nowconsist of two parts: the content and the timer. They are divided into two categories: small,i.e., those whose content consists of one bit, and large, i.e., all others.19

Let Dv denote the sum of the number of children of u, over all ancestors u of v. The timerof a wakeup message M sent to v is an integer indicating how many rounds remain betweengetting the message M and round Dv of the process. Finally, an allocation message sent tonode v is used to transmit the information necessary for forming the labels of descendants ofv. The size of every message is O(logn) bits. Every node gets at most two wakeup messagesfrom its parent (one small and one large), at most one count message from each child, andat most one allocation message from its parent (more precisely, non-leaves get one allocationmessage and leaves do not get any allocation message).We �rst describe wakeup messages. The source sends large wakeup messages to its consec-utive children (in arbitrary order). The content of the wakeup message sent to the ith childconsists of the pre�x " (the empty sequence) and of the integer i. Every node v that receivesa wakeup message waits until round Dv and, starting from the next round, sends wakeupmessages to all of its children in consecutive rounds. (The reason for waiting with the wakeupmessage until round Dv is technical: this delay will be used in the proof of Lemma 2.14.) Wewill later describe the content of these messages. Their main purpose is to wake up all nodes.Count messages behave as in the previous variants of the algorithm.In order to describe allocation messages, and wakeup messages sent by nodes other thanthe source, we again use the notions of the initial and �nal capital at node v, and introducethe notion of the intermediate capital at node v. These are natural numbers denoted byc1(v), c2(v) and c3(v), for initial, intermediate, and �nal capital, respectively, where initiallyc1(s) = 1.After sending all wakeup messages, the source s starts the �rst waiting period lastingc1(s) = 1 rounds. At the end of this period the source knows which of its children are leaves,as it got count messages from all of them. Suppose that s did not get count messages from kof its children. We distinguish between three possible situations:1. Normal situation: k � 1,2. Special situation: k 2 f2; 3g,3. Suspended situation: k � 4.The source s assigns itself the label ("; 0).In the normal situation, c2(s) c1(s), c3(s) c2(s), and s sends allocation messages toall its children that are not leaves, in consecutive time units, in the same order in which itsent wakeup messages. As in the simpli�ed Algorithm Wake & LabelC , children from which sgot a count message get a closed allocation message, and the (at most one) child from which20

no count message arrived gets an open allocation message. These messages are de�ned as inthe corresponding (normal) situation of Algorithm Wake & LabelC .In the special situation, c2(s) c1(s), c3(s) c2(s) + dc2(s)=2e = 2. Suppose, withoutloss of generality, that vi, i = 1; : : : ; r, are those children of s that are not leaves and fromwhich count messages arrived by the end of the �rst waiting period, and u0, u1 and possiblyu2 are children from which count messages have not arrived. The source sends allocationmessages in the same order in which it sent wakeup messages. Nodes vi, i = 1; : : : ; r, get thesame closed allocation messages, as in the normal situation. Nodes u0, u1 and u2 get specialallocation messages. The special message sent to node uj consists of a marker special, of the�nal capital c3(s) and of the pre�x which is the one-term sequence (j).In the suspended situation, s starts the second waiting period: it waits until it gets countmessages from all of its remaining children except at most 3. Let c be the duration of thesecond waiting period. Then c2(s) c1(s) + c. If at the end of the second waiting periods did not get count messages from at most 1 child then c3(s) c2(s) and s acts as in thenormal situation. If at the end of the second waiting period s did not get count messagesfrom 2 or 3 children then c3(s) c2(s) + dc2(s)=2e and s acts as in the special situation.This �nishes the description of the actions of the source. We now describe the actions of anode v di�erent from the source. These actions are simple when v is a leaf. In this case, if thecontent of the wakeup message consisted of a pre�x p and an integer k (i.e., the message waslarge), v assigns itself the label (p; k) (after sending the usual count message to its parent).If the content of the wakeup message consisted of a single bit (i.e., the message was small),v sends the count message, waits for a large wakeup message containing a pre�x p and aninteger k, and assigns itself the label (p; k). In the rest of the description we assume that v isnot a leaf.After being woken up by a (small or large) wakeup message, v reads from the timer howmany rounds it needs to wait, and starts sending wakeup messages to its children in roundDv + 1. These are small messages, as long as v has not gotten an allocation message from itsparent. Children to whom v sends small wakeup messages are called old children; all otherchildren of v are called young children. At some point v gets an allocation message from itsparent, consisting of a pre�x p and an integer k. Then v assigns itself the label (p; k).We now describe the scheduling of messages sent by v to its children, and later de�ne thecontent of these messages. There are two cases.1. The node v gets an allocation message from its parent u before it has sent wakeupmessages to all of its children.After receiving the allocation message, v starts sending large wakeup messages to its youngchildren. When all children get wakeup messages, v sets c1(v) c3(u) and starts the �rst21

waiting period lasting c1(v) rounds. If at the end of it v is in a suspended situation (it hasnot received count messages from more than 3 children), it starts the second waiting periodlasting until it gets count messages from all of its children, except at most 3. During thewaiting period(s) v is not idle but sends second wakeup messages to its old children. Thesemessages are large. At the end of waiting there may be still some old children that have notyet gotten large wakeup messages (call these children �nal) but v postpones sending thesemessages. Instead, in consecutive rounds, it sends allocation messages to all its children thatare not leaves. If such a child is among the �nal children of v, the appropriate large wakeupmessage is appended to the allocation message. After sending these messages to all childrenthat are not leaves, v completes its task by sending appropriate large wakeup messages to its�nal children that are leaves.2. The node v gets an allocation message from its parent after it has sent wakeup messagesto all of its children.After sending small wakeup messages to all of its children, v starts the �rst waiting periodlasting c1(v) rounds (note that c1(v) = c3(u) was included in the allocation message receivedby v). At the end of the waiting period, if v is in a suspended situation then it continues withthe second waiting period, as above. The node v is idle till the later of the following events:the end of one or both waiting periods, and obtaining the allocation message. Then v sendsmessages combining an allocation message and a large wakeup message to all its children thatare not leaves. Finally, v sends large wakeup messages to all its children that are leaves.We now describe the content of the messages sent by v. It depends on the allocationmessage obtained by it. There are three possible cases.� The obtained allocation message is closed, consisting of the pre�x p and of the interval[a; b].The large wakeup messages sent by v to its children vi, i = 1; : : : ; r, contain the pre�xp and the consecutive integers a+ i� 1. The allocation messages are closed and consistof the pre�x p and of intervals Ii, i = 1; : : : ; r of natural numbers, such that the left endof I1 is a+ r, the left end of Ii+1 is the successor of the right end of Ii, and jIij = xi� 1,where xi is the size of the subtree rooted at vi (reported to v by a count message).� The obtained allocation message is open, consisting of the �nal capital c3(u), of thepre�x p, and of the range [t;1).In this case, v sets c1(v) c3(u). The large wakeup message sent to the ith childconsists of the pre�x p and of the integer t+ i� 1.At the end of the �rst waiting period there are three possibilities, as described abovefor the source: normal, special and suspended.22

In the normal situation, c2(v) c1(v), c3(v) c2(v), and the allocation messages sentby v are similar as in the case of the source, with the following exceptions: the pre�xsent is p rather than ", and the left end of interval I1 is t+ z, where z is the number ofchildren of v.In the special situation, c2(v) c1(v), c3(v) c2(v) + dc2(v)=2e, and the allocationmessages sent by v are similar as in the case of the source, with the following exceptions:1. in closed allocation messages the pre�x sent is p rather than ", and the left end ofinterval I1 is t+ z, where z is the number of children of v;2. the special message sent to child ui consists of a marker special, of the �nal capitalc3(v) and of the pre�x p0 which is the concatenation of the sequence p and theone-term sequence (i).In the suspended situation v waits until the number of children that have not sent countmessages is at most 3 and then sends messages as described above.� The obtained allocation message was special, consisting of a marker special, of the �nalcapital c3(u), and of the pre�x p.In this case node v acts as after obtaining an open allocation message, with t = 0.This completes the description of Algorithm Wake & Label, except for handling \late"count messages. A node may get count messages from its children after it got an allocationmessage from its parent. In this case the node does not send any count message to its parent.As for Algorithm Wake & LabelC , this ensures the termination of Algorithm Wake & Label.Before proving the correctness of the algorithm and analyzing its performance, we makethe following remarks whose aim is to clarify the purpose of the main tools used in it.1. The reason for sending two categories of wakeup messages is the following. The wakeupmessage must be sent su�ciently early to guarantee the speed of the process. However, beforegetting the allocation message, a node v does not know what labels to give to its children.Hence it starts with wakeup messages whose content is one bit, planning to revisit them later.Sending such messages cannot last too long because if the degree of v is large compared to thesize of the tree, there would be no time to visit all children again. In particular, the sourcestarts sending large wakeup messages immediately because, in the case when all of its childrenare leaves (the tree is a star), after sending messages to all children there are only two roundsleft till deadline n + 1.2. The �rst waiting period and the related notion of capital, are the crucial concepts ofthe algorithm. If a node v does not obtain a count message from a child u during this period,it knows a lower bound on the size of the subtree rooted at u. If there are two or more such23

children, v can a�ord to increase the length of labels by 1 because it can be proved (Lemma2.16) that any sequence of such situations (which we called special) is at most logarithmic.This is due to the fact that the length of the waiting period (controlled by the capital) growsexponentially with consecutive special situations.3. The aim of the second waiting period is to reduce the number k of children fromwhich a count message has not arrived during the �rst waiting period, to at most 3. Withoutthis device, all these children should get di�erent pre�x extensions. In each special situationthe extension would have to be of length dlog ke bits, which could yield labels of length�(logn log d), where d is the maximum degree. At any point, if there are still many childrenwhich have not sent count messages, a node can safely wait: every round of silence indicatesthe existence of at least one additional descendant and hence increases the overall deadlineby 1.2.2.3 Analysis of Algorithm Wake & LabelThe proof of correctness and the performance analysis of Algorithm Wake & Label rely onthe following lemmas. The �rst lemma is similar to Lemma 2.5.Lemma 2.11 Algorithm Wake & Label assigns distinct labels to all nodes.Lemma 2.12 For any node v, there exist at least c1(v)� 1 nodes foreign to v.Proof. The lemma is true when v is the source since c1(s) = 1. Suppose it is true for a nodev. We prove it for a child w of v. By de�nition, c1(w) = c3(v). There are three possible cases.Case 1. At the end of the �rst waiting period v was in a normal situation.In this case c3(v) = c2(v) = c1(v) and the conclusion follows from the fact that any nodeforeign to v is foreign to w.Case 2. At the end of the �rst waiting period v was in a special situation.In this case c2(v) = c1(v) and c3(v) = c1(v) + dc1(v)=2e. Let u be a child of v di�erentfrom w, from which v did not get a count message by the end of the �rst waiting period.The delay between waking up u and the end of the �rst waiting period is at least c1(v). Thisimplies that the size of the subtree rooted at u is larger than dc1(v)=2e, i.e., u has at leastdc1(v)=2e descendants. All of them are foreign to w but not foreign to v. Since there are atleast c1(v)� 1 nodes foreign to v, and c1(w) = c1(v) + dc1(v)=2e, it follows that there exist atleast c1(w)� 1 nodes foreign to w.Case 3. At the end of the �rst waiting period v was in a suspended situation.24

Let c be the duration of the second waiting period. Thus c2(v) = c1(v)+ c. Let u1, u2 andu3 be three children of v di�erent from w from which v did not get a count message until theend of the second waiting period. Consider two subcases:3.1. At the end of the second waiting period v did not receive a count message from atmost 1 child.Then c3(v) = c2(v). The second waiting period lasted c rounds and during this period v didnot get a count message from u1, u2 and u3. This implies that the size of the subtrees rootedat u1 and at u2 is larger than dc=2e, i.e., each of u1 and u2 has at least dc=2e descendants. Thetotal number of these descendants is at least c. All of them are foreign to w but not foreignto v. Since there are at least c1(v)� 1 nodes foreign to v and c1(w) = c1(v)+ c, it follows thatthere exist at least c1(w)� 1 nodes foreign to w.3.2. At the end of the second waiting period v did not receive a count message from 2 or3 children.Then c3(v) = c2(v)+ dc2(v)=2e. Similarly as above we argue that all the descendants of u1and u2 are foreign to w but not foreign to v, and there are at least c of them. The total timeof both waiting periods was c1(v)+ c = c2(v). During this time v did not get a count messagefrom u3. This implies that the size of the subtree rooted at u3 is larger than dc2(v)=2e, i.e.,u has at least dc2(v)=2e descendants. All of them are foreign to w but not foreign to v, andare di�erent from descendants of u1 and of u2. Hence there are at least c + dc2(v)=2e nodeswhich are foreign to w but not foreign to v. Since there are at least c1(v) � 1 nodes foreignto v, and c1(w) = c1(v) + c + dc2(v)=2e, it follows that there exist at least c1(w) � 1 nodesforeign to w. 2For any node v, we de�ne the following parameters:dv is the number of children of v;�v is the number of nodes di�erent from v and from all descendants of v;fv is the number of nodes foreign to v.Recall that the parameter Dv, de�ned earlier, is the sum of du, over all ancestors u of v.Clearly, Dv = �v � fv.Lemma 2.13 Any node v that is not a leaf and not the source, gets an allocation message inround at most �v + 2.Proof. The lemma is clearly true when v is a child of the source. Assume that the lemma istrue for a node v. We will prove it for a child w of v. The node v is woken up by a wakeup25

message in round at most Dv = �v � fv. We show the argument in the case when v is not inthe suspended situation at the end of the �rst waiting period (i.e., there is no second waitingperiod). Otherwise the reasoning is similar.There are two cases.1. The node v gets an allocation message from its parent before the end of the �rst waitingperiod.In this case v sends �rst wakeup messages to all its children in dv rounds following roundDv, then waits c1(v) rounds, and sends allocation messages to all its children that are notleaves. Denote the number of such children by r. Hence w gets an allocation message inround at most �v � fv + dv + c1(v)+ r. Since c1(v) � fv +1, in view of Lemma 2.12, this timeis at most �v + dv + r + 1. Since, �w � �v + dv + r � 1, it follows that w gets an allocationmessage in round at most �w + 2.2. The node v gets an allocation message from its parent at or after the end of the �rstwaiting period.In this case v gets the allocation message in round at most �v+2. Then it sends allocationmessages to all of its children that are not leaves. It follows that w gets an allocation messagein round at most �v + 2 + r. However, �w � �v + r. It follows that w gets the allocationmessage by the round �w + 2. 2Lemma 2.14 Every leaf gets a large wakeup message in round at most n+ 1.Proof. Let u be a leaf and let v denote its parent. As in the proof of Lemma 2.13, we showthe argument in case when v is not in a suspended situation, the other case being similar.There are two cases.1. The node v gets an allocation message from its parent before the end of the �rst waitingperiod.In this case v sends �rst wakeup messages to all its children in dv rounds following roundDv, then waits c1(v) rounds, then sends allocation messages to all its r children that are notleaves, and �nally sends large wakeup messages to its �nal children that are leaves. (Recallthat v's �nal children are those old children which at the end of waiting have not yet receivedlarge wakeup messages.) If x denotes the number of old children, there are at most x� c1(v)�nal children. Hence u gets a large wakeup message by round Dv+dv+ c1(v)+r+x� c1(v) =Dv + dv + r+x. The number of old children is equal to the number of rounds between Dv +1(when v starts sending wakeup messages) and the time when v gets an allocation message,which is at most �v + 2, by Lemma 2.13. Hence x � �v + 2� Dv, which implies that u gets26

a large wakeup message by round �v + dv + r + 2. Since �v + dv + r � n � 1, the conclusionfollows.2. The node v gets an allocation message from its parent at or after the end of the �rstwaiting period.In this case v gets the allocation message in round at most �v + 2, and u gets a largewakeup message by round �v + 2 + dv � n + 1. 2Lemma 2.15 The execution time of Algorithm Wake & Label, working in an n-node tree, isat most n+ 1.Proof. If v is not a leaf, an allocation message is sent to node v by round �v + 2. Since�v � n � 1, for all nodes, this implies that all allocation messages are sent by round n + 1.Hence all wakeup messages to non-leaves are sent by round n+1. If v is a leaf, a large wakeupmessage is sent to node v by round n + 1, in view of Lemma 2.14. This implies that allwakeup and all allocation messages are sent by round n+1. It remains to show that the sameis true for count messages. Since a non-leaf does not send any count message after getting anallocation message, it follows that non-leaves do not send count messages after time n + 1.Let v be a leaf and let u be the parent of v. The node v sends a count message immediatelyafter being woken up. If u has old children then the last of them must get a large wakeupmessage by round n + 1, and consequently all children of u, including v, must be woken upby round n which implies that v sends its count message by round n+1. Hence suppose thatu does not have old children. The node u starts waking up its children in round Du + 1, andthus v is woken up by round Du+du, and sends its count message by round Du+du+1. Thisconcludes the proof because Du + du + 1 = Dv + 1, and Dv � n� 1, for every node v. 2Lemma 2.16 All labels given to nodes by Algorithm Wake & Label, and all messages sentduring its execution in an n-node tree, are of size O(logn) bits.Proof. It is enough to prove that for every label assigned, its value is at most n and its pre�xhas length at most O(logn) bits. The �rst statement is obvious, as values are consecutiveintegers starting from 0. In order to prove the second statement, it su�ces to show that,for any branch of the tree, the number of nodes in this branch which send special allocationmessages during the execution of the algorithm, is O(logn). Take any branch of the treeand let v1; : : : ; vk, be its nodes sending special allocation messages, listed top-down. Thusc1(vi+1) � 32c1(vi) and c1(v1) � 1. Hence c1(vk) � (32)k�1. By Lemma 2.12, the number ofnodes foreign to vk is at least (32)k�1 � 1. It is also at most n� 1. Thus k is O(logn). 227

Since at most 4 messages travel along any link of the tree, Lemmas 2.15 and 2.16 im-ply the desired result. Again, the simple \rushing" modi�cation introduced for AlgorithmWake & Label+C ensures asymptotically optimal time complexity.Theorem 2.3 Given an n-node tree T and a source s, Algorithm Wake & Label assignsdistinct labels of size O(logn) bits to all the nodes. Its time complexity is at most minfn +1; 3bb(T; s)g, hence it is asymptotically optimal. Its message and bit complexities are O(n)messages and O(n logn) bits, respectively.2.3 A lower bound for message-optimal algorithmsWhile Algorithm Wake & Label uses O(n) messages, up to 4 messages can travel along everylink, and hence the total number of messages can be as much as 4 times larger than the lowerbound of n� 1. Our next result shows that any labeling protocol that meets this lower boundon the number of messages must in fact produce very large labels.Theorem 2.4 Any labeling protocol using at most n� 1 messages must assign labels of (n)bits to label some n-node tree.Proof. A protocol that uses at most n � 1 messages on n-node trees satis�es the propertythat any link is traversed exactly once by a message, namely, from parent to child.Fix a labeling protocol P . To prove the lower bound, it su�ces to construct some n-nodetree for which P assigns some (n)-bit labels. In fact we will construct a binary tree withthis property. We study the behavior of P on the class of trees rooted at s in which everynon-leaf node v has exactly two children, w0(v) and w1(v). Each such non-leaf node v sendsunique messages M0(v) to w0(v) and M1(v) to w1(v). In every execution of P these messagesdepend only on the unique message that v got from its parent.Assume n is odd, and let d = (n � 1)=2. Let B be the complete binary tree of depth d,rooted at s. Since B has 2d leaves, protocol P must assign a label of size (d) = (n) to atleast one of them. Let x be such a leaf of B. Our proof is based on identifying an n-nodesubtree T of B, containing the leaf x, such that P 's execution on T is indistinguishable fromits execution on B, and hence P will assign the same label to x in T as in B.Let Z = fz0; z1; : : : ; zdg be the branch of B where z0 = s and zd = x. Let Y = fy1; : : : ; ydg,where yi is the other child of zi�1 in B, distinct from zi. Let T be the subtree of B spannedby the nodes of Z [ Y . T has n = 2d+ 1 nodes.Consider an execution of protocol P on T . By induction on i, the unique message sent byzi to zi+1 is the same as the message sent by zi to zi+1 when the protocol is executed on B.28

In particular, the messages received by x in the two executions are also identical. Since thelabel assigned to each leaf depends only on the unique message received by it, it follows thatlabels assigned in both cases are equal. Consequently, the leaf x of the n-node tree T gets alabel of size (n). 2Note that our proof method implies the following claim, which is somewhat stronger inthe sense that even restricting the labeling problem to binary trees would not allow to derivelabeling algorithms using labels smaller than (n) bits.Corollary 2.1 Any labeling protocol for binary trees which uses at most n� 1 messages overevery n-node binary tree, must assign labels of (n) bits to some nodes in some n-node binarytree.2.4 Optimal time algorithms for treesIn what follows we present an algorithm named Fastest working in optimal time bb(T; s) onany n-node tree T and source s. It uses O(n) messages but assigns labels of size O(pn) bits.In Section 2.5 we prove that this is the smallest possible size of labels which can be assignedby optimal time algorithms.Denote the degree of a vertex x by d(x) and the subtree rooted at x by Tx. Given a node x,let t(x) denote the round when x gets a message from its parent (setting t(s) = 0), and de�nethe capital c(x) as the maximum number of rounds that the node x is allowed to wait betweentime t(x) and starting broadcasting to its children, and still ensure completing broadcastingin Tx by round bb(T; s). (Hence for the source, c(s) = 0.) We havec(x) = bb(T; s)� bb(Tx; x)� t(x): (1)Any execution of a broadcast can be thought of as if an adversary chooses the orderin which a node x calls its children. Given any such order, we rank the children of eachnode accordingly, as follows: if v is the ith child called by x, then the rank of v is set to�(v) = d(x) � i. In particular, the child ranked 0 is called at the latest possible time. Werefer to this child as the latest child.For a non-root node x, let p(x) denote the path from the source s to x in T , not includings itself. (For s, let p(s) = ;.) We now de�ne the total rank of a node x, denoted �(x), as thesum of the ranks over p(x), i.e., �(x) = Pv2p(x) �(v). (Thus for s, �(s) = 0.)Lemma 2.17 For any node v, c(v) � �(v). 29

Proof. The claim holds trivially for the source s, so it su�ces to prove it for a non-root v.Consider a non-leaf node x. Since the adversary may �x the order in which x calls its childrenarbitrarily, necessarily bb(Tx; x) � bb(Tz; z) + d(x) (2)for any child z of x. If z is the ith child informed by x, then t(z) = t(x) + i, and thus by (1)and (2),c(z) = bb(T; s)� bb(Tz; z)� t(z) � bb(T; s)� bb(Tx; x) + d(x)� t(x)� i = c(x) + �(z) :Hence for a non-root v, by repeatedly applying the last inequality from v upwards on thepath p(v), it follows that c(v) � c(s) +Pz2p(v) �(z) = c(s) + �(v). Since c(s) = 0, the lemmafollows. 22.4.1 A simpli�ed protocol PWe �rst describe a simple variant of Algorithm Fastest, named protocol P , which capturesthe essential idea and works in optimal time but still assigns potentially long labels. We thenshow how to re�ne it and get labels of size O(pn) bits.The labels assigned by protocol P are strings in the language described by the followinggrammar:- S =) "- S =) � hrankiS- S =) � hlatestiS- �; � =) coding of a positive integer in base 2where " is the empty word and hranki and hlatesti are two special symbols. The meaningof the labels is the following:� The label � hrankiS is assigned to the rank-� child of the node labeled S. (Recall thatthe rank of a node v is de�ned as �(v).)� The label � hlatestiS is assigned to the node reached by starting from the node labeledS and continuing downwards to the rank-0 (latest) child, for � times.30

ε

3R 2R 1R 1L

3L1R2L

2L3R1R1L3R2R1L3R2R2L

2L1L3R1R3R2R3R

1R1L2R1L

Figure 5: Tree labeling using protocol P . The symbols \R" and \L" stand for \ hranki " and\ hlatesti " respectively.Figure 5 illustrates the output of Protocol P on an example tree.Protocol P operates as follows. When a node x receives message S from its parent, it doesthe following:1. It assigns S to be its own label.2. If S = � hrankiS 0 then it sends messages (d(x)� i) hrankiS to the ith child it calls, fori < d(x), and sends message 1 hlatestiS to the last child it calls.3. If S = � hlatestiS 0 then it sends messages (d(x) � i) hrankiS to the ith child it calls,for i < d(x), and sends message (� + 1) hlatestiS 0 to the last child it calls.To start the process, the source acts as if it has received a message S = ", the empty word.Protocol P clearly terminates since messages traverse the tree top-down, and every nodesends a unique message to each of its children. While protocol P requires time bb(T; s) in theworst case and assigns distinct labels to all nodes, the length of the label assigned to node xcan be as large as (n logn) on certain topologies (such as the one of Figure 2).2.4.2 Algorithm FastestWe now re�ne protocol P to avoid the use of long labels. The modi�ed algorithm, AlgorithmFastest, is based on the observation that whenever the label assigned to x by P is long, itimplies that �(x) and hence c(x) is large (see Lemma 2.17). Thus x is allowed to wait a long31

time before continuing the label assignment process. This delay can be used to explore someof the subtrees, as done in Algorithm Wake & Label, and thus reduce the size of used labels.In Algorithm Fastest each node sends to its children three types of messages:- Allocation messages of the form M = ([S : i]; �), consisting of a location part [S : i],where S is a string and i is an integer, and a deadline part � which is an integer.- Wakeup messages.- Closure messages of the form ([S : i]; [a; b]) where [S : i] is as before, and a; b are twointegers.A node v other than the source also sends a count message to its parent informing it of thesize of the subtree Tv, as in Algorithm Wake & Label.The algorithm performs the following two phases.Phase AUpon receiving a wakeup message x starts sending wakeup messages to its children, in thenext round. The ranking function described in Protocol P is determined according to thissequence of calls.Any leaf which got a wakeup message sends back a count message to its parent, andintermediate nodes send count messages bottom-up, as in Algorithm Wake & Label.Upon receiving an allocation message ([S : i]; �), x keeps on performing phase A for �rounds. (The source behaves like a node receiving the allocation message ([0 : 0]; 0) at time0.) If phase A has not started before, x starts it and performs it for � rounds. At the end ofthis period, all children that have sent count messages to x are called closed and all others arecalled open. Then x chooses ([S : i]) as its own label and immediately proceeds as follows:Phase BCase 1. At most one child is open.In this case x has already called all its children. Now x �rst sends the message ([S : i+1]; d(x)�1) to the open child (if any) and then sends closure messages of the form ([S : i]; [a; b]) toall closed children. The interval [a; b] assigned to each closed child is computed on the basisof the count message received from that child, which reported the size of its subtree, as inAlgorithm Wake & Label.Case 2. More than one child is open.There are two subcases.2.1. The node x has already called all its children:32

Then x sends allocation messages to all its children in the same order as in phase A.2.2. The node x has not called all its children yet:Then x sends allocation messages �rst to its children which it has not called yet (im-plicitly serving as a \wakeup" message as well), and then to all other children, in thesame order of sending the wakeup messages.In both subcases, the children of x are ranked in the order of the �rst messages sent toeach of them. If x has k open children y1; : : : ; yk ranked �(y1) > �(y2) > : : : > �(yk), thenchild yj is called the jth open child.Messages sent by x during phase B are computed in the following way. For open children,x makes use of S to compute a string Sj to be sent to the jth open child in the same wayas in protocol P . However, protocol Fastest requires more information. That is, if x callsan open child j on round rj of phase B, then instead of sending simply the message Sj as inprotocol P , x sends Mj = ([Sj : 0]; �) with � = d(x)� rj.Closed children of x get the appropriate closure messages, computed as in Case 1.If a node x receives a closure message ([S : i]; [a; b]), then it assigns ([S : i]; [a]) as its ownlabel. Moreover, all children of x are already closed, and thus x sends them the appropriateclosure messages.This completes the description of Algorithm Fastest.2.4.3 Analysis of Algorithm FastestThe algorithm Fastest clearly terminates since any node completes its task at most d(x)rounds after its parent x has done so, and the source �nishes after d(s) rounds. In order tocompute the size of labels assigned by the algorithm, we need the following lemmas.Lemma 2.18 Any node x involved in phase B, has performed phase A for at least �(x)rounds.Proof. Assume that a node x starts phase A (resp. B) in round ta (resp. tb). Then the childv of x with rank �(v) starts phase A in round t0a = ta+ d(x)� �(v). Moreover, it starts phaseB in round t0b = tb + d(x). It follows that t0b � t0a = tb � ta + �(v). The conclusion now followsby the de�nition of �(x). 233

Lemma 2.19 Let a and n be positive reals, let k be a positive integer, and let x = (x1; : : : ; xk)be a vector of integers greater than 1. Suppose that P1�i�k ixi � n. ThenkXi=1(logxi + a) � 2pn� 1 + a(p2n + 1) :Proof. Without loss of generality we may assume thatkXi=1 ixi = n : (3)First, consider the following real-valued maximization problem :For a positive real vector x = (x1; : : : ; xk),maximize f(x) = X1�i�k log xisubject to condition (3).Standard analysis reveals that f admits a unique global maximum at xi = n=(ki). Conse-quently f(x) � X1�i�k log� nki� = k log�nk�� log(k!):As k! � �ke�k�1 for any integer k � 1, we obtainf(x) � k logn� 2k log k + log k + (k � 1) � k logn� 2k log k + 2k � 1:Consider the auxiliary function g(y) = y logn� 2y log y + 2y � 1, for y � 0. Its maximum isattained for y = pn and is 2pn� 1. Hencef(x) � 2pn� 1 : (4)Now, going back to the original problem, we use the fact that xi � 1 for every 1 � i � k, toconclude that n = P1�i�k ixi � k(k � 1)=2, and hencek � p2n+ 1 : (5)Finally, combining inequalities (5) and (4) yields thatX1�i�k(log xi + a) � f(x) + ak � 2pn� 1 + a(p2n+ 1) : 234

Theorem 2.5 Given an n-node tree T and a source s, Algorithm Fastest assigns distinctlabels of size O(pn) bits to all the nodes. Its time complexity is the optimal bb(T; s). Itsmessage and bit complexities are O(n) messages and O(npn) bits, respectively.Proof. It is easy to see that Algorithm Fastest assigns distinct labels and works in timebb(T; s). In what follows we bound the size of the labels assigned to the nodes.Let L(x) denote the label of x, and let jL(x)j denote its length. First, we study themaximum length jS(x)j of a pre�x appearing in a label of x. As pre�xes are only modi�ed bynodes receiving an allocation message, we consider only such nodes. Suppose that x receivesan allocation message [S(x) : i], and let ql(x) (resp. qr(x)) be the number of hlatesti (resp.hranki ) symbols appearing in S(x). Since there is at least one hranki symbol between twosuccessive hlatesti symbols, we have ql(x) � qr(x) + 1.Note that S(x) is made of two types of character groups : (i) � hranki which means \I amthe �th open child," and (ii) � hlatesti which means \I am obtained by following the latestbranch for � times." Let Sr(x) be the subsequence of S(x) containing groups of type (i) andSl(x) be the one with groups of type (ii); we have jS(x)j = jSr(x)j+ jSl(x)j, and we will nowbound each of the two terms separately.Bounding jSr(x)jSuppose that Sr(x) = �1 hranki�2 hranki : : : �k hranki and consider the symbols hrankiappearing in S at positions f1; 2; : : : kg. These symbols are in a one-to-one correspondencewith some vertices v1; v2; : : : vk of the path from r to x.Since i� 1 hranki symbols occur before the symbol associated to any vertex vi, we have�(vi) � i. Lemma 2.18 implies that for any vi, at least i rounds elapse between phases A andB. Hence, if vi is an open child, it has at least i=2 descendants. Moreover, for every openchild w of vi, since �(w) � �(vi), it follows that w has at least i=2 descendants as well.The symbol �i means that at the end of phase A, vi had at least �i � 1 open childrendi�erent from vi+1 (otherwise the integer �i cannot appear). In the special case where �i = 1,vi had at least one open child di�erent from vi+1 (otherwise no character would be added tothe pre�x S(x) but instead the value of the integer j appearing in the location [S : j] wouldbe increased). In any case, vi has at least �i=2 open children, di�erent from vi+1. By theprevious argument, each of these children has at least i=2 descendants, so the tree containsat least i�i=4 nodes which do not belong to the subtree Tvi+1 . Globally, we �nd k pairwisedisjoint sets of cardinalities at least i�i=4. It follows thatX1�i�k i�i � 4n:35

Since jSr(x)j � P1�i�k(log�i +O(1)), lemma 2.19 implies jSr(x)j = O(pn).Bounding jSl(x)jIn order to bound the length of Sl(x) = �1 hlatesti � � ��k hlatesti , note that the symbol �imeans that there exist �i successive latest children each one having a total rank at least i� 1.Similarly to the previous analysis, we get P1�i�k i�i � 2n. Since jSl(x)j � P1�i�k(log �i +O(1)), using lemma 2.19 once again we get jSl(x)j = O(pn).Bounding jL(x)jIn view of the above, jS(x)j = O(pn). Since jL(x)j � max jS(x)j+O(logn) for any vertex x,it follows that jL(x)j = O(pn), proving that all labels are of size O(pn).The same arguments show that all messages are of size O(pn) bits. Since at most 3 mes-sages travel on any link, this shows that Algorithm Fastest has message and bit complexitiesO(n) messages and O(npn) bits, respectively. 22.5 A tradeo� for optimal time algorithms on treesThe following lower bound shows that labels assigned by Algorithm Fastest are of smallestpossible order of magnitude, for all algorithms working in optimal time bb(T; s), on any treeT and source s.Theorem 2.6 Any labeling protocol working in time at most bb(T; s) on any tree T and sources, must assign labels of size (pn) on some n-node tree.Proof. Fix a labeling protocol P . We study the behavior of P on the class of binary treesrooted at s. Note that the local state of a node v during the execution of P depends only onthe degree of v, on whether v = s, and on messages previously received by v.Assume that d = q(n� 1)=2 is integer, and let B be the complete binary tree of depth d,rooted at s. Let C be the tree obtained from B by replacing every link of B by a simple pathof length d. Since C has 2d leaves, protocol P must assign a label of size (d) = (pn) to atleast one of them. Let x be such a leaf of C.Let Z be the branch of C joining s and x. Let z0; z1; : : : ; zd�1 be nodes of Z with morethan one child, listed top-down, with z0 = s. Let zd = x. Let Y = fy1; : : : ; ydg, where yi is36

the other descendant of zi�1 at distance d from it, di�erent from zi. Let T be the subtree ofC spanned by the nodes of Z [ Y and the nodes connecting them. T has n = 2d2 + 1 nodes.Let �T (resp., �C) denote the execution of protocol P on the tree T (resp., C). The deviationtime of a node v of T , denoted by �t(v), is the time in which the execution �T deviates in vfrom �C , i.e., the �rst round in which v enters a di�erent local state in the two executions.Note that the only nodes that start the two executions in di�erent local states, once theyare woken up, are the nodes of Y 0 = Y n fydg, since each yi 2 Y 0 has di�erent degrees in Tand C. Since the execution is initiated by the source s, node yi is woken up in round id atthe earliest, hence �t(yi) � id.Every other node v starts the two executions with an identical local state, and thereforeit can distinguish between them only after receiving a di�erent message from some neighbor.As only the nodes of Y 0 can originate the transmission of di�erent messages in the executions�T and �C , there must exist a path (u0; : : : ; uq) in T such that u0 2 Y 0, uq = v, and ui sendsa di�erent message to ui+1 in round ri of executions �T and �C , where r0 < � � � < rq�1. Hencedenoting the distance between the nodes v and w in T by dist(v; w), we have that for anynode v =2 Y 0, �t(v) � min1�i�d�1f�t(yi) + dist(yi; v)g � min1�i�d�1fid+ dist(yi; v)g :In particular, as dist(yi; x) = d(d� i+ 2), we have that�t(x) � min1�i�d�1fid+ (d2 � id+ 2d)g � d2 + 2d : (6)Let tlC denote the time x is assigned a label in the execution �C. Note that bb(T; s) = bb(C; s) =d2 + d, and hence tlC � d2 + d. By Inequality (6), tlC < �t(x), hence in round tlC the states of xin the executions �T and �C are still identical, and therefore x must get the same (pn)-bitlabel in �T as in �C . 2Again, the above proof yields the following slightly stronger claim (in the same way Corol-lary 2.1 is stronger than Theorem 2.4).Corollary 2.2 Any labeling protocol for binary trees which works in time at most bb(T; s) onany binary tree T and source s, must assign labels of size (pn) on some n-node binary tree.3 Labeling arbitrary networksIn this section we study the label assignment problem for arbitrary networks in the mixedmodel. Our algorithms, named Algorithm Wake & LabelGX for X = A;B, are simple variants37

of the corresponding Algorithms Wake & LabelX . They assign labels from the range [1; n].Algorithm Wake & LabelGB terminates in worst-case time 3n and has message and bit com-plexities of O(m) messages and O(m + n logn) bits, respectively, where m is the number oflinks in the network. Using Algorithm Wake & LabelA instead of Wake & LabelB, the result-ing algorithm assigns labels from the range [1; n], and works in asymptotically optimal time,for any n-node network.3.1 Lower boundCall a link saturated if a message has already crossed it. It is easy to see that bb(G; s) equalsthe worst-case time required for saturating all links. Indeed, since the network is unknown, itis necessary to saturate all links to be sure that all nodes got the message, as an extra nodeof degree 2 could be \hidden" in the middle of an unsaturated link.We will use the following useful properties of \blind broadcast," proved in [11].Lemma 3.1 For every n-node network G, bb(G; s) � 2n� ecc(G; s)� 2.Proof. Let s be the source and let d = ecc(G; s). Let Li, for i = 1; : : : ; d, be the ith level ofthe network (i.e., the set of nodes at distance i from the source). Denote by ai the size of Li.After a1 rounds since the beginning of broadcasting, all links between the source and L1 aresaturated. After at most a1�1+a2 further rounds, all internal links in L1 and all links betweenL1 and L2 are saturated. After at most a2� 1+ a3 further rounds, all internal links in L2 andall links between L2 and L3 are saturated. Proceeding in this way we conclude that after atmost a1+(a1�1+a2)+(a2�1+a3)+� � �+(ad�1�1+ad) rounds, all links of the network, exceptpossibly the internal links in Ld, are saturated. Further ad�1 rounds are su�cient to saturateall these links. Thus total time is at most 2(a1+ � � �+ ad)� d = 2(n� 1)� d = 2n� d� 2. 2As an immediate corollary we get the following.Corollary 3.1 For any integer n, there exists an n-node network Gn with source sn, suchthat bb(Gn; sn) = 2n� o(n).Hence 2n is the asymptotic lower bound on the worst-case execution time of any labelingprotocol.3.2 Algorithm Wake & LabelGBThe �rst stage of Algorithm Wake & LabelGB involves constructing a spanning tree T (rootedat s) for the network G. The tree construction procedure works as follows. Initially, the source38

broadcasts a \wakeup" message throughout the network. Again, call a link saturated if thewakeup message was sent on it in at least one direction. Suppose a node v gets the wakeupmessage for the �rst time in round t, from a neighbor w. Then v marks w as its parent inthe tree, and in the next round, t + 1, it replies to w with an \ack-parent" message, thusinforming w of this fact. In each subsequent round, v sends the wakeup message on one of its(yet) unsaturated links. (Note that if both v and w try to wake up each other simultaneously,then none of them will reply with an acknowledgement to the other.)By an argument similar to that of the proof of Lemma 3.1 one can show that the treeconstruction procedure terminates by time 2n � 2. We will use terms \parent", \child" and\leaf" with respect to this tree.Moreover, we claim that by round 2n � 1, each leaf v of the tree T knows that it is aleaf. This is because by round 2n� 2, all of v's links are saturated, and hence not getting an\ack-parent" message in response to any of its own wakeup messages (if any) reveals to v (byround 2n� 1) that it was not selected as a parent by any of its neighbors.Let Tv denote the subtree of the constructed tree T , rooted at v. The second stage ofthe algorithm involves counting the number of nodes nv in each subtree Tv. This is done inthe usual bottom-up convergecast fashion (cf. count messages in the description of AlgorithmWake & Label).Fact 3.1 Once all leaves in a subtree Tv have started the counting, the time to complete thecount on Tv is at most ecc(Tv; v) � nv � 1.The third (allocation) phase of the algorithm is carried out just as in Algorithm Wake & LabelB.Clearly, Algorithm Wake & LabelGB terminates, since each of the three phases does.Theorem 3.1 Given an n-node, m-edge network and a source s, Algorithm Wake & LabelGBassigns distinct labels from the range [1; n] to all the nodes. Its time, message and bit com-plexities are 3n rounds, O(m) messages and O(m+ n logn) bits, respectively.Proof. It is easy to verify that all labels are distinct and belong to [1; n]. We now analyzethe worst-case execution time of the algorithm.Let p0 = s, and let pi+1 denote the child of pi for whom pi had to wait (i.e., that was thelast to complete the count), for i � 0. This de�nes a path P = (p0; : : : ; pk+1), where pk+1 didnot need to wait at all (i.e., all its children have already completed their count once it got itsblock of labels from its parent pk). All nodes not on the path P are called normal.We �rst observe the following. 39

Fact 3.2 For a normal node v, the time required to complete the label allocation phase overTv is at most nv � 1.Based on this, we now argue that for any normal child v of pi, 0 � i � k, the labelallocation over Tv completes by round 3n. Suppose that pi started the label distributionamong its children in round 2n + q. Letting n̂ = npi+1, note that by Fact 3.1, the count onTpi+1 completes by round 2n+ n̂� 1, implying that q � n̂� 1. As the total number of nodesin the subtrees of all the normal children of pi is at most n� n̂, we get from Fact 3.2 that thelabel distribution on them completes by round (2n+ q) + (n� n̂) � 3n.It remains to argue the same bound for nodes pi, 0 � i � k + 1, and in fact, it su�cesto argue this for pk+1. Let n̂ = npk+1 and let ` denote the number of normal children of pk.Suppose that pk started the label distribution among its children in round 2n + q. Observethat by Fact 3.1, the count on each subtree Tv of a normal child v of pk has completed byround 2n + nv � 2n + (n � n̂ � ` + 1) � 1, implying that q � n � n̂ � `. It follows that pkpasses the remaining in�nite block to pk+1, after spending ` rounds on distributing blocks toits normal children, by round 2n + (n� n̂) at the latest. By Fact 3.2 again, the distributionon Tpk+1 will be also completed by round (3n� n̂) + n̂ = 3n at the latest.As for message and bit complexities, note that all messages in stage 1 (the tree constructionstage) are of constant size, and one such message travels on every link of the network. Messagesin stages 2 and 3 (the counting and allocation stages) are of logarithmic size, and in each ofthese stages one such message travels on every link of the spanning tree T . This concludesthe proof. 23.3 Algorithm Wake & LabelGAThe �rst stage of Algorithm Wake & LabelGA involves waking up all nodes and simultaneousconstruction of a spanning tree T (rooted at s), for the network G. It is carried out in thesame way as the �rst stage of Algorithm Wake & LabelGB. The second (counting) phase ofthe algorithm is also done just as in Algorithm Wake & LabelGB. Finally, the third phase isinitiated by the source only after receiving count messages from all its children, as in AlgorithmWake & LabelA, and is performed in the same manner. Again, Algorithm Wake & LabelGAterminates since Algorithm Wake & LabelA does.Theorem 3.2 Given an n-node, m-edge network G and a source s, Algorithm Wake & LabelGAassigns distinct labels from the range [1; n] to all the nodes. Its time complexity is at most4bb(G; s) + 1, hence it is asymptotically optimal. Its message and bit complexities are O(m)messages and O(m+ n logn) bits, respectively.40

Proof. It is clear that labels are distinct, and from the range [1; n]. We now estimate theexecution time of the algorithm. By an argument similar to the proof of Lemma 3.1, thetree construction procedure terminates after bb(G; s) + ecc(G; s) rounds. As in AlgorithmWake & LabelGB, after one more round every leaf of T knows that it is a leaf and startsstage 2. Stage 2 is completed after h further rounds, where h is the height of the tree T .Messages in stage 3 are all sent after bb(G; s) additional rounds. Since ecc(G; s) � bb(G; s)and h � bb(G; s), we conclude that the execution time of the algorithms is at most bb(G; s) +ecc(G; s)+1+h+bb(G; s) � 4bb(G; s)+1. Since bb(G; s) � �(G; s), Algorithm Wake & LabelGAworks in asymptotically optimal time. Since at most 2 messages of constant size travel alongeach link of the network in stage 1 (possibly one in each direction, simultaneously), and atmost 3 additional messages of logarithmic size travel along each link of the tree T during theentire execution, the claim concerning message and bit complexities is satis�ed. 24 The extreme modelsThis section studies two variants of the mixed model discussed in the previous sections, namely,the all-port model and the one-port model. These variants are referred to as extreme becausethey either completely relax all the communication constraints, or maximize these constraints.In the all-port model, a node is able to send messages to all its neighbors simultaneously,and at the same time, to receive messages from all its neighbors simultaneously. The degreeof a node is therefore the unique limitation on its communication capability. (In a sense, themixed model is \all-port" for receptions only.) It should be clear that in the all-port model,a node is able to send di�erent messages to all its neighbors simultaneously.In contrast, the one-port model allows each node, on each round, to send only one messageto a single neighbor, or to receive a single message from a neighbor, but not both. This meansthat a protocol allowing a node to send a message to a neighbor and receive a message from(the same or another) neighbor on the same round is not admissible, and will result in a run-time error. It should be clear that in this model it is crucial that di�erent protocols runningsimultaneously inside the same network are carefully coordinated, since an uncoordinatedsimultaneous execution of many unrelated protocols might cause unintentional collisions dueto simultaneous receptions of several messages by the same node through di�erent ports.4.1 The all-port modelIn this section we discuss label assignment in the all-port model. Clearly, all the algorithmspresented for the mixed model work in the all-port model as well. Hence we focus on improved41

algorithms, which do not work in the mixed model, and on lower bounds (which will naturallyapply to the mixed model as well).Speci�cally, we start by describing two labeling algorithms for arbitrary networks. The �rstalgorithm, called DFS+, labels the nodes of an n-node network in 2n rounds in the worst case.The second algorithm is asymptotically optimal since it labels the nodes in exactly 3 �ecc(G; s)rounds, and clearly no algorithm can perform faster than ecc(G; s) rounds. Although the latteralgorithm is asymptotically optimal, it might be slower than the former algorithm for somenetworks.We then give two lower bounds for label assignment algorithms on trees.4.1.1 Algorithm DFS+The following algorithm labels an arbitrary graph G in time 2n�2 with labels from the range[1; n] in the all-port model. The algorithm is a variant of the distributed depth-�rst search(DFS) algorithm of [6]. It terminates for the same reason that the DFS algorithm does.The algorithm is essentially sequential, in the sense that it has exactly one locus of activityat any given moment. The control of the algorithm is carried via a single message (the\token"), that traverses the graph in depth-�rst fashion, starting at the source s and visitingone vertex at a time. The token carries with it a counter C of labels, such that the labels inthe range [1; C] have already been assigned. Whenever the token reaches a node v for the �rsttime, the node assigns itself the label C + 1 and increases the counter C.As in the standard DFS process, whenever the token reaches a node v, the next step isdecided as follows. If v has neighbors that were not visited so far, then we next visit one ofthem. Otherwise, we backtrack to the vertex from which v was visited for the �rst time. Ifthere is no such vertex (i.e., if v is the source s), then the process terminates. It is well knownthat this process is guaranteed to visit every vertex in the graph, and moreover, it implicitlyde�nes a tree, known as a DFS tree, with s as the source, by setting the parent of a vertex vto be the vertex w from which v was visited for the �rst time.If every edge of the graph is traversed by the token, then the process will clearly require�(m) rounds in an m-edge network. The idea proposed in [6] in order to reduce the timecomplexity of the DFS process to O(n) is to perform the explorations of all non-tree edges\for free". To do that, the algorithm must ensure the property that a vertex visited for the�rst time will know which of its neighbors have already been visited and which haven't.This can be achieved as follows. Each node v with a set Ev of adjacent edges maintains alist Qv containing a subset of Ev, such that the node at the other end of each edge e 2 Qv hasnot yet been visited by the process. Initially the list Qv is set to Ev. Whenever v is informed42

by some neighbor w that it has been visited, or whenever the token arrives at v from w, vremoves the edge connecting it to w from the list Qv. (Note that these operations do notrequire v to know w's identity or label.)When a node v is visited for the �rst time, the process �rst assigns the label C + 1 to vand increase the counter C. The process is then required to do the following:If Qv = ; then do:� Inform all v's neighbors that v has been visited;� Backtrack to the node from which v was visited for the �rst time.If Qv 6= ; then do:� Pick some edge e 2 Qv and remove it from Qv;� Inform v's neighbors on all edges except e that v has been visited, and at the same time,transfer the token to the neighbor at the other end of e.In subsequent visits of the token at node v, the process does the same, except that it does notassign v a label or inform v's neighbors.Note that in all cases, the entire operation of the process at the visited node v requires asingle round. Moreover, only tree edges are traversed, once in each direction. It follows thatthe time complexity of the algorithm is 2n� 2.Theorem 4.1 Given an n-node, m-edge network G and a source s in the all-port model,Algorithm DFS+ assigns distinct labels from the range [1; n] to all the nodes. Its time, messageand bit complexities are 2n� 2 rounds, O(m) messages and O(m+ n logn) bits, respectively.4.1.2 An asymptotically optimal algorithm for arbitrary networksAlgorithm All-port 3-Phase is the following straightforward modi�cation of AlgorithmWake & LabelGA, possible in view of the all-port model properties. In each of the three stagesof Algorithm Wake & LabelGA, all actions of a node are now performed simultaneously. Thisalgorithm obviously terminates, since Wake & LabelGA does.Theorem 4.2 Given an n-node, m-edge network G and a source s in the all-port model,Algorithm All-port 3-Phase assigns distinct labels from the range [1; n] to all the nodes. Itstime complexity is 3 � ecc(G; s) + 1, hence it is asymptotically optimal. Its message and bitcomplexities are O(m) messages and O(m+ n logn) bits, respectively.43

Proof. Algorithm All-port 3-Phase works in exactly 3 � ecc(G; s) + 1 rounds. Indeed, ittakes ecc(G; s) + 1 rounds for the nodes at distance ecc(G; s) from s to realize that they areleaves of the Breadth First Search (BFS) tree T . Then, 2 �ecc(G; s) additional rounds are usedto perform counting upward in T , and to perform labeling downward in T . The argumentconcerning message and bit complexities is the same as for Algorithm Wake & LabelGA. 2Remark. When applying Algorithm All-port 3-Phase to trees, three rounds can be savedby introducing a slight modi�cation. On a tree T , when a node x at distance d from the source sreceives a wake-up message, it acknowledges the message, and includes in its acknowledgmentthe number of its children. At time 2d the source s knows all the degrees of vertices atdistance d, that is, it knows the structure of the tree at distance d + 1. Therefore, at time2 (ecc(T; s)�1), the source knows the entire tree, and can start labeling. All nodes are labeledafter 2 (ecc(T; s)�1)+ecc(T; s) = 3�ecc(T; s)�2 rounds. As shown next, this modi�ed versionof Algorithm All-port 3-Phase performs in strictly optimal time.4.1.3 Lower bounds for optimal labeling on treesThe optimality of Algorithm All-port 3-Phase on trees is based on the following lowerbound.Theorem 4.3 Any labeling protocol in the all-port model that assigns labels from the range[1; n] requires at least 3 � ecc(T; s)� 2 rounds on some tree T and source s.Proof. A (k; k1; k2)-broom� B is the graph of size n = 2k + k1 + k2 + 1 consisting of� a path of 2k + 1 nodes with extremities vL; vR, and� k1 (resp. k2) additional nodes connected to vL (resp. vR).Assume the source s is the central node of the path. Then ecc(B; s) = k + 1.Assume for the purpose of contradiction that there exists a protocol that assigns labels fromthe range [1; n] on every tree, and completes labeling the (k; k̂; k̂)-broom B, where k̂ = 2k+2,in t < 3 � ecc(B; s)� 2 = 3k + 1 rounds.Let B(k; k̂) denote the family of all (k; k̂; k0)-brooms for any k0 � 0. Consider the lastround of the protocol's execution on B. At that time, any leaf x of vL has not received yet�or really a \dual-purpose" broom, for concurrently sweeping the oor and the ceiling44

any information from the node vR, since vR is at distance k from s, hence the earliest roundin which it wakes up is k, and the distance from vR to x is 2k + 1. Hence at time t, the localinformation maintained at the node x is the same for all brooms in B(k; k̂). It follows thatthe label ` assigned to x by the protocol is at most 2k + 1 + k̂ = 4k + 3, since otherwise, `would be larger than the number of nodes of the (k; k̂; 0)-broom, causing the protocol to failon it.A symmetric argument can be applied to every leaf y of vR, yielding that at time t, nodey cannot have received a label larger than 4k + 3.But B has 4k + 4 leaves, and by the above argument, each of them must be assigned adistinct label from the range [1; 4k + 3]; contradiction. Hence a protocol assigning labels inthe range [1; n] requires at least 3 � ecc(B; s)� 2 rounds on the (k; k̂; k̂)-broom B. 2If the message complexity is exactly m (the number of edges), then we already know byTheorem 2.4 (which is stated for the mixed model but clearly holds for the all-port modelas well), that labels of size (n) are required in some trees. In the all-port model, one canrelax the message complexity hypothesis, and show that assuming the time to be ecc(T; s) isenough to force some labels to be of size (n).Theorem 4.4 Any labeling protocol in the all-port model that works in ecc(T; s) rounds mustassign labels of size (n) on some tree T and source s.Proof. The proof goes along similar lines to that of Theorem 2.4. Consider the class T ofbinary trees T with a source s of eccentricity d in which every non-leaf node v has exactly twochildren. Given a tree T 2 T , an extremal leaf of T is any leaf v at distance d from the source s.Associate with every extremal leaf v of T a d-bit word w(v; T ) = w1(v; T )w2(v; T ) : : : wd(v; T ),wi(v; T ) 2 fleft,rightg, such that the path from s to v in T is obtained by starting from s andgoing successively left or right according to the wi(v; T )'s. (The labels wi(v; T ) may be setarbitrarily, and are only for the convenience of the proof.)Consider a protocol P running in d rounds on any tree T 2 T . For any node v of T , letL(v; T ) be the label assigned to v by P . Such a protocol satis�es the property that for everyextremal leaf v, the label L(v; T ) is assigned to v at time d, and moreover, that label is afunction L(v; T ) = f(M;w(v; T )) where M is the message sent by s to its child on the pathto v in round 1. This is because each node along the path from s to v had to send a messagedown towards v in the very �rst round after it was woken up by s, and therefore it could notrely on any other information.Let B be the complete binary tree of eccentricity d rooted at s. Since B has 2d leaves,protocol P must assign a label of size (d) to at least one of them. Let x be such a leaf of B,and let w = w(x;B). 45

Let Z = fz0; z1; : : : ; zdg be the branch of B where z0 = s and zd = x. Let Y = fy1; : : : ; ydg,where yi is the other child of zi�1 in B, distinct from zi. Let T0 be the subtree of B spannedby the nodes of Z [Y , with the same \left/right" orientation for the edges, namely, such thatw(x; T0) = w(x;B).Also, B and T0 look locally the same to s, hence in round 1 of the executions of protocolP on T and B, s sends to z1 the same message M .It follows that labels assigned to x in both cases are equal, i.e.,L(x; T0) = f(M;w(x; T0)) = f(M;w(x;B)) = L(x;B):As T0 has n = 2d+1 nodes, we conclude that the leaf x of T0 gets a label of size (d) = (n).24.2 The one-port modelIt turns out that an appropriate adaptation of Algorithm Wake & LabelA can be made towork for trees in the one-port model as well, in asymptotically optimal time. It works in timeat most 3 bb(T; s) and assigns labels from [1; n], for any n-node tree T . We also present analgorithm working in asymptotically optimal time for arbitrary networks. It assigns labelsfrom the range [1; n] and has time complexity 2m (we prove that m, the number of edges, isa lower bound on time for algorithms labeling arbitrary networks). Note that if the networkis known to be a tree, m = n � 1 is not a lower bound on labeling time any more: as in themixed model, the lower bound becomes bb(T; s). Hence an algorithm working in 2m roundsis not asymptotically optimal for trees.4.2.1 Algorithm Time-Slots for treesAlgorithm Time-Slots works in three phases, in which nodes send messages wakeup, count,and allocation. In the �rst phase wakeup messages are sent. Upon receiving a wakeup message(and starting in round 1, in case of the source) a node with d children sends wakeup messages(0; d), (1; d),: : : , (d� 1; d), to its consecutive children, in arbitrary order. The role of wakeupmessages is to wake up nodes and inform them in what time slots they can later send countmessages.Count messages are sent bottom up, �rst by leaves of the tree, following their waking upby a wakeup message. A leaf that got a wakeup message (i; d), sends a count message to itsparent in the earliest round t � i mod d. A non-leaf node that got count messages from allits children, and earlier got a wakeup message (i; d) from its parent, sends a count message46

to its parent in the earliest round t � i mod d. The contents of count messages are as inAlgorithm Wake & LabelA. A node that got count messages from all its children knows thesizes of subtrees rooted at each of them.Allocationmessages are sent top down, starting at the source, as in Algorithm Wake & LabelA.Clearly, Algorithm Time-Slots terminates.Theorem 4.5 Given an n-node tree T and a source s in the one-port model, AlgorithmTime-Slots assigns distinct labels from the range [1; n] to all the nodes. Its time complexityis at most 3 bb(T; s), hence it is asymptotically optimal. Its message and bit complexities areO(n) messages and O(n logn) bits, respectively.Proof. Time division in sending count messages assures that the requirements of the one-port model are satis�ed. It is obvious that labels are distinct, and from the range [1; n]. Aftertime bb(T; s) all leaves have got wakeup messages. Waiting time for a node to send a countmessage to its parent after receiving count messages from all its children, is at most d, if theparent has d children. Hence the source receives count messages from all its children after atmost bb(T; s) + c rounds, where c is the maximum sum of numbers of children, taken over allbranches of the tree. Since c � bb(T; s), this will happen in round 2 bb(T; s), at the latest.Sending allocation messages, and thus completing the execution of the algorithm, takes atmost bb(T; s) further rounds, for a total of 3 bb(T; s).Since at most 3 messages of size O(logn) bits travel along each link of the tree, the messageand bit complexities are as claimed. 24.2.2 An asymptotically optimal algorithm for arbitrary networksFor arbitrary networks, let us �rst establish a natural lower bound for the label assignmentproblem on arbitrary networks in the one-port model.Theorem 4.6 Any labeling algorithm working for arbitrary networks in the one-port modelmust take at least m rounds on every m-edge network.Proof. Consider a labeling algorithm A that works correctly on every graph. Suppose, forthe purpose of contradiction, that there exists a graph G(V;E) and an execution � of thealgorithm A on G, such that the labeling of the nodes of G is completed in less than mrounds. Then necessarily, at least one of the following two events must have occurred duringthe execution: 47

1. no message was sent over some edge e = (u; w), or2. at some round t, two messages were sent over two di�erent edges e1 = (u1; w1) ande2 = (u2; w2) that were both unsaturated up until the end of round t� 1. (Recall that,in our terminology, a link is saturated if it has been traversed by a message, in eitherdirection.)We now show that either event leads to contradiction. Suppose �rst that event 1 tookplace. Consider the graph G1 obtained from G by eliminating the edge e, and replacing it bya new node v0, and two new edges e0 = (u; v0) and e00 = (v0; w). If algorithm A is invoked fromthe same source s on G1, then its execution �1 on G1 will be identical to �. Hence execution�1 terminates without assigning a label to the node v0, contradicting the assumption thatalgorithm A performs correctly on every graph.Now suppose that event 2 took place. Speci�cally, suppose (without loss of generality)that ui has sent a message to wi over the edge ei in round t, for i = 1; 2. Observe that bythe speci�cations of the one-port model, all four nodes involved, namely, u1, u2, w1 and w2,are necessarily distinct. Consider the graph G2 obtained from G by eliminating the edges e1and e2, and replacing them by a new node v0, and four new edges e01 = (u1; v0), e001 = (v0; w1),e02 = (u2; v0) and e002 = (v0; w2). If algorithm A is invoked from the same source s on G2,then its execution �2 on G2 will be identical to � up to round t � 1, and moreover, in roundt a message will be sent by the node ui over the edge e0i, for i = 1; 2. This will violate thespeci�cations of the one-port model, as it causes the node v0 to receive two messages on thesame round, leading again to contradiction. 2It follows that the labeling algorithm DFS, based on brute-force DFS, performs surprisinglywell, since it yields an asymptotically optimal protocol.Theorem 4.7 Given an n-node, m-edge network G = (V;E) and a source s in the one-portmodel, Algorithm DFS assigns labels from the range [1; n] to all the nodes. Its time complexityis at most 2m, hence it is asymptotically optimal. Its message and bit complexities are O(m)messages and O(m logn) bits, respectively.Proof. Algorithm DFS visits all nodes of the network, and therefore can label the nodes from 1to n. Moreover, every edge is traversed exactly twice, once in every direction, and thereforethe time complexity of Algorithm DFS is 2m. 248

References[1] S. Albers and M. R. Henzinger, Exploring unknown environments, Proc. 29th Symp. onTheory of Computing, 1997, 416-425.[2] D. Angluin, Local and Global Properties in networks of processors, Proc. 12th Symp. onTheory of Computing, 1980, 82-93.[3] H. Attiya, M. Snir and M. Warmuth, Computing on an Anonymous Ring, Journal of theACM 35, (1988), 845-875.[4] H. Attiya and M. Snir, Better Computing on the Anonymous Ring, Journal of Algorithms12, (1991), 204-238.[5] H. Attiya and J. Welch, Distributed Computing: Fundamentals, Simulations and Ad-vanced Topics, McGraw-Hill, England, 1998.[6] B. Awerbuch, A new distributed depth-�rst-search algorithm, Information ProcessingLetters 20, (1985), 147-150.[7] B. Awerbuch, O. Goldreich, D. Peleg and R. Vainish, A Tradeo� Between Informationand Communication in Broadcast Protocols, Journal of the ACM 37, (1990), 238-256.[8] P. Boldi and S. Vigna, Computing anonymously with arbitrary knowledge, Proc. 18thACM Symp. on Principles of Distributed Computing, 1999.[9] X. Deng and C. H. Papadimitriou, Exploring an unknown graph, Proc. 31st Symp. onFoundations of Computer Science, 1990, 356-361.[10] K. Diks, E. Kranakis A. Malinowski and A. Pelc, Anonymous wireless rings, TheoreticalComputer Science 145 (1995), 95-109.[11] L. Gargano, A. Pelc, S. P�erennes and U. Vaccaro, E�cient communication in unknownnetworks, Proc. 26th Int. Workshop on Graph-Theoretic Concepts in Computer ScienceJune 2000, Konstanz, Germany, LNCS 1928, 172{183.[12] E. Kranakis, Symmetry and Computability in Anonymous Networks: A Brief Survey,Proc. 3rd Int. Conf. on Structural Information and Communication Complexity, 1997,1-16.[13] E. Kranakis, D. Krizanc and J. van der Berg, Computing Boolean Functions on Anony-mous Networks, Information and Computation 114, (1994), 214-236.[14] N. Lynch, Distributed Algorithms, Morgan Kaufmann, San Mateo, CA, 1995.49

[15] P. Panaite and A. Pelc, Exploring unknown undirected graphs, Proc. 9th ACM-SIAMSymposium on Discrete Algorithms, 1998, 316-322.[16] N. Sakamoto, Comparison of Initial Conditions for Distributed Algorithms on AnonymousNetworks, Proc. 18th ACM Symp. on Principles of Distributed Computing, 1999, 173{179.[17] M. Yamashita and T. Kameda, Computing on anonymous networks, Proc. 7th ACMSymp. on Principles of Distributed Computing, 1988, 117{130.[18] M. Yamashita and T. Kameda, Leader election Problem on networks in which proce-sor identity numbers are not distinct, IEEE Trans. Parallel and Distributed Systems,10(9):878{887, 1999.[19] M. Yamashita and T. Kameda, Computing on anonymous networks: Part I - charac-terizing the solvable cases, IEEE Trans. Parallel and Distributed Systems, 7(1):69{89,1996.

50