15
Noname manuscript No. (will be inserted by the editor) How much memory is needed for leader election Emanuele G. Fusco · Andrzej Pelc the date of receipt and acceptance should be inserted later Abstract We study the minimum memory size with which nodes of a network have to be equipped, in order to solve deterministically the leader election problem. Nodes are unlabeled, but ports at each node have ar- bitrary fixed labelings which, together with the topol- ogy of the network, can create asymmetries to be ex- ploited in leader election. We consider two versions of the leader election problem: strong LE in which exactly one leader has to be elected, if this is possible, while all nodes must terminate in a state “infeasible” in the case of failure, and weak LE, which differs from strong LE in that no requirement on the behavior of nodes is imposed, if leader election is impossible. Nodes are modeled as identical automata and we ask what is the minimum amount of memory of such an automaton to enable leader election. We show that logarithmic memory is optimal for both strong and weak leader election in the class of arbitrary connected graphs. By contrast we show that A preliminary version of this paper appeared in the Pro- ceedings of the 24th International Symposium on Distributed Computing (DISC 2010), LNCS 6343. This work was done during the visit of Emanuele G. Fusco at the Research Chair in Distributed Computing of the Univer- sit´ e du Qu´ ebec en Outaouais. Andrzej Pelc was partially supported by NSERC discovery grant and by the Research Chair in Distributed Computing at the Universit´ e du Qu´ ebec en Outaouais. E. G. Fusco Computer Science Department, Sapienza, University of Rome, 00198 Rome, Italy. E-mail: [email protected] A. Pelc epartement d’informatique, Universit´ e du Qu´ ebec en Outaouais,Gatineau, Qu´ ebec J8X 3X7, Canada. E-mail: [email protected] strong LE can be accomplished in the class of trees of maximum degree Δ using only O(log log Δ) bits of memory, thus proving an exponential gap in memory requirements for leader election between the class of trees and the class of arbitrary graphs. Keywords Leader election · anonymous graphs · memory 1 Introduction Leader election is a well-known problem in distributed computing, first posed in [28]. Every node of a net- work has a boolean variable initialized to 0, and after the election, exactly one node, called the leader, should change this value to 1. If nodes of the network have dis- tinct labels, then leader election is always possible (e.g., the node with the largest label can become a leader). However, nodes may refrain from revealing their iden- tities, e.g., for security reasons. Hence it is desirable to have leader election algorithms that do not rely on node identities but exploit asymmetries of the network due to its topology and to port labelings. The amount of memory needed to solve distributed and network problems is a topic extensively studied in the literature, for such tasks as, e.g., network explo- ration [9,16,23,33], routing [14,15] and rendezvous [17, 18,27]. Somewhat surprisingly, leader election has not been studied in this context. In this paper we study the minimum memory size with which nodes of a network have to be equipped for solving deterministically the leader election problem. A network is modeled as an undirected connected graph. We assume that nodes are unlabeled, but ports at each node have arbitrary fixed labelings 0,...,d - 1, where d is the degree of the node. We do not assume any coherence between port labelings at various nodes.

How much memory is needed for leader election

Embed Size (px)

Citation preview

Noname manuscript No.(will be inserted by the editor)

How much memory is needed for leader election

Emanuele G. Fusco · Andrzej Pelc

the date of receipt and acceptance should be inserted later

Abstract We study the minimum memory size withwhich nodes of a network have to be equipped, in orderto solve deterministically the leader election problem.Nodes are unlabeled, but ports at each node have ar-bitrary fixed labelings which, together with the topol-ogy of the network, can create asymmetries to be ex-ploited in leader election. We consider two versions ofthe leader election problem: strong LE in which exactlyone leader has to be elected, if this is possible, whileall nodes must terminate in a state “infeasible” in thecase of failure, and weak LE, which differs from strongLE in that no requirement on the behavior of nodesis imposed, if leader election is impossible. Nodes aremodeled as identical automata and we ask what is theminimum amount of memory of such an automaton toenable leader election.

We show that logarithmic memory is optimal forboth strong and weak leader election in the class ofarbitrary connected graphs. By contrast we show that

A preliminary version of this paper appeared in the Pro-ceedings of the 24th International Symposium on DistributedComputing (DISC 2010), LNCS 6343.

This work was done during the visit of Emanuele G. Fusco atthe Research Chair in Distributed Computing of the Univer-site du Quebec en Outaouais.

Andrzej Pelc was partially supported by NSERC discoverygrant and by the Research Chair in Distributed Computingat the Universite du Quebec en Outaouais.

E. G. FuscoComputer Science Department, Sapienza, University ofRome, 00198 Rome, Italy.E-mail: [email protected]

A. PelcDepartement d’informatique, Universite du Quebec enOutaouais,Gatineau, Quebec J8X 3X7, Canada.E-mail: [email protected]

strong LE can be accomplished in the class of treesof maximum degree ∆ using only O(log log∆) bits ofmemory, thus proving an exponential gap in memoryrequirements for leader election between the class oftrees and the class of arbitrary graphs.

Keywords Leader election · anonymous graphs ·memory

1 Introduction

Leader election is a well-known problem in distributedcomputing, first posed in [28]. Every node of a net-work has a boolean variable initialized to 0, and afterthe election, exactly one node, called the leader, shouldchange this value to 1. If nodes of the network have dis-tinct labels, then leader election is always possible (e.g.,the node with the largest label can become a leader).However, nodes may refrain from revealing their iden-tities, e.g., for security reasons. Hence it is desirable tohave leader election algorithms that do not rely on nodeidentities but exploit asymmetries of the network dueto its topology and to port labelings.

The amount of memory needed to solve distributedand network problems is a topic extensively studied inthe literature, for such tasks as, e.g., network explo-ration [9,16,23,33], routing [14,15] and rendezvous [17,18,27]. Somewhat surprisingly, leader election has notbeen studied in this context. In this paper we study theminimum memory size with which nodes of a networkhave to be equipped for solving deterministically theleader election problem.

A network is modeled as an undirected connectedgraph. We assume that nodes are unlabeled, but portsat each node have arbitrary fixed labelings 0, . . . , d−1,where d is the degree of the node. We do not assumeany coherence between port labelings at various nodes.

2 Emanuele G. Fusco, Andrzej Pelc

Nodes are modeled as identical automata that commu-nicate with each other along links of the network, andwe ask what is the minimum amount of memory of suchan automaton to enable deterministic leader election.We consider two versions of the leader election prob-lem: strong LE and weak LE. In strong LE one leaderhas to be elected whenever this is possible, while allnodes must terminate in a state “infeasible” in the caseof failure. Weak LE differs from strong LE in that no re-quirement on the behavior of nodes is imposed, if leaderelection is impossible.

1.1 Our results.

We show that logarithmic memory is optimal for leaderelection in the class of arbitrary connected graphs. WeakLE can be achieved with O(log n) bits of memory forall connected graphs with at most n nodes and strongLE can be achieved with O(log n) bits of memory for allconnected graphs with exactly n nodes (none of theseassumptions can be entirely removed). On the otherhand, we show that Ω(log n) bits of memory are nec-essary to enable leader election even for the class ofrings. By contrast we show that strong LE can be ac-complished in trees of maximum degree ∆ using onlyO(log log∆) bits of memory, without any additional in-formation. This proves an exponential gap in memoryrequirements for leader election between the class oftrees and the class of arbitrary graphs. Moreover, weprove that no automaton can solve the leader electionproblem for all trees, even in the weak form.

1.2 Related work.

Leader election was first studied for rings, under theassumption that all labels are distinct. A synchronousalgorithm, based on comparisons of labels, and usingO(n log n) messages was given in [21]. It was provedin [19] that this complexity is optimal for comparison-based algorithms. On the other hand, the authors showedan algorithm using a linear number of messages but re-quiring very large running time. An asynchronous al-gorithm using O(n log n) messages was given, e.g., in[32] and the optimality of this message complexity wasshown in [4]. Leader election in radio networks has beenstudied, e.g., in [22,24,30] and randomized leader elec-tion, e.g., in [35].

Many authors [1,2,3,11,25,26,34,36,38] studied var-ious computing problems in anonymous networks. Inparticular, [8,38] characterize networks in which leaderelection can be achieved when nodes are anonymous. In[37] the authors study the problem of leader election ingeneral networks, under the assumption that labels are

not unique. They characterize networks in which thiscan be done and give an algorithm which performs elec-tion when it is feasible. They assume that the number ofnodes of the network is known to all nodes and do notattempt to minimize the number of messages. In [13]the authors study feasibility and message complexityof sorting and leader election in rings with nonuniquelabels, while in [12] the authors provide algorithms forthe generalized leader election problem in rings with ar-bitrary labels, unknown (and arbitrary) size of the ringand for both synchronous and asynchronous communi-cation. In [20] the leader election problem is approachedin a model based on mobile agents. Characterizationof feasible instances for the leader election prob-lem have been provided in [5,6,7].

Memory size needed for tree canonizaton, a task re-lated to symmetry breaking in tree networks, has beeninvestigated in [29]. The author shows a centralized al-gorithm, deciding whether two directed trees are iso-morphic or not, that works in logarithmic space. Tothe best of our knowledge, the present paper is the firststudy of the memory size of nodes required for leaderelection in arbitrary networks.

1.3 The model.

The network is modeled as an undirected connectedgraph whose nodes are unlabeled, but ports at eachnode v have arbitrary fixed labelings 0, . . . , d(v) − 1,where d(v) is the degree of the node. Unless otherwisespecified, we will use the term “graph” to mean a graphwith the above properties. Each node is a copy of thesame input/output automaton A which is a quadru-ple (S, Q, π, λ), where S is a finite set of states, Q isthe input/output alphabet, π : S × Q −→ S is thestate transition function, and λ : S −→ Q is the out-put function. The alphabet Q is the set of finite se-quences each of whose terms is a finite binary sequencecalled a message. All nodes start in the same state S0,called the initial state. Computations in the networkare organized in asynchronous phases. Consider a nodev that is in state S at the beginning of some phase. Letλ(S) = (m0,m1, . . . ,mn) be the sequence of messagescorresponding to state S (some of the messages mi maybe equal to the empty message θ: this is a reserved stringof bits. Node v sends message mi on port i, for all portsi = 0, . . . , d(v)−1. (All messages mi, for i ≥ d(v) are ig-nored.) After sending, node v waits until a message m′i(possibly empty) arrives on each port i = 0, . . . , d(v)−1.The sequence σ = (m′0, . . . ,m

′d(v)−1) becomes an input

symbol, under the influence of which node v transits tostate S′ = π(S, σ). This ends the current phase for nodev and at the beginning of the next phase node v is instate S′. There are three pairwise disjoint sets of states

How much memory is needed for leader election 3

included in S: the sets L, N and U . States in L arecalled leader states, states in N are called non-leaderstates, and states in U are called infeasible states. Oncea node enters a state in one of these sets, it remains for-ever in the set (although it may change states). Moreformally, for any σ ∈ Q and any states S′ ∈ L, S′′ ∈ Nand S′′′ ∈ U , we have π(S′, σ) ∈ L, π(S′′, σ) ∈ N andπ(S′′′, σ) ∈ U . For a given network, the task of leaderelection (LE) consists in the following: all nodes exceptone eventually enter a non-leader state, and one nodeeventually enters a leader state.

We say that LE is possible for a given network, ifthere exists an algorithm which solves LE for any ad-versary modeling asynchrony of message transmissions.

We consider two versions of the leader election taskfor a class C of graphs :• Weak LE. Let G be any graph in class C. If leaderelection is possible for the graph G, then LE is accom-plished.• Strong LE. Let G be any graph in class C. If leaderelection is possible for the graph G, then LE is accom-plished. If leader election is impossible for the graph G,then either LE is accomplished or all nodes eventuallyenter an infeasible state. Note that even in instanceswhen LE is impossible (i.e., by definition, it cannot bedone against all adversaries), some adversary may stillallow the election of a unique leader, whence the some-what paradoxical situation when LE can be sometimesperformed although it is impossible.

Hence weak LE differs from strong LE in that, in thecase of impossibility of leader election, no restriction onthe behavior of nodes is imposed: they can stop in anarbitrary state, or arbitrarily circulate through the setof states. In Section 2 we explain precisely when leaderelection is possible.

We say that an automaton A solves weak (resp.strong) LE in the class C of graphs, if the respectivetask can be carried out for every graph of the class C inwhich copies of A are placed in every node, under anyadversarial scheduling of message deliveries.

We seek automata with small memory, measured bythe number of states, or equivalently by the number ofbits on which these states can be encoded. An automa-ton with K states requires Θ(logK) bits of memory.

2 Preliminaries

We will use the following notion from [38]. Let G be agraph and v a node of G. The view from v is the infiniterooted tree V(v) with labeled ports, defined recursivelyas follows. V(v) has the root x0 corresponding to v.For every node vi, i = 1, . . . , k, adjacent to v, thereis a neighbor xi in V(v) such that the port numberat v corresponding to edge v, vi is the same as the

port number at x0 corresponding to edge x0, xi, andthe port number at vi corresponding to edge v, viis the same as the port number at xi correspondingto edge x0, xi. Node xi, for i = 1, . . . , k, is now theroot of the view from vi. By Vt(v) we denote the viewV(v) truncated to depth t. We will use the followingpropositions directly following from [31,38].

Proposition 1 For a n-node graph, V(u) = V(v), ifand only if Vn−1(u) = Vn−1(v).

Proposition 2 Let u and v be two nodes in a graph G,such that V(u) = V(v). Let (a1, . . . , ak) be a sequenceof port numbers in G and let u′ and v′ be nodes in G,such that a path from u to u′ and a path from v to v′

correspond to the sequence (a1, . . . , ak). Then V(u′) =V(v′).

The following proposition (implied by the resultsin [38]) expresses the feasibility of leader election interms of views.

Proposition 3 Leader election is possible in a graphG, if and only if views of all nodes are different.

Proposition 3 establishes the uniqueness of views asa necessary and sufficient condition on the feasibility ofleader election. We will show in this paper that if thiscondition is satisfied, then weak LE can be performedin the class of all graphs with at most n nodes usingO(log n) bits of memory at each node. Observe thatsome bound on the size of the graphs in which leaderelection is to be performed is necessary: otherwise evenweak LE cannot be done, regardless of memory size. In-deed, it follows from Theorem 2 proved in Section 3 thatno automaton can solve even weak LE in the class ofall cycles. On the other hand, we will show that strongLE is feasible in all graphs with exactly n nodes usingO(log n) bits of memory at each node. Here we use astrong assumption that the number of nodes is known.Notice that this assumption cannot be weakened evento knowing a linear bound on the size of the graph. In-deed, consider the following well-known example. Thereare two cycles: a k-node cycle C = (v1, . . . , vk) and a(2k)-node cycle C ′ = (w1, . . . , wk, w

′1, . . . , w

′k) with the

following port labelings. In cycle C, at node v1 port0 corresponds to edge v1, v2, and at every node vi,for i > 1, port 0 corresponds to edge vi−1, vi. In cy-cle C ′ at nodes w1 and w′1 port 0 corresponds to edgew1, w2 (resp. w′1, w′2) and at every node wi and w′i,for i > 1, port 0 corresponds to edge wi−1, wi (resp.w′i−1, w

′i). It is easy to see that if the adversary sched-

ules synchronous computations, nodes wi and w′i in cy-cle C ′ will be always in the same state as node vi inthe cycle C (of course the labels are not known to thenodes and are used only for the description). Hence the

4 Emanuele G. Fusco, Andrzej Pelc

solvability of strong LE in the class consisting of thesetwo cycles (whose sizes differ only by a factor of 2) isimpossible: an automaton providing a solution for C(where leader election is possible) will incorrectly electtwo leaders in C ′ (where leader election is impossible),instead of stopping in an infeasible state.

In the sequel we will use the notion of a UniversalExploration Sequence (UXS) [23]. Let (a1, a2, . . . , ak)be a sequence of integers. An application of this se-quence to a graph G at node u is the sequence of nodes(u0, . . . , uk+1) obtained as follows: u0 = u, u1 is theneighbor of u0 such that the port at u0 correspondingto edge u0, u1 has number 0; for any 1 ≤ i ≤ k, ui+1

is the neighbor of ui such that the port number at ui

corresponding to the edge ui, ui+1 is (p + ai) modd(ui), where p is the port number at ui correspond-ing to the edge ui, ui−1. A sequence (a1, a2, . . . , ak)whose application to a graph G at any node u containsall nodes of this graph is called a UXS for this graph.A UXS for a class G of graphs is a UXS for all graphsin this class.

The following important result, based on a reduc-tion from Koucky [23], is due to Reingold [33].

Proposition 4 [33] For any positive integer n, thereexists a UXS Y (n) = (a1, a2, . . . , ak) for the class Gn ofall graphs with at most n nodes, such that:• k is polynomial in n,• for any i ≤ k, the integer ai can be constructed usingO(log n) bits of memory.

The above result implies that a (usually non-simple)path (u0, . . . , uk+1) traversing all nodes can be com-puted (node by node) using O(log n) bits of memory,for any graph with at most n nodes. Moreover, loga-rithmic memory suffices to walk back and forth on thispath: to walk forward at node ui, port (p + ai) modd(ui) should be computed when coming by port p, towalk backward, port (p−ai) mod d(ui) should be com-puted.

For a fixed UXS (a1, a2, . . . , ak) and a node u ofa graph G, the signature of node u is the sequenceS(u) = ((b1, b′1) . . . , (bk+1, b

′k+1)) of pairs of integers,

such that bi is the port number at node ui−1 corre-sponding to the edge ui, ui−1, and b′i is the port num-ber at node ui corresponding to the edge ui, ui−1,where (u0, . . . , uk+1) is the application of the UXS (a1,a2, . . . , ak) to graph G at node u. Thus S(u) is the se-quence of pairs of port numbers corresponding to tra-versed edges in the walk starting at node u and con-structed using the UXS (a1, a2, . . . , ak).

Using Proposition 4, the following result has beenproved in [10].

Proposition 5 [10] Let Y (n2 + n) be a UXS for theclass Gn2+n of all graphs with at most n2 + n nodes,

satisfying Proposition 4. Let G be a graph with at mostn nodes. For every node u of G, let S(u) be the signatureof u corresponding to the UXS Y (n2+n). Then, for anynodes u1, u2 of G we have V(u1) 6= V(u2), if and onlyif S(u1) 6= S(u2).

3 Leader election in arbitrary graphs

3.1 Weak Leader Election

We first provide an intuitive description of our algo-rithm that solves weak LE in logarithmic memory. Ifnodes had large memories they could discover theirwhole signatures and then exchange them with all othernodes in the network. By Propositions 3 and 5, if leaderelection is possible, then all signatures must be differ-ent. When each node has compared its signature withsignatures of all other nodes, a leader can be elected byselecting the node with the smallest signature in lexi-cographic order.

Since in our case the memory of a node is much toosmall to store an entire signature, the basic idea of ouralgorithm is to perform this comparison term by term,so that each node needs to recall the step of the compar-ison it is performing and two values only. This is madepossible by exploiting universal exploration sequencesfrom [33].

Fix n and denote by Y the UXS Y (n2 + n) fromProposition 5. Let Y [i] denote the i-th term of Y . LetG be any graph with at most n nodes. For every node u,let S(u) be the signature of u corresponding to Y . Wedenote by S(u)[i] the i-th term of the signature S(u).The length of Y is denoted by |Y |.

Now fix nodes u and v. Let (p, p′) = S(u)[1]. Nodeu compares (p, p′) with S(v)[1] (this can be done by anappropriate exchange of messages between u and v). Ifthe two values coincide, node u proceeds to compare thesecond term of its signature with the second term of thesignature of v. The comparison proceeds for |Y | stepsor up to the time when two distinct values are found inthe signatures. If S(v) precedes S(u) in lexicographicorder, u gives up comparing its signature with othernodes and becomes a non-leader. If S(u) precedes S(v)in lexicographic order, or the two signatures are equal,node u remains a leader candidate, and starts compar-ing its signature with the signature of the next node inthe application of Y at u. Node u becomes the leader, ifit did not give up after |Y | signature comparisons. No-tice that n− 1 comparisons are not enough, indeed theUXS can induce loops and thus some comparisons mayresult in comparing the signature of a node with itself.After |Y | signature comparisons, a node is guaranteedto have compared its signature with those of all othernodes, in view of the properties of Y .

How much memory is needed for leader election 5

The main problem in comparing signatures in thisway is the congestion caused by simultaneous execu-tion of this task in all nodes of the network. Indeed,a node of large degree could simultaneously receive arequest from each of its neighbors. Even in a networkof constant maximum degree a node that is a crossingpoint of many paths defined by the UXS could receiveup to Θ(n) simultaneous requests. Handling linearlymany requests simultaneously would require exponen-tially many states.

To solve this problem, we implement a policy thatallows each node to handle only one request per phase,by selecting the one with the smallest rank in lexico-graphic order and annihilating all others. Hence, manyrequests for getting a given element of a signature willbe lost and will have to be sent again. Nevertheless weprove that eventually every node receives a reply to allits requests.

The algorithm

We first define the annihilating policy as a procedurewhich specifies which message survives when a nodereceives some input. Notice that this policy is imple-mented by correctly defining the transition function πof the automaton and does not require any additionalstate. If a node u receives more than one non-emptymessage in a phase, it purges its input by calling Pro-cedure annihilate. All non-empty messages sent in theexecution of the algorithm have at least two fields calledfield 1 and field 2.

Procedure annihilateLet M be the set of non-empty messages received bynode u in a given phase. The message m ∈M that sur-vives is the one with the smallest rank in lexicographicorder over field 1, field 2, and the incoming port num-ber. Node u considers this unique message (and emptymessages on other ports) as its input in the given phase.

From now on we assume that a node receives atmost one non-empty message in each phase. When nomessage is specified to be sent by a node on a givenport in a given phase, the message sent on that port isthe empty message.

The following procedure is the building block of ouralgorithms for LE.

Procedure get(i, k)Request messages, sent during the execution of Pro-cedure get(i, k), have eight fields.Field 1 contains the distance between the originatorand the target from which information is sought. Thedistance is counted along two distinct applications of

Y . The first application, called path A, is at the origi-nator u and is used for the first i steps, up to a givennode v. The second application, called path B, is at vand is followed for k steps up to the target node t (seeFigure 1).Field 2 contains the overall number of nodes that stillhave to relay the message.Field 3 contains the distance between node v and thetarget node t from which information is sought, countedalong path B.Field 4 contains the number of nodes in path B thatstill have to relay the message.Field 5 contains the distance between node u and nodev, counted along path A.Field 6 contains the number of nodes in path A thatstill have to relay the message.Field 7 will contain the entry port r on path A at nodev.Field 8 will contain the pair of port numbers (q, q′) thatis the information sought at the target t.

Procedure get(i, k) is initiated by a node u by send-ing a request messagem =< k+i, 2(k+i)−1, k, 2k, i, 2i−1, ∗, (0, ∗) > through port 0. When a node w receivesa request message m =< k + i, x, k, y, i, z, r, (q, q′) >from port p, it proceeds as follows.1. if z > i, then node w is on path A and relays mes-sage m forward along this path by sending messagem′ =< k + i, x − 1, k, y, i, z − 1, ∗, (p′, ∗) > throughport p′ = p+ Y [2i− z] mod d(w);2. if z = i and y = 2k, then node w is equal to v.It relays message m forward along path B by send-ing message m′ =< k + i, x − 1, k, y − 1, i, i, p, (0, ∗) >through port 0;3. if z = i and 2k > y > k, then node w is in path Band relays message m forward along this path by send-ing message m′ =< k + i, x− 1, k, y − 1, i, i, r, (p′, ∗) >through port p′ = p+ Y [2k − y] mod d(w);4. if z = i and y = k, then node w is the target nodet. It relays message m backward along path B by send-ing message m′ =< k + i, x − 1, k, y − 1, i, i, r, (q, p) >through port p;5. if z = i and 0 < y < k, then node w is in path B andrelays message m backward along this path by send-ing message m′ =< k + i, x− 1, k, y − 1, i, i, r, (q, q′) >through port p− Y [y] mod d(w);6. if z = i and y = 0, then node w is equal to v. It relaysmessage m backward along path A by sending messagem′ =< k+ i, x−1, k, 0, i, z−1, ∗, (q, q′) > through portr;7. if 0 < z < i, then node w is in path A and relaysmessage m backward along this path by sending mes-sage m′ =< k+ i, x− 1, k, 0, i, z− 1, ∗, (q, q′) > throughport p− Y [z] mod d(w);8. if z = y = x = 0, node w is equal to u and value (q, q′)

6 Emanuele G. Fusco, Andrzej Pelc

Path B: application of Y at v (k steps)

u

v

tq′

Path A: application of Y at u (i steps)r

q

Fig. 1 Route of message m in Procedure get(i, k) from node u. (Notice that nodes are not necessarily distinct.)

is the k-th element of the signature of node v. The re-quest has thus been replied. The outcome of Procedureget(i, k) for node u is the value of S(v)[k], where v isthe i-th node in the application of Y at u.

Procedure get(i, k) allows a node u to obtain thek-th term of the signature of the i-th node in the appli-cation of Y at u. The procedure is defined for parame-ters i ≥ 0 and k > 0. In particular, get(0, k) allows anode to obtain the k-th term of its own signature.

We now provide a detailed description of the algo-rithm using the above procedure.

Algorithm Weak Leader ElectEach node maintains two counters, k and i, initializedto 1. Counters track the step in the signature compar-ison process. In phase 0, each node initiates Procedureget(0, 1).• A node u that initiated get(0, k) and did not receiveyet a reply to its request, reinitiates get(0, k) in eachphase in which it receives only empty messages.• When a node u gets a reply in Procedure get(0, k),it stores S(u)[k] and initiates get(i, k).• A node that initiated get(i, k) and did not receiveyet a reply to its request, reinitiates get(i, k) in eachphase in which it receives only empty messages.•When a node u gets a reply in Procedure get(i, k), itcompares the outcome of the procedure, call it o, withS(u)[k]. If o < S(u)[k] (in lexicographic order), thennode u enters a non-leader state and it keeps partici-pating in the algorithm only by acting as a relay node.If o > S(u)[k] (in lexicographic order), then node uincreases counter i by 1, sets counter k to 1, and initi-ates get(0, 1). If o = S(u)[k] and k < |Y |, then nodeu increases counter k by 1, and initiates get(0, k). Ifk = |Y |, node u increases counter i by 1, sets counter kto 1, and initiates get(0, 1).• A node enters a leader state when its counter i reachesvalue |Y |+ 1. A node in a leader state keeps participat-ing in the algorithm only by acting as a relay node.

Lemma 1 Algorithm Weak Leader Elect elects aunique leader whenever it is possible.

Proof The correctness of the algorithm immediately fol-lows from Propositions 3 and 5, if all requests are replied.Hence, in order to prove the lemma, we have to showthat nodes get replies to all their requests after a finitenumber of trials.

We consider a message smaller than another, if field1 of the first message is smaller than field 1 of the secondmessage, or if fields 1 are equal and field 2 of the firstmessage is smaller than field 2 of the second message.

Let m be a message with minimum rank, in lexico-graphic order over field 1 and field 2, in a snapshot ofthe network at time t. Let t′ > t be the first time whenmessage m is either annihilated or relayed. Message mcan be annihilated, if and only if it collides in a givennode u with a smaller message m′ or with a messagewith the same values for field 1 and 2 that is comingfrom a port with smaller number.

Recall that, whenever a message is relayed by anode, the value of its second field is decreased by 1, thusproducing a new message m′ smaller than m. Hence, re-gardless of whether message m is annihilated or relayedat time t′, a message m′ smaller than m must exist inthe network at that time. Fields 1 and 2 of any messageare positive integers bounded by 2|Y | and 4|Y | − 1, re-spectively. Hence, after a finite amount of time, therewill be a message that cannot be annihilated, and thusthe originator of the request corresponding to this mes-sage will get a reply.

Since at most 2n|Y |2 requests need to be repliedduring an execution of the algorithm and, once a re-quest is replied, it is never sent again, all requests willbe replied after a finite number of trials, which provesthe lemma.

Since Algorithm Weak Leader Elect requires everynode to keep only constantly many counters of size log-arithmic in n, we get the following theorem.

Theorem 1 There exists an automaton with O(log n)bits of memory that solves weak LE in the class ofgraphs with at most n nodes.

We now provide a matching lower bound on thememory size required to solve weak LE, which holds

How much memory is needed for leader election 7

already on the class of rings, and is valid even for syn-chronous computations.

Theorem 2 An automaton with Ω(log n) bits of mem-ory is required to solve weak LE in the class of rings withat most n nodes.

Proof Consider a ring on three nodes (see Figure 2.a)such that nodes can be colored black, yellow, and greenrespecting the following three conditions:

1. port 0 of the black node leads to the yellow node;2. port 0 of the yellow node leads to the black node;3. port 0 of the green node leads to the yellow node.

Call this ring R3.LE obviously admits a solution in R3 as, e.g., the

black node is the only node that can receive messagessent both from port 0 and port 1 of its neighbors.

Let A be an automaton that solves weak LE in ringsof at most n nodes, for n ≥ 3. Let x be the number ofstates of A and suppose that 2x3 + 10 ≤ n. Considera synchronous execution given by automaton A in R3.Such an execution must elect a leader in R3 within x3

rounds. Indeed x3 is an upper bound on the number ofpossible state configurations of nodes in network R3.

Assume, without loss of generality, that the blacknode is elected as a leader in R3. Now consider thering obtained as follows. First construct a ring with2 · 3

⌈x3/3

⌉+ 6 ≤ 2x3 + 12 nodes whose nodes can be

colored black, yellow, and green respecting condition 1,2, and 3 above. Call this ring Rx (see Figure 2.b withdashed edges and nodes on the right-hand side). Thenremove from Rx one yellow node and the green nodeadjacent to it, connecting the two neighboring blacknodes by an edge (see Figure 2.b with the dashed partreplaced by a continuous edge). Call the obtained ringR′x. It has at most 2x3 + 10 nodes. In a synchronousexecution on ring Rx, all black nodes must be electedas leaders; indeed yellow, green and black nodes wouldget exactly the same messages in ring Rx as nodes withthe respective colors in ring R3.

On the other hand, LE admits a solution on ring R′x(as all nodes have distinct views). Thus automaton Ashould elect a unique leader in this ring, because the sizeof the ring is at most n. This is impossible, as two blacknodes exist in network R′x (namely, the two black nodeson the left-hand side of Figure 2.b) that are at distanceat least x3 from each of the two adjacent black nodes.Hence they would receive, in a synchronous execution inR′x, the same sequence of messages, as in a synchronousexecution in Rx, up to the round when all black nodeswould be elected as leaders in Rx. Hence, A cannotsolve weak LE in the class of rings with at most 2x3+10nodes, which proves the theorem.

3.2 Strong Leader Election

Algorithm Strong Leader Elect for solving strong LEin n-nodes networks can be obtained by making eachnode compare signatures of all other nodes, keepingcount of how many distinct ones it finds in the net-work. As different signatures correspond to differentviews, and leader election is possible in a network withn nodes, if and only if all nodes have different views,the feasibility of LE in a n-node graph is equivalent tothe existence of n distinct signatures. Algorithm WeakLeader Elect can then be applied, in solvable instances,in order to elect a unique leader.

We provide a detailed description of our algorithmfor strong LE, using the following procedure.

Procedure compare signatures(q, r)Node u compares the signature of the q-th node in theapplication of Y at u with the signature of the r-thnode in this application by repeatedly calling Proce-dure get(q, k) and get(r, k), for k ranging from 1 to|Y |, and comparing the received terms.

If the two signatures are equal, the outcome of Pro-cedure compare signatures(q, r) at node u is 0, oth-erwise it is 1.

Algorithm Strong Leader Elect

Stage 1: node u keeps a counter d and a counter r,both initialized to 1:

– node u compares the signature of the r-th node inthe application of Y at u with signatures of all nodesat distance less than r in this application, by repeat-edly calling Procedure compare signatures(i, r),for i ranging from 0 to r − 1;

– if the signature of the r-th node is different from allsignatures it has been compared with, then node uincreases counter d by 1;

– when i reaches value r − 1, r is increased by 1;– when r reaches value |Y |+ 1:

if d = n, then node u enters stage 2;If d < n, then node u enters an infeasible state.

Stage 2: execute Algorithm Weak Leader Elect.

It should be noted that different nodes could deter-mine at different times whether leader election is possi-ble or not in the given network. Hence, some node couldbe executing Algorithm Weak Leader Elect, while othernodes are still busy discovering that leader election ispossible in the given network. Interference between nodesexecuting stage 1 and nodes executing stage 2 of Al-gorithm Strong Leader Elect is avoided by lettingnodes still executing stage 1 treat messages from stage 2as empty messages. Nodes executing stage 2 also assignhigher priority to serving messages originated by nodes

8 Emanuele G. Fusco, Andrzej Pelc

1

1

0

0

1

0

b

y

g

0

0

0

1

1

01 1 1 01 1 1

0 1 0 0 0 1

g y bg y

0 0

y

g

3 · dx3/3e nodes

3 · dx3/3e nodes

y

0

0

00

1

0

0

1

b

11

b

g

b

y g b y g b

1

1

1

a b

Fig. 2 Rings R3, Rx, and R′x.

still executing stage 1. We omit the details of how tomodify Procedure annihilate in order to implementsuch a policy.

Lemma 2 Algorithm Strong Leader Elect elects aunique leader whenever it is possible. If leader electionis impossible, all nodes enter an infeasible state.

Proof By Proposition 5, LE admits a solution in a net-work, if and only if all nodes have distinct signatures.Counter d in Algorithm Strong Leader Elect is in-creased by 1, if and only if the recently checked signa-ture is different from all the already checked ones. Itfollows that each distinct signature is counted exactlyonce by any node u executing the algorithm, as long asall requests are replied. The argument from the proofof Lemma 1 shows that all requests are replied aftera finite number of trials in Algorithm Strong LeaderElect as well. Hence, upon completion of stage 1,counter d of a node has value n, if and only if LE isfeasible. This concludes the proof.

Algorithm Strong Leader Elect requires everynode to keep only constantly many counters of size log-arithmic in n, plus counters needed for executing Algo-rithm Weak Leader Elect. Hence, as a consequence ofTheorem 1, we get the following result.

Theorem 3 There exists an automaton with O(log n)bits of memory that solves strong LE in the classof graphs with exactly n nodes.

Notice that the lower bound Ω(log n) on the mem-ory size needed to solve weak LE for the class of graphswith at most n nodes (proved in Theorem 2) does notimmediately imply a similar lower bound for strong LEfor the class of graphs with exactly n nodes. Indeed,the argument used for weak LE relies on rings of differ-ent sizes, while in strong LE the automaton is designedfor a specific value of n. Nevertheless, a similar lowerbound, showing that the automaton from Theorem 3 isalso optimal, can be obtained as follows.

Proposition 6 An automaton with Ω(log n) bits ofmemory is required to solve strong LE in the class ofn-nodes rings.

Proof Assume, for contradiction, that an automaton Awith x states solves strong LE for the class of ringswith n nodes, where n > 2x + 1. Consider a ring Ron n nodes, where ports at the endpoints of each edgehave labels 0 and 1. Consider a synchronous executionscheduled by the adversary. Leader election in this ringis impossible, and since the synchronous adversary doesnot break the symmetry, strong LE requires all nodesin this ring to enter an infeasible state. Assume that acopy of automaton A is placed in all nodes of R andconsider a synchronous execution scheduled by the ad-versary. As all nodes in R are identical, they are alwaysin the same state. Hence, a repeated configuration ofstates is reached within x rounds. It follows that x isan upper bound on the round number when all nodesin R must enter an infeasible state. Now consider the

How much memory is needed for leader election 9

ring R′, obtained by inverting port labels of one node.Leader election is possible in this ring, however, nodesat distance larger than x from the node with invertedport labels would receive, in a synchronous executionin ring R′, the same sequence of messages as in a syn-chronous execution in ring R, up to the round whenthey entered an infeasible state in ring R. Hence thesenodes must enter an infeasible state in ring R′ as well,contradiction.

4 Leader election in trees

In this section we provide an upper bound O(log log∆)on the number of memory bits required to solve strongLE in trees with maximum degree ∆. We also show thatno automaton can solve even weak LE in all trees.

A tree T has a central node, if and only if, it haseven diameter D. The central node in this case is theunique node that is the starting point of (at least) twoedge disjoint paths of length D/2. If a tree T has odddiameter D, then it has a central edge. This unique edgeis the central edge of any path of length D in T . LE isalways possible in trees with a central node, while treeswith a central edge admit LE, if and only if, the twosubtrees rooted at the endpoints of the central edge arenot isomorphic1 (either because of differences in thetopology or different port labelings).

Consider the set T0 of rooted trees where each nodehas label 0 at the port leading to its parent. Such a n-node tree can be encoded by a binary string of length2n− 2. This is done by performing a depth-first visit ofthe tree, driven by increasing order of port numbers ateach node, and writing 1 every time an edge is traversedgoing down, and 0 every time an edge is traversed goingup. A tree T ∈ T0 can be reconstructed from its code asfollows. Start from the root, making it the current node.In every step of the reconstruction we have a suffix σ ofthe code and a current node v. In the first step σ is thecode. If the first element of σ is a 1, attach a new childto v, label the port connecting v to this child with thesmallest port number not yet assigned at node v. Alsoassign label 0 to the port at the child connecting it tov. The child becomes the current node at the next step.If the first element of σ is a 0, the parent of v becomesthe current node at the next step. In both cases, thefirst element of σ is removed.

A string s of length 2n − 2 belongs to the set Cnof well formed codes, if and only if it has n − 1 ones,n − 1 zeroes, and no prefix of s contains more zeroesthan ones. The coding and decoding functions describedabove define a bijection between the set Cn and the set

1 Rooted trees are isomorphic, if there exists a bijectionfrom nodes of one to nodes of the other that maps the rootto the root, preserving adjacencies and port numbers.

of all n-node trees in T0. This is a subset of the trees wewant to handle, as in general the port number leadingto the parent of a node v is arbitrarily chosen between0 and d(v) − 1. This difficulty can be overcome, thusdefining a bijection between the class of all rooted treeswith port numbers and their representations as codestrings, as follows. Consider an internal node w. Let ibe the port number, at w, of the edge connecting w toits parent. Let u be the child of w such that the edgebetween w and u has port number i+1 at w. Then addthe symbol into the code before the first visit to u.Denote such an augmented code of a tree T by B(T ).From now on it is called the code of T . As symbol hasbeen added to the code, resulting in a ternary alphabet,we use 2 bits to represent each symbol in code B(T )without ambiguities.

4.1 Strong LE in trees using O(log log∆) memory bits

We first give an overview of our algorithm. AlgorithmTree Leader Elect solving strong LE in trees has threestages. In stage 1, the tree is pruned, starting fromthe leaves, until only one node or one edge remains.If only one node remains after pruning, this node canbe elected as a leader. When the pruning ends on anedge, LE is possible, if and only if, the two subtreesrooted at the endpoints of the edge are not isomorphic.

Stage 2 determines, when the pruning ends on anedge, whether the two subtrees, rooted on the end-points of the unpruned edge, are isomorphic or not. Ifnot, a unique leader is elected, otherwise LE is impos-sible. Endpoints of the unpruned edge coordinate theprocess of comparing the two subtrees, however, thememory of each node is so small that it cannot evensave one port number. Hence, no single node can trackthe progress of the comparison on its own. Informationallowing to perform the comparison is thus distributedamong many nodes in the subtrees, so that no nodeneeds to store more than constantly many counters,whose values are bounded by log∆. The comparisonis done by performing a pre-order visit of each subtree;flags are used to identify nodes in the path from theroot of the subtree to the currently visited node, i.e.,the owner of the token. This owner is responsible forgenerating the next symbol of the augmented code ofthe subtree rooted in one of the endpoints of the un-pruned edge, and for sending it up to this endpoint.Each of the endpoints of the unpruned edge compareseach symbol received from its subtree with the corre-sponding symbol obtained from the other subtree. Iftwo mismatching symbols are found, the symmetry isbroken and a leader is elected, otherwise, each endpointresumes the visit of its subtree by broadcasting a re-quest for the next symbol to all its neighbors. Among

10 Emanuele G. Fusco, Andrzej Pelc

them, exactly one is flagged and will relay the requestdown the tree towards the current owner of the token.

While moving the token from a parent to its firstchild is easy, moving the token from a child to the nextchild, or determining that all children have been alreadyvisited and thus the token has to be sent back to theparent, is much harder, as port numbers determiningthe ranks of the children in the pre-order visit are toolarge to be kept in the memory of any single node.

Procedure Move Token, described below, is the fun-damental building block of the algorithm. The proce-dure allows to move the token from a child to the nextchild to be visited (or back to the parent when all chil-dren have been already visited), using only one counterof O(log log∆) bits at each node to enable the exe-cution of a distributed binary search among chil-dren.

In stage 3, success or impossibility of LE is broad-cast to all nodes, thus allowing non-leader nodes to cor-rectly enter a non-leader or an infeasible state, accord-ing to the outcome of the election.

Procedure Move TokenThe procedure is initiated by the parent w of the cur-rent owner v of the token.

We assume that either w is one of the endpoints ofthe central edge, or it has at least one neighbor that ismarked ascending (namely, its parent). This invariantwill hold at each call of the procedure in Algorithm TreeLeader Elect.

Each node u has a counter c(u) that is set to 0when the procedure is initiated. Let p(u) be the portnumber, at w, connecting w to node u. Moreover, letx be the number of bits allowed by the memory sizeto be assigned to a counter c(u). O(log log∆) memorybits are enough to guarantee 22x ≥ ∆, and this is allwe will need.

The following block of 4 phases is iterated 2x times,counted by c(w) ranging from 0 to 2x − 1. Nodes thatare candidates to obtain the token are all the neighborsu of w, having p(u) ≥ 1, that are not marked and donot own the token.1. In phase 1, node w sends message < c(w) > to allits neighbors. Each such message also carries thevalue p(u) corresponding to its destination nodeu.2. In phase 2, let k =

∑c(w)i=1 si22x−i, where s1 = 1

if p(v) ≥ 22x−1, s1 = 0 otherwise, and, for i > 1,si = 1 if p(v) ≥ 22x−i +

∑i−1j=1 sj22x−j , and si = 0 oth-

erwise. Node v sends message < large >, if p(v)− k ≥22x−c(w)−1. Otherwise it sends message < small >.3. In phase 3, node w relays the message, either <large > or < small >, received from v in phase 2,together with counter c(w). Then it increases counterc(w) by one.

4. In phase 4, for each candidate node u, we have k =∑c(w)i=1 si22x−i, where s1 = 1 if p(u)− 1 ≥ 22x−1, s1 = 0

otherwise, and, for i > 1, si = 1 if p(u) − 1 ≥ 22x−i +∑i−1j=1 sj22x−j , and si = 0 otherwise. If w sent mes-

sage < large, c(w) > in phase 3, each candidate node ustops being a candidate if p(u)− k− 1 < 22x−c(w)−1. Ifw sent message < small, c(w) > in phase 3, each can-didate node u stops being a candidate if p(u)− k− 1 ≥22x−c(w)−1.

After 2x iterations of the above block, the remainingcandidate node, if it exists, sends message < success >to all its neighbors and obtains the token. The nextphase is used by node w to inform its children (in par-ticular node v), if the token has been moved to the nextchild or not.

Procedure Move Token chooses the node u such thatp(u) = p(v)+1 as the new owner of the token, if such anode exists among children of the node w that initiatedthe procedure. The procedure can be easily modified tochoose the node u such that p(u) = p(v)+2, in the casewhen w is connected to its parent (i.e., its only neighbormarked ascending) through port p(v) + 1. This is doneby letting a candidate node u lose (i.e., stop being acandidate), in phase 4, if p(u) − k − 2 < 22x−c(w)−1

when a < large > message was sent by its parent, andif p(u)−k−2 ≥ 22x−c(w)−1, when a < small > messagewas sent by its parent. Values si, which determine k,are computed in this case as follows. s1 = 1 if p(u) −2 ≥ 22x−1, s1 = 0 otherwise, and, for i > 1, si = 1 ifp(u)− 2 ≥ 22x−i +

∑i−1j=1 sj22x−j , and si = 0 otherwise.

We now proceed to a detailed description of the al-gorithm using the above procedure.

Algorithm Tree Leader ElectThe algorithm has 3 stages.Stage 1 (Pruning).Nodes of the tree can be in three types of states: in-ternal, ready for pruning, and pruned. In phase 1 a leafenters a ready for pruning state while nodes of degreelarger than 1 enter an internal state. A node in an in-ternal state enters a ready for pruning state, when allits neighbors but one are in a pruned state.

A node u that enters a ready for pruning state inphase i enters a pruned state in phase i+ 1 if one of itsneighbors (i.e., its parent) remained internal in phasei. If the parent v also entered a ready for pruning state(i.e., one neighbor of u is ready for pruning and all oth-ers are pruned) in phase i, then edge (u, v) remainsunpruned and its endpoints start executing stage 2 ofthe algorithm.

A node u in an internal state in phase i becomesthe leader in phase i+ 1, if all its neighbors where in apruned state in phase i. In this case stage 2 is skipped,node u becomes the leader and broadcasts successfulelection to all other nodes in stage 3.

How much memory is needed for leader election 11

Stage 2 (Comparing).The endpoints of the unpruned edge coordinate the pro-cess of comparing their respective subtrees as follows.Nodes in stage 2 can be marked ascending, descending,or be unmarked. Moreover, exactly one node in eachsubtree can be the owner of the token.

In the first phase of stage 2, each endpoint of theunpruned edge offers the token to the node connectedthrough port 0. The token is accepted by this node (bymeans of an acknowledgement sent to all its neighborsin the next phase), unless the node is the other end-point of the unpruned edge. After reception of the ac-knowledgement from its child, the endpoint sends a codemessage < 1 > to all its neighbors and waits for the cor-responding message to be sent by the other endpoint.If the acknowledgement was not received, the endpointoffers the token to its child connected through port 1and sends a code message < 1 > to all its neighborsafter reception of the acknowledgement from this child.Then, the endpoint waits for the corresponding messageto be sent by the other endpoint.

After comparing two corresponding symbols of thecodes, each endpoint resumes the visit of its subtree bysending to all its neighbors a request for the next sym-bol. Among children of an endpoint, exactly one eitherowns the token, or is marked as descending. When adescending node receives a request for the next symbol,it marks itself as ascending and relays the request bysending it to all its neighbors. When the owner v ofthe token receives a request for the next symbol, it actsdifferently according to the following cases.

1. If v is a leaf, then it sends code message < 0 > toits parent, together with the token.

2. If v is an internal node that never received a requestfor the next symbol, it first offers the token to thenode connected through port 0. If this node is notmarked as ascending, it accepts the token and noti-fies v in the next phase. In this case, node v losesthe token, marks itself as descending, and sends codemessage < 1 > to all its neighbors. If port 0 con-nects node v to its parent, then v did not receivethe confirmation of acceptance of the token. If thisis the case, node v offers the token to the node con-nected through port 1. When this node accepts thetoken, node v loses it, marks itself as descending,and sends code message < 1 > to all its neighbors.Notice that since v is an internal node receiving arequest for the next symbol for the first time, eitherport 0 or port 1 connect v with one of its childrenthat has not been visited yet.

3. If v is an internal node that receives a subsequentrequest for the next symbol, v notifies its parentw, which in turn initiates Procedure Move Token. IfProcedure Move Token is successful, node w marks

itself as descending and sends code message < 01 >to all its neighbors. Otherwise, the modified versionof Procedure Move Token is initiated by w, tryingto move the token from the child connected throughport i to the one connected through port i+2. If themodified version of the procedure is successful, nodew marks itself as descending and sends code message< 0 1 > to all its neighbors. If both versions ofProcedure Move Token fail to assign the token to achild of w, then all children of w have been alreadyvisited. Hence, node w gets the token, and sendsthe code message < 0 > to all its neighbors. Whena node v loses the token, it unmarks itself.

Nodes marked as ascending that receive a code mes-sage, mark themselves as descending and relay the codemessage to their parent by sending it to all their neigh-bors.

Stage 2 ends with a successful election when the end-points of the unpruned edge receive two correspondingcode messages that do not match, or if one endpointreceives the token back from its last child while theother endpoint has still a code message to compare. Inthis case, the node with the lexicographically smallercode message (or the one that received the token back)becomes the leader. If both endpoints receive the to-ken back, the subtrees are isomorphic and thus leaderelection is impossible.

Stage 3 of the algorithm is initiated by the endpointsof the unpruned edge in order to broadcast the outcomeof the election to all nodes in their respective subtrees.

Stage 3 (Broadcasting).Broadcast the outcome of the election (elected/impos-sible) to all nodes in the tree. A node that gets mes-sage < elected > enters a non-leader state and a nodethat gets a message < impossible > enters an infeasiblestate.

Lemma 3 Let w be the parent of the current owner vof the token. Let j be the port number at w correspond-ing to edge w, v. Let v′ be the child of w such that portj + 1 at w corresponds to edge w, v′, if such a nodeexists. Procedure Move Token moves the token from vto v′.

Proof We prove by induction on iteration i = 0, . . . , 2x−1 in the procedure that ports p(u) of candidate nodesafter phase 4 of iteration i are integers in an interval oflength at most 22x−i−1. Moreover, if j = p(v), then thechild z of w such that p(z) = j + 1 is a candidate in alliterations, provided that it was a candidate in iteration0. As the length of the interval of candidate nodes is atmost 1 in iteration 2x − 1, the lemma will follow.

Assume that port j + 1 does not connect node w toits parent. Then node z (if it exists), is a candidate in

12 Emanuele G. Fusco, Andrzej Pelc

iteration 0. If j ≥ 22x−1, w relays a < large > messagein phase 3 of iteration 0, and in phase 4 of the itera-tion all nodes u such that p(u)− 1 < 22x−1 stop beingcandidates. If this is the case, j + 1 > 22x−1 and z re-mains a candidate. If j < 22x−1, w relays a < small >message in phase 3, and in phase 4 all nodes u suchthat p(u) − 1 ≥ 22x−1 stop being candidates. If thisis the case, j + 1 ≤ 22x−1 and z remains a candidate.In both cases values of p(u), for all candidate nodes u,range in an interval of length at most 22x−1 at the endof iteration 0. This completes the basis of the proof byinduction.

By the inductive hypothesis, after phase 4 of iter-ation i, z is a candidate node, and ports connecting wto the candidate nodes range in an interval of length atmost 22x−i−1. In particular, these port numbers are inan interval of the form [1+

∑i+1`=1 s`22x−`, 1+22x−i−1 +∑i+1

`=1 s`22x−`]. It follows that all candidate nodes com-pute the same value k computed by v in iteration i+ 1,and thus react properly to < small > and < large >messages by stopping being candidates in phase 4 of it-eration i+ 1, respectively if p(u)− k − 1 ≥ 22x−i−2, orif p(u)−k−1 < 22x−i−2. Hence the length of the inter-val of candidate nodes is at most 22x−i−2 and containsj + 1. This concludes the proof by induction.

Lemma 4 Algorithm Tree Leader Elect performsstrong LE in any tree.

Proof It is easy to see that stage 1 of Algorithm TreeLeader Elect correctly prunes the tree ending witheither a single node or a single edge. If a single noderemains, it is elected as a leader. When a single edgeremains after pruning, the endpoints of this edge com-pare the codes representing their subtrees, by segmentsof at most 3 symbols, when executing stage 2 of the al-gorithm. If the subtrees are not isomorphic, their codesare different, and this difference will eventually be dis-covered by both endpoints of the unpruned edge, thatwill thus agree on the leader. If the two subtrees areisomorphic, the comparison process will end withoutfinding any difference, thus allowing both endpoints ofthe unpruned edge to agree on the impossibility of LE.

Stage 3 of Algorithm Tree Leader Elect allows allnodes to learn the outcome of the election, both in thecase of success and in the case of impossibility, whichcompletes the proof.

Theorem 4 There exists an automaton withO(log log∆) bits of memory, that solves strong LE inthe class of trees with maximum degree at most ∆.

Proof Stages 1 and 3 of Algorithm Tree Leader Electrequire an automaton with only constantly many states.As for stage 2, the only task requiring more than con-stantly many memory bits is moving the token among

sibling nodes, by means of calls to ProcedureMove Token. All values exceeding log∆ (e.g., port num-bers) that appear in the description of Procedure MoveToken are handled by the state transition function ofthe automaton, and never need to be stored in the mem-ory of a node. Indeed, the procedure requires the par-ent w of the current owner of the token to store onlythe iteration number (which ranges from 0 to 2x − 1 ∈O(log∆)) and other nodes to remember only whetherthey are candidates or not. Hence O(log∆) states of theautomaton are enough, which implies that O(log log∆)memory bits are sufficient.

4.2 Impossibility of a universal leader electionautomaton for trees

In this section we prove the following impossibility re-sult which remains valid for strong LE as well.

Theorem 5 No automaton can solve weak LE in theclass of all trees.

Proof Assume, for contradiction, that an automaton Asolves weak LE in the class of all trees. Let C be thenumber of states of automaton A. Consider the follow-ing class of trees. A (h, k)-tree is a tree on h + k + 2nodes, obtained by connecting the central node of astar with h+ 1 nodes to the central node of a star withk + 1 nodes (see Figure 3 for an example of a (4, 3)-tree). Both ports corresponding to the edge connectingthe centers are labeled 0. Hence, LE is possible in a(h, k)-tree, if and only if h 6= k.

Call vh the node of degree h + 1 and vk the nodeof degree k + 1 in a (h, k)-tree. Call h-leaves the leavesconnected to vh and k-leaves the leaves connected tovk. lh,p denotes the h-leaf that is connected to node vh

by the edge whose corresponding port number at vh isp.

Suppose that copies of automaton A are placed inall nodes of the tree. The trace th,k(i) of node vh is thesequence of states of vh in a (h, k)-tree, up to phase i.The j-th term of this sequence, denoted by th,k[j], forj ≤ i, is the state of vh at the beginning of phase j.

The state of a given leaf lh,p at the beginning of agiven phase only depends on the trace of the centralnode vh to which the leaf is connected, up to the pre-vious phase.

For any automaton with C states, we can describethe transition function of a given h-leaf as a transitionmatrix mapping each pair of states (the state of vh andthe state of the h-leaf) to a new state of the h-leaf. Thismatrix has C2 cells; each cell of the matrix contains avalue chosen among the C possible states for the h-leaf. Hence at most X = CC2

distinct matrices exist.

How much memory is needed for leader election 13

0

0 0

0

0

0

12

34

21

3

0

0

0

l4,1

l4,2

l4,3

l4,4

v4 l3,2v3

l3,3

l3,1

Fig. 3 A (4, 3)-tree.

The value of p determines the transition matrix of theh-leaf lh,p. The leaf lh,p is equivalent to lh,q, denotedby lh,p ≡ lh,q, if lh,p and lh,q have the same transitionmatrix. Notice that two equivalent h-leaves are alwaysin the same state.

In a (h, h)-tree, traces th,h(i) of the two centers areequal, for any value i. Informally speaking, we can con-struct a transition function π′ whose input consists ofthe current state of node vh and messages from pair-wise non-equivalent h-leaves. We can then construct anautomaton A′ having π′ as its transition function. Nowconsider two (h, h)-trees. Tree T contains copies of au-tomaton A in all nodes. Tree T ′ contains copies of au-tomaton A′ in the central nodes and copies of automa-ton A in all leaves. The function π′ is such that, for allvalues i, traces th,h(i) of central nodes in T are equalto traces t′h,h(i) of central nodes in T ′.

Formally, let λ∗(S) = m0, where λ(S) = (m0,m1,. . . ,mh) is the sequence of messages that is the out-put corresponding to state S in automaton A. J ⊂S ×Q is the set of legal inputs defined as follows. σ =(S,m0,m1, . . . ,mh) is in J , if and only if (m0,m1, . . . ,mh) ∈ Q, m0 = λ∗(S), and mp = mq for each pair(p, q) such that lh,p ≡ lh,q. An input of function π forthe copy of automaton A placed in a central node of a(h, h)-tree is always legal. Indeed, the states of the twocentral nodes are equal in any phase and the states ofequivalent h-leaves are equal in any phase. Two nodesin the same state always send the same message on thesame port.

Hence we can define the following bijection α, whosedomain is the set J of legal inputs and whose set of val-ues J ′ has cardinality bounded by CX+1. Let α : J −→J ′, α((S,m0,m1, . . . ,mh)) = (λ∗(S),mz1 , . . . ,mzr ),where all integers zi are indices of pairwise non-equi-valent h-leaves and r ≤ X. As α is a bijection, we canalso define its inverse α−1 : J ′ −→ J .

Once function α has been defined, the transitionfunction π′ we are seeking can be constructed as follows.π′ : J ′ −→ S, π′(α(σ)) = π(α−1(α(σ))) = π(σ).

Now we can prove that CX+1 is an upper bound onthe number of reachable state configurations of nodesin a (h, h)-tree. Indeed, the existence of the bijection αshows that CX+1 is an upper bound on the cardinalityof the set of legal inputs, and we already proved thatthe input of each central node of a (h, h)-tree is legalin all phases. The upper bound CX+1 on the numberof distinct legal inputs in a central node was obtainedby counting as distinct those inputs that are producedby distinct configurations. This yields the upper boundCX+1 on the number of reachable state configurationsof one central node and of leaves adjacent to it. Sincein a (h, h)-tree centers are always in the same state andcorresponding leaves as well, we conclude that CX+1

is an upper bound on the number of reachable stateconfigurations of all nodes in a (h, h)-tree.

In any (h, h)-tree, traces with more than CX+1 termswill thus induce a repeated configuration of states ofall nodes. As CX+1 does not depend on the value h,infinitely many triples (a, b, c), with a < b < c, exist,such that ta,a(i) = tb,b(i) = tc,c(i), for any value i.Pick such a triple of integers. We will now prove, byinduction on j, that ta,b(j) = tb,a(j) = ta,a(j), for allvalues j. For j = 0, the base of induction holds, as thefirst term of any trace is the initial state of the automa-tonA. Assuming ta,b(j) = tb,a(j) = ta,a(j) we have thatta,b[j+ 1] = ta,a[j+ 1], since, by the inductive hypothe-sis, tb,a[j] = ta,a[j] and all a-leaves are in the same statein phase j in an (a, b)-tree as in an (a, a)-tree. Similarly,tb,a[j + 1] = tb,b[j + 1]. As ta,a(i) = tb,b(i) for any valuei, we have ta,b[j + 1] = tb,a[j + 1] = ta,a[j + 1], whichconcludes the proof by induction.

It follows that we can find three values, a < b < c,such that, for any assignment x = a, x = b, or x = cand any assignment y = a, y = b, or y = c, traces of thecentral nodes in a (x, y)-tree are always equal. Hence,for all (x, y)-trees, any x-leaf has the same state, in agiven phase, as the corresponding y-leaf (if it exists).Also the states of nodes vx and vy are equal in eachphase. Hence, neither an a-leaf nor a b-leaf can becomea leader, as this would cause election of two leaders in an

14 Emanuele G. Fusco, Andrzej Pelc

(a, c)-tree or in a (b, c)-tree. The same holds for nodesva and vb. On the other hand, weak LE requires elec-tion of a leader in an (a, b)-tree, contradiction. Hence,automaton A does not solve weak LE in the class of alltrees, and the proof of the theorem is complete.

The argument from the proof of Theorem 5 shows infact that an automaton with C states cannot solve weakLE in the class of trees of maximum degree CCC2

+1.This implies that the minimum number of memory bitsof an automaton solving weak LE for all trees of maxi-mum degree ∆ is Ω(log log log∆).

5 Conclusion

We gave upper and lower bounds on the number ofmemory bits at nodes, required to solve both strong andweak leader election. For arbitrary graphs these boundsare tight and they are Θ(log n) for n-node networks. Fortrees of maximum degree ∆ we gave an upper boundO(log log∆) and a lower bound Ω(log log log∆). Thisyields the following open problem.

What is the minimum number of memory bits ofan automaton that can solve weak (respectivelystrong) LE in the class of trees of maximum de-gree ∆?

A problem related to strong LE is to identify im-possible instances, i.e., instances for which, for any al-gorithm there exists an adversary that makes this algo-rithm fail accomplishing LE. (Recall that even for suchinstances, LE can sometimes be accomplished againstsome asynchronous adversaries.) While in our algorithmfor arbitrary graphs all nodes enter an infeasible statefor any adversary in all impossible instances, this is notthe case for our algorithm for trees. (Our algorithm can“accidentally” elect a leader in an impossible instance,due to the “help” of some adversaries.) Applying our al-gorithm for general graphs to n-node trees, would allowto recognize impossible instances using Θ(log n) mem-ory bits. However, the following modification of our al-gorithm for trees permits to recognize impossible in-stances using only O(log log∆) memory bits for treesof maximum degree ∆.

Procedure Move Token allows us to perform a visitof a tree starting from a given node u using O(log log∆)memory bits. If an execution of Algorithm Tree LeaderElect successfully elects a leader u, Procedure MoveToken can then be used to repeatedly apply Stage 2 ofAlgorithm Tree Leader Elect using each edge of thetree as the unpruned edge. LE is impossible, if and onlyif, some execution of this stage results in a failure (theedge unpruned in this execution is the central edge andjoins two isomorphic subtrees).

In this paper we focused on the size of memory,while most of the literature was concerned with timeand message complexity of leader election. This yieldsthe following problem.

What are the tradeoffs between memory size atnodes and time or message complexity of leaderelection?

References

1. H. Attiya, M. Snir and M. Warmuth, Computing on anAnonymous Ring, Journal of the ACM 35, (1988), 845–875.

2. H. Attiya and M. Snir, Better Computing on the Anony-mous Ring, Journal of Algorithms 12, (1991), 204–238.

3. P. Boldi and S. Vigna, Computing anonymously with ar-bitrary knowledge, Proc. 18th ACM Symp. on Principlesof Distributed Computing, 1999, 181–188.

4. J.E. Burns, A formal model for message passing systems,Tech. Report TR-91, Computer Science Department, In-diana University, Bloomington, September 1980.

5. J. Chalopin, Local Computations on Closed UnlabelledEdges: The Election Problem and the Naming ProblemSOFSEM 2005: Theory and Practice of Computer Science,82–91.

6. J. Chalopin, A.W. Mazurkiewicz, and Y. Metivier, La-belled (Hyper)Graphs, Negotiations and the NamingProblem. Proc. 4th international conference on GraphTransformations (ICGT 2008), 54–68.

7. J. Chalopin, Y. Metivier, Election and Local Computa-tions on Edges. Proc. Foundations of Software Science andComputation Structures (FoSSaCS 2004), 90–104.

8. B. Codenotti, P. Gemmell, J. Simon, Symmetry breakingin anonymous networks: characterizations, Proc. 4th IsraelSymposium on Theory of Computing and Systems, (ISTCS1996), 16–26.

9. S. A. Cook and C. Rackoff. Space Lower Bounds for MazeThreadability on Restricted Machines. SIAM J. Comput.9 (1980), 636–652.

10. J. Czyzowicz, A. Kosowski and A. Pelc, How to meetwhen you forget: Log-space rendezvous in arbitrarygraphs, Proc. 29th ACM Symp. on Principles of Dis-tributed Comp. (PODC 2010), 450–459.

11. K. Diks, E. Kranakis A. Malinowski and A. Pelc, Anony-mous wireless rings, Theoretical Computer Science 145(1995), 95–109.

12. S. Dobrev and A. Pelc, Leader election in rings withnonunique labels, Fundamenta Informaticae 59 (2004),333–347.

13. P. Flocchini, E. Kranakis, D. Krizanc, F.L. Luccio and N.Santoro, Sorting Multisets in Anonymous Rings, Proc. ofthe IEEE International Parallel and Distributed ProcessingSymposium (IPDPS 2000), Cancun, Mexico, (2000), 275–280.

14. P. Fraigniaud and C. Gavoille. Routing in Trees. Proc.28th Int. Colloquium on Automata, Languages and Program-ming (ICALP 2001), 757–772.

15. P. Fraigniaud and C. Gavoille. A Space Lower Bound forRouting in Trees. Proc. 19th Annual Symp. on TheoreticalAspects of Computer Science (STACS 2002), 65–75.

16. P. Fraigniaud and D. Ilcinkas. Digraphs Exploration withLittle Memory. Proc. 21st Symp. on Theoretical Aspects ofComp. Science (STACS 2004), 246–257.

How much memory is needed for leader election 15

17. P. Fraigniaud, A. Pelc, Deterministic rendezvous in treeswith little memory, Proc. 22nd International Symposiumon Distributed Computing (DISC 2008), 242–256.

18. P. Fraigniaud, A. Pelc, Delays induce an exponentialmemory gap for rendezvous in trees, Proc. 22nd Ann.ACM Symposium on Parallel Algorithms and Architectures(SPAA 2010), 224–232.

19. G.N. Fredrickson and N.A. Lynch, Electing a leader in asynchronous ring, Journal of the ACM 34 (1987), 98–115.

20. M. A. Haddar, A. H. Kacem, Y. Metivier, M. Mosbah,M. Jmaiel, Electing a leader in the local computationmodel using mobile agents. Proc. 6th ACS/IEEE Interna-tional Conference on Computer Systems and Applications(AICCSA 2008), 473–480.

21. D.S. Hirschberg, and J.B. Sinclair, Decentralizedextrema-finding in circular configurations of processes,Communications of the ACM 23 (1980), 627–628.

22. T. Jurdzinski, M. Kutylowski, J. Zatopianski, Efficient al-gorithms for leader election in radio networks. Proc., 21stACM Symp. on Principles of Distr. Comp. (PODC 2002),51–57.

23. M. Koucky, Universal Traversal Sequences with Back-tracking, J. Comput. Syst. Sci. 65 (2002), 717–726.

24. D. Kowalski, A. Pelc, Leader election in ad hoc radionetworks: a keen ear helps, Proc. 36th International Collo-quium on Automata, Languages and Programming (ICALP2009), LNCS 5556, 521–533.

25. E. Kranakis, Symmetry and Computability in Anony-mous Networks: A Brief Survey, Proc. 3rd Int. Conf.on Structural Information and Communication Complexity,1997, 1–16.

26. E. Kranakis, D. Krizanc and J. van der Berg, ComputingBoolean Functions on Anonymous Networks, Informationand Computation 114, (1994), 214–236.

27. E. Kranakis, D. Krizanc, and P. Morin, RandomizedRendez-Vous with Limited Memory, Proc. 8th LatinAmerican Theoretical Informatics (LATIN 2008), 605–616.

28. G. LeLann, Distributed systems: Towards a formal ap-proach. In Information processing’77, B. Gilchrist, Ed.,155-160, North Holland 1977.

29. S. Lindell, A logspace algorithm for tree canonization,Proc. 24th ACM Symposium on Theory of Computing(STOC 1992), 400–404.

30. K. Nakano, S. Olariu, Uniform leader election protocolsfor radio networks, IEEE Transactions on Parallel Dis-tributed Systems 13 (2002) 516–526.

31. N. Norris, Universal Covers of Graphs: Isomorphism toDepth N−1 Implies Isomorphism to All Depths, DiscreteApplied Mathematics 56, 1 (1995), 61–74.

32. G.L. Peterson, An O(n log n) unidirectional distributedalgorithm for the circular extrema problem, ACM Trans-actions on Programming Languages and Systems 4 (1982),758–762.

33. O. Reingold. Undirected connectivity in log-space. Jour-nal of the ACM 55 (2008), 1–24.

34. N. Sakamoto, Comparison of Initial Conditions for Dis-tributed Algorithms on Anonymous Networks, Proc.18th ACM Symp. on Principles of Distributed Computing(PODC 1999), 173–179.

35. D.E. Willard, Log-logarithmic selection resolution proto-cols in a multiple access channel., SIAM J. on Computing15 (1986) 468–477.

36. M. Yamashita and T. Kameda, Computing on anony-mous networks, Proc. 7th ACM Symp. on Principles ofDistributed Computing (PODC 1988), 117–130.

37. M. Yamashita and T. Kameda, Electing a leader whenprocesor identity numbers are not distinct, Proc. 3rdWorkshop on Distributed Algorithms, LNCS Vol 392,Springer-Verlag, (WDAG 1989), 303–314.

38. M. Yamashita and T. Kameda, Computing on anony-mous networks: Part I - characterizing the solvable cases,IEEE Trans. Parallel and Distributed Systems, 7 (1996),69–89.