Leader election for anonymous asynchronous agents in arbitrary networks

We consider the problem of leader election among mobile agents operating in an arbitrary network modeled as an undirected graph. Nodes of the network are unlabeled and all agents are identical. Hence the only way to elect a leader among agents is by exploiting asymmetries in their initial positions in the graph. Agents do not know the graph or their positions in it, hence they must gain this knowledge by navigating in the graph and share it with other agents to accomplish leader election. This can be done using meetings of agents, which is difficult because of their asynchronous nature: an adversary has total control over the speed of agents. When can a leader be elected in this adversarial scenario and how to do it? We give a complete answer to this question by characterizing all initial configurations for which leader election is possible and by constructing an algorithm that accomplishes leader election for all configurations for which this can be done.


The model and the problem
Leader election is one of the fundamental problems in distributed computing, first stated in [27].Each entity in some set has a Boolean variable initialized to 0 and, after the election, exactly one of these entities, called the leader, should change this value to 1.All other entities should know which one becomes the leader.In this paper we consider the problem of leader election among mobile agents that operate in a network.We assume that neither nodes of the network nor agents have labels that can be used for leader election.This assumption is motivated by scenarios where nodes and/or agents may refrain from revealing their identities, e.g., for security or privacy reasons.Hence it is desirable to have leader election algorithms that do not rely on identities but exploit asymmetries in the initial configuration of agents due to its topology and to port labelings.With unlabeled nodes and agents, leader election is impossible for symmetric initial configurations, e.g., in a ring in which ports at each node are 0,1, in the clockwise direction and agents are initially situated at every node.Our goal is to answer the following question: For which initial configurations of agents is leader election possible and how to do it when it is possible?A network is modeled as an undirected connected graph with unlabeled nodes.It is important to note that the agents have to be able to locally distinguish ports at a node: otherwise, the adversary could prevent an agent from choosing a particular edge, thus making navigation in the network impossible even in the simple case of trees.This justifies a common assumption made in the literature: ports at a node of degree d have arbitrary fixed labelings 0, . . ., d − 1.Throughout the paper, we will use the term "graph" to mean a graph with the above properties.We do not assume any coherence between port labelings at various nodes.Agents can read the port numbers when entering and leaving nodes.
At the beginning, identical agents are situated in some nodes of the graph, at most one agent at each node.The graph with bicolored nodes (black if the node is occupied, white if it is not) is called an initial configuration.Agents do not have labels and have unlimited memory: they are modeled as identical Turing machines.They execute the same deterministic algorithm.
Agents navigate in the graph in an asynchronous way which is formalized by an adversarial model used in [3,10,11,12,20] and described below.Two important notions used to specify movements of agents are the route of the agent and its walk.Intuitively, the agent chooses the route where it moves and the adversary describes the walk on this route, deciding how the agent moves.More precisely, these notions are defined as follows.The adversary initially places an agent at some node of the graph.The route is chosen by the agent and is defined as follows.The agent chooses one of the available ports at the current node.After getting to the other end of the corresponding edge, the agent learns the port number by which it enters and the degree of the entered node.Then it chooses one of the available ports at this node or decides to stay at this node.The resulting route of the agent is the corresponding sequence of edges ({v 0 , v 1 }, {v 1 , v 2 }, . . .), which is a (not necessarily simple) path in the graph.
We now describe the walk f of an agent on its route.Let R = (e 1 , e 2 , . . . ) be the route of an agent.Let e i = {v i−1 , v i }.Let (t 0 , t 1 , t 2 , . . .), where t 0 = 0, be an increasing sequence of reals, chosen by the adversary, that represent points in time.Let f i : [t i , t i+1 ] → [v i , v i+1 ] be any continuous function, chosen by the adversary, such that f i (t i ) = v i and f i (t i+1 ) = v i+1 .For any t ∈ [t i , t i+1 ], we define f (t) = f i (t).The interpretation of the walk f is as follows: at time t the agent is at the point f (t) of its route.This general definition of the walk and the fact that (as opposed to the route) it is designed by the adversary, are a way to formalize the asynchronous characteristics of the process.The movement of the agent can be at arbitrary speed, the adversary may sometimes stop the agent or move it back and forth, as long as the walk in each edge of the route is continuous and covers all of it.This definition makes the adversary very powerful, and consequently agents have little control on how they move.This, for example, makes meetings between agents hard to achieve.Note that agents can meet either at nodes or inside edges of the graph.
Agents with routes R 1 and R 2 and with walks f 1 and f 2 meet at time t, if points f 1 (t) and f 2 (t) are identical.A meeting is guaranteed for routes R 1 and R 2 , if the agents using these routes meet at some time t, regardless of the walks chosen by the adversary.When agents meet, they notice this fact and can exchange all previously acquired information.However, if the meeting is inside an edge, they continue the walk prescribed by the adversary until reaching the other end of the current edge.New knowledge acquired at the meeting can then influence the choice of the subsequent part of the routes constructed by each of the agents.
Since agents do not know a priori the topology of the graph and have identical memories at the beginning, the only way to elect a leader among agents is by learning the asymmetries in their initial positions in the graph.Hence agents must gain this knowledge by navigating in the network and share it with other agents to accomplish leader election.Sharing the knowledge can be done only as a result of meetings of agents, which is difficult because of the asynchronous way in which they move.
It is not hard to see (cf.Proposition 4.2) that in the absence of a known upper bound on the size of the graph, leader election is impossible even for asymmetric configurations.Hence we assume that all agents know a priori a common upper bound n on the size of the graph.This is the only information about the environment available to the agents when they start the task of leader election.
Having described our model, we can now make the initial problem more precise.Call an initial configuration eligible if, starting from this configuration, leader election can be accomplished regardless of the actions of the adversary.Thus in order that a configuration be eligible, it is enough to have some leader election algorithm starting from it, even one dedicated to this specific configuration.Now our problem can be reformulated as follows.
Which initial configurations are eligible?Find a universal leader election algorithm that elects a leader regardless of the actions of the adversary, for all eligible configurations in graphs of size at most n, where n is known to the agents.

Our results
Assuming an upper bound n on the size of the graph, known a priori to all agents, we characterize all eligible initial configurations and construct an algorithm that accomplishes leader election for all of them.More precisely, we formulate a combinatorial condition on the initial configuration, which has the following properties.On the one hand, if this condition does not hold, then the adversary can prevent leader election starting from the given initial configuration.On the other hand, we construct an algorithm that elects a leader, regardless of the adversary, for all initial configurations satisfying the condition, in graphs of size at most equal to the given bound n.
Intuitively, leader election is possible when the initial configuration is asymmetric and when agents can learn this, regardless of the actions of the adversary.Both these requirements are contained in the necessary and sufficient condition on eligibility, which we formulate in Section 3. In fact, the process of learning the asymmetries by the agents is the main conceptual and technical challenge in the design and analysis of our algorithm.Agents acquire and share this knowledge as a result of meetings.The difficulty is to design the algorithm in such a way that all asymmetries be finally learned by all agents and that all agents be aware of this fact and thus capable to correctly elect the leader.

Related work
Leader election in networks was mostly studied assuming that all nodes have distinct labels and election has to be performed among nodes.This task was first studied for rings.A synchronous algorithm, based on comparisons of labels, and using O(n log n) messages was given in [22].It was proved in [18] that this complexity is optimal for comparison-based algorithms.On the other hand, the authors showed an algorithm using a linear number of messages but requiring very large running time.An asynchronous algorithm using O(n log n) messages was given, e.g., in [31] and the optimality of this message complexity was shown in [6].Deterministic leader election in radio networks has been studied, e.g., in [23,24,28] and randomized leader election, e.g., in [34].In [21] the leader election problem is approached in a model based on mobile agents for networks with labeled nodes.
Many authors [1,2,5,15,25,26,32,35,37] studied various computing problems in anonymous networks.In particular, [4,37] characterize message passing networks in which leader election can be achieved when nodes are anonymous.In [36] the authors study the problem of leader election in general networks, under the assumption that labels are not unique.They characterize networks in which this can be done and give an algorithm which performs election when it is feasible.They assume that the number of nodes of the network is known to all nodes.In [17] the authors study feasibility and message complexity of sorting and leader election in rings with nonunique labels, while in [16] the authors provide algorithms for the generalized leader election problem in rings with arbitrary labels, unknown (and arbitrary) size of the ring and for both synchronous and asynchronous communication.Characterizations of feasible instances for leader election and naming problems have been provided in [7,8,9].Memory needed for leader election in unlabeled networks has been studied in [19].
The asynchronous model for mobile agents navigation in unlabeled networks has been previously used in [3,10,11,12,20] in the context of rendezvous between two agents.In [3,10,11,12] agents had different labels and in [20] agents were anonymous, as in our present scenario.The synchronous model, in which agents traverse edges in lock-step, has been used, e.g., in [13,14,33], also in the context of rendezvous.

Roadmap
In Section 2 we formalize the description of how agents decide.This concerns both navigation decisions (on what basis the agents construct their routes) and the final decision who is the leader.We define memory states of the agents that are the basis of all these decisions.In Section 3 we formulate the combinatorial condition EC concerning initial configurations that is then proved to be equivalent to eligibility, and we formulate our main result.In Section 4 we prove two negative results concerning leader election: one saying that condition EC is necessary for eligibility and the other saying that the assumption concerning knowledge of the upper bound cannot be removed.In Section 5 we give our main contribution: we construct a universal algorithm electing a leader for all configurations satisfying condition EC, if agents know an upper bound on the size of the graph.Section 6 contains conclusions.

Memory states and decisions of agents
In this section we describe formally on what basis the agents make decisions concerning navigation in the graph (i.e., how they construct their routes) and on what basis they make the decision concerning leader election.All these decisions depend on the memory states of the agents.At every time t the memory state of an agent is a finite sequence of symbols defined as follows.Before an agent is woken up by the adversary, its memory state is blank: it is the empty sequence.When an agent is woken up, it perceives the degree d of its initial position, i.e., its memory state becomes the sequence (d).Further on, the memory state of an agent changes when it visits a node.It is caused by the following three types of events: entering a node by the agent, meeting other agents, and leaving a node by the agent.A change of a memory state of an agent is done by appending to its current memory state a sequence of symbols defined as follows.The change due to entering a node of degree d by port number p, consists of appending the sequence (p, d) to the current memory state of the agent.The change due to leaving a node by port q consists of appending q to the current memory state of the agent.The change due to meeting other agents is defined as follows.When entering a node v the agent considers all meetings with other agents that occurred since leaving the previous node.Suppose that the current memory states of the agents met in this time interval by agent λ were σ 1 , . . ., σ k , in lexicographic order, regardless of the order of meetings in this time interval and disregarding repeated meetings corresponding to the same memory state (and thus to the same agent).Agent λ appends the sequence of symbols ([σ 1 ]...[σ k ]) to its current memory state.When two or more of these events occur simultaneously, for example an agent meets another agent when it enters a node, or an agent meets simultaneously several agents, then the appropriate sequences are appended to its current memory one after another, in lexicographic order.When in the previous memory state the agent made a decision to stay idle at the current node, then its memory state can change only if and when some other agent enters this node.This completes the description of how the memory states of agents evolve.Notice that after traversing an edge the action of agent λ consisting of appending a sequence of symbols [σ] due to a meeting with an agent with current memory state σ since leaving the previous node, is performed by λ at most once.Since the number of agents is finite, this implies that, by any given moment in time, the memory state of an agent has changed only a finite number of times, and each time a finite sequence of symbols has been appended.Hence memory states are indeed finite sequences of symbols.
The decisions of agents are made always when an agent is at a node and they are of three possible types: an agent can decide to stay idle, it can decide to exit the current node by some port, or it can elect a leader and stop forever.All these decisions are based on the memory state of the agent after entering the current node and are prescribed by the algorithm.(Recall that agents execute the same deterministic algorithm.)If an agent decides to stay at a given node, then it remains idle at it until another agent enters this node.At this time the memory state of the idle agent changes, and in the new memory state the agent makes a new decision.If an agent decides to leave the current node by a given port, it walks in the edge in the way prescribed by the adversary and makes a new decision after arriving at the other end of the edge.Finally, if an agent decides to elect a leader, it either elects itself, or it decides that it is not a leader, in which case it has to give a sequence of port numbers leading from its own initial position to the initial position of the leader: this is the meaning of the requirement that every non-leader has to know which agent is the leader.

Feasibility of leader election
In this section we express the necessary and sufficient condition on eligibility of an initial configuration and we formulate the main result of this paper.We first introduce some basic terminology.
We will use the following notion from [37].Let G be a graph and v a node of G.We first define, for any l ≥ 0, the truncated view V l (v) at depth l, by induction on l.V 0 (v) is a tree consisting of a single node x 0 .If V l (u) is defined for any node u in the graph, then V l+1 (v) is the port-labeled tree rooted at x 0 and defined as follows.For every node v i , i = 1, . . ., k, adjacent to v, there is a child x i of x 0 in V l+1 (v) such that the port number at v corresponding to edge {v, v i } is the same as the port number at x 0 corresponding to edge {x 0 , x i }, and the port number at v i corresponding to edge {v, v i } is the same as the port number at x i corresponding to edge {x 0 , x i }.Now node x i , for i = 1, . . ., k becomes the root of the truncated view V l (v i ).
The view from v is the infinite rooted tree V(v) with labeled ports, such that V l (v) is its truncation to level l, for each l ≥ 0. For an initial configuration in which node v is the initial position of an agent, the view V(v) is called the view of this agent.
We will also use a notion similar to that of the view but reflecting the positions of agents in an initial configuration.Consider a graph G and an initial configuration of agents in this graph.Let v be a node occupied by an agent.A function f that assigns either 0 or 1 to each node of V(v) is called a binary mapping for V(v).A pair (V(v), f ), where f is a binary mapping for V(v), such that f (x) = 1 if and only if x corresponds to an initial position of an agent, is called the enhanced view from v. Thus, the enhanced view of an agent additionally marks in its view the nodes corresponding to initial positions of other agents in the initial configuration.
For any route R = (e 1 , e 2 , . . ., e k ) such that e i = {v i−1 , v i }, we denote b(R) = v 0 and d(R) = v k , and we say that R leads from v 0 to v k in G. Since nodes of G are unlabeled, agents traveling on a route are aware only of the port numbers of the edges they traverse.Hence, it will be usually more convenient to refer to these sequences of port numbers rather than to the edges of the route.Any finite sequence of non-negative integers will be called a trail.
We define an operator T , that provides the trail corresponding to a given route.More formally, ) to be the trail such that p 2i−1 and p 2i are the port numbers of {v i , v i+1 } at v i and v i+1 , respectively, for i = 1, . . ., j − 1.We say that a trail For a sequence A = (a 1 , . . ., a k ) we denote by A the sequence (a k , a k−1 , . . ., a 1 ).For two sequences A = (a 1 , . . ., a k ) and B = (b 1 , . . ., b r ) we write (A, B) to refer to the sequence (a 1 , . . ., a k , b 1 , . . ., b r ).
For any agent λ, let h(λ) denote its initial position.Consider two agents λ and λ .Consider any route R leading from h(λ) to h(λ ) and let T = T (R).If T = T , then we say that the route R is a palindrome.For a given initial configuration, a palindrome R is called uniform, if for any route R such that T (R ) = T (R), whenever b(R ) is occupied by an agent, then d(R ) is also occupied by an agent.
We are now ready to formulate our condition on an initial configuration, that will be called EC (for eligibility condition) in the sequel:

Enhanced views of all agents are different and (There exist agents with different views or There exists a non-uniform palindrome)
We now formulate our main result whose proof is the objective of the rest of the paper.Theorem 3.1 Assume that all agents are provided with an upper bound n on the size of the graph.Then an initial configuration is eligible if and only if condition CE holds for this configuration.Moreover, there exists an algorithm electing a leader for all eligible configurations, regardless of the actions of the adversary.

The negative results
In this section we prove two negative results concerning the feasibility of leader election.The first result shows that condition CE is necessary to carry out leader election, even if the graph (and hence its size) is known to the agents.Proposition 4.1 Suppose that the condition CE does not hold for the initial configuration.Then there exists an adversary, such that leader election cannot be accomplished for this configuration, even if the graph is known to the agents.
Proof: Fix an initial configuration.Condition CE can be abbreviated as α ∧ (β ∨ γ), where α is "Enhanced views of all agents are different", β is "There exist agents with different views", and γ is "There exists a non-uniform palindrome".Suppose that EC does not hold.
First consider the case when α is false.This means that there exist agents λ and λ with the same enhanced view.This in turn implies that for every agent µ there exists an agent µ that has the same enhanced view as µ.Indeed, if T is the trail corresponding to a route that leads from h(λ) to h(µ), agent µ is the agent whose initial position is at the end of the route corresponding to T and starting at h(λ ).For every agent µ we will call the agent µ its twin.Consider a hypothetical leader election algorithm and the "perfectly synchronous" adversary that starts the execution of the algorithm simultaneously for all agents and moves all of them with the same constant speed.Such an adversary induces rounds which are units of time in which all agents traverse an edge.The beginning of a round coincides with the end of the previous round.Hence at the beginning and at the end of each round every agent is at a node.If agents meet inside an edge, they must meet exactly in the middle of a round in which they traverse an edge in opposite directions.We will show that the memory state of twins is identical at the end of each round.This implies that leader election is impossible, as an agent elects a leader when it is at a node, and consequently if some agent elects itself as a leader, its twin would elect itself as well, violating the uniqueness of the leader.
The invariant that the memory state of twins is identical at the end of each round is proved by induction on the round number.It holds at the beginning, due to the same degree of initial positions of twins.Suppose that after some round i the memory states of twins are identical.Consider twins µ and µ .In round i + 1 they exit by the same port number and enter the next node by the same port number.If in round i + 1 they don't meet any agent in the middle of the edge, at the end of the round µ must meet agents with the same memory states as those met by µ (if any), and hence memory states of µ and µ at the end of round i + 1 are identical.If in round i + 1 agent µ meets some agents in the middle of the edge, then agent µ must meet exactly the twins of these agents in the middle of the edge.By the inductive hypothesis, these twins have the same memory states as agents met by µ and hence again, at the end of the round the memory states of µ and µ are identical.This concludes the proof if α is false.
Next consider the case when β ∨ γ is false.This means that views of all agents are identical and every palindrome for the initial configuration (if any) is uniform.For any trail π that yields a uniform palindrome, this gives a partition of all agents into pairs (µ π , µ π ) of agents at the ends of routes that correspond to this trail.
Again we consider the "perfectly synchronous" adversary described above.There are two subcases.If there is no palindrome in the initial configuration, then we prove the following invariant, holding at the beginning of each round, by induction on the round number: the memory state of all agents is the same and there is no palindrome between agents.The invariant holds at the beginning by assumption.Suppose it holds after round i.In round i + 1 all agents choose the same port number and enter the next node by the same port number.There are no meetings in round i + 1.Indeed, the only meeting could be in the middle of an edge but this would mean that agents were joined by a one-edge palindrome at the beginning of round i + 1.If a pair of agents were joined by a palindrome after round i + 1, they would have to be joined by a palindrome longer or shorter by two edges at the beginning of the round, contradicting the inductive assumption.Hence the invariant holds by induction.
The second subcase is when there is a palindrome in the initial configuration (and hence all such palindromes are uniform).Now we prove the following invariant holding in the beginning of each round: the memory state of all agents is the same and every agent is at the end of a palindrome corresponding to the same trail.The invariant holds at the beginning by the assumption.Suppose the invariant holds after round i.In round i + 1 all agents choose the same port number and enter the next node by the same port number.If after round i no pair of agents were at the ends of an edge with both ports equal, or they were but agents did not choose this port in round i + 1, then no meeting occurred and the invariant carries on after round i + 1.If after round i every pair of agents were at the ends of an edge with both ports p and the agents chose this port in round i + 1, then meetings of agents with identical memory states occurred in pairs in the middle of each joining edge.Since meeting agents had identical memory state during the meeting, this holds also after round i + 1 and agents are again in pairs at the ends of edges with both ports p.Thus the invariant holds at the end of round i + 1.
Hence at the beginning of each round the memory state of all agents is the same, both when α and when β ∨ γ is violated.This implies that with the "perfectly synchronous" adversary leader election is impossible whenever condition EC is violated for the initial configuration.Notice that the argument holds even when agents know the graph in which they operate.
Our second negative result shows that the assumption about the knowledge of an upper bound on the size of the graph cannot be removed from Theorem 3.1.Proposition 4.2 There is no algorithm that accomplishes leader election regardless of the adversary for all initial configurations satisfying condition CE.
Proof: Suppose for a contradiction that such a universal algorithm A exists.Consider an "almost" oriented ring of size m: ports 0,1 are in the clockwise direction at each node except one, where they are counterclockwise.This node is called special.The initial configuration on this ring consists of two agents: one at the special node, and one at the neighbor clockwise from it.Call this configuration C 1 (cf.Fig. 1 (a)).This configuration satisfies condition CE: agents have different views.Hence algorithm A must elect a leader for this configuration, regardless of the adversary.Consider a "perfectly synchronous" adversary that starts the execution of the algorithm simultaneously for all agents and moves all of them with the same constant speed.It induces rounds corresponding to edge traversals by all agents.Suppose that a leader is elected for this adversary after t rounds.Now consider a ring of size 4tm in which there are 4t special nodes at distances m: at these nodes ports 0,1 are in the counterclockwise direction, and in all other nodes they are in the clockwise direction.The initial configuration consists of 8t + 1 agents.There is an agent at every special node and at every clockwise neighbor of a special node.Additionally there is an agent at the counterclockwise neighbor of one special node.Call this configuration C 2 (cf.Fig. 1 (b)).This configuration satisfies condition CE.Indeed, due to the single group of three consecutive agents, all agents have distinct enhanced views.On the other hand, agents at special nodes have a different view from agents at clockwise neighbors of special nodes.Hence algorithm A must elect a leader for this configuration as well, regardless of the adversary.Consider the same "perfectly synchronous" adversary as before.Consider the agent λ in the configuration C 2 that is initially situated at the special node v antipodal to the special node with both neighbors hosting agents.Consider the agent λ initially situated at the special node v that is clockwise from v and closest to v.In the first t rounds of the execution of A starting from configuration C 2 , memory states of agents λ and λ are identical to memory states of the agent µ initially situated at the special node of configuration C 1 .This is due to the large size of the ring in configuration C 2 .Hence if in configuration C 1 agent µ elects itself, then in configuration C 2 agents λ and λ elect each of them itself as the leader after t rounds.If in configuration C 1 agent µ elects its neighbor, then in configuration C 2 agents λ and λ elect each of them their neighbor as the leader after t rounds.In both cases two different agents are elected, which is a contradiction.

The algorithm and its correctness
In this section we present an algorithm that elects a leader for all initial configurations satisfying condition EC, assuming that an upper bound on the size of the graph is known to all agents.In view of Proposition 4.2, this assumption cannot be removed.This upper bound, denoted by n, is an input of our algorithm.
The section is divided into three subsections.In the first subsection we provide additional terminology and notation, as well as some auxiliary results used in the algorithm and in its analysis.In the second subsection we give the intuitive overview of the algorithm and its formal description, and we provide some illustrative examples of its functioning.Finally, the third subsection is devoted to the proof that the algorithm is correct.

Additional notions and auxiliary results
Let G be a graph and let v be any node of G.For any integer l > 0, we define the code of V l (v) as the sequence ξ(V l (v)) of integers obtained as follows.Perform the complete depth first search traversal of V l (v), starting at its root, in such a way that at each node an edge with a smaller port number is selected prior to an edge with a larger port number.Then, if {x, y} is the i-th traversed edge, when going from x to y during the traversal of {x, y}, then the (2i − 1)-th and (2i)-th elements of ξ(V l (v)) are the port numbers of {x, y} at x and y, respectively.The following is a direct consequence of this definition.Proposition 5.1 Let u and v be any nodes of G and let l > 0 be an integer.
Let l > 0 be an integer.We extend the notion of binary mappings to the truncated views.We say that f is a binary mapping for V l (v), if f assigns either 0 or 1 to each node of V l (v).If f is a binary mapping for V(v) (or for V l (v) for some l > 0), then (V l (v), f ) (where l ≤ l , respectively) refers to f restricted to the nodes of V l (v).Given two binary mappings f 1 , f 2 for V l (v), we write ) is the enhanced view from v and f is a binary mapping for V l (v) such that f f , then the pair (V l (v), f ) is called a partially enhanced view from v. Intuitively, in a partially enhanced view only some nodes corresponding to initial positions of agents are marked.
Let (V(v), f ) be the enhanced view from v, where v is selected so that there exists an agent λ with h(λ) = v.Then, (ξ(V n−1 (v)), f ) is called the complete identifier of λ.The significance of the notion of a complete identifier is the following.An agent can never get the entire view or the entire enhanced view, as these are infinite objects.However, the following propositions from [29] show that to differentiate two views or two enhanced views, it is enough to consider their truncations to depth n − 1.Thus, as stated in Corollary 5.1, complete identifiers identify agents with different enhanced views.

Proposition 5.2 ([29]
) For a n-node graph G and for all nodes u and v of G, V(u) = V(v) if and only if V n−1 (u) = V n−1 (v).

Proposition 5.3 ([29]
) For a n-node graph G, for all nodes u and v of G, if (V(u), f ) and (V(v), f ) are the enhanced views from u and v, respectively, then Corollary 5.1 For a n-node graph G and for any agents λ and λ , the enhanced views from h(λ) and h(λ ) are equal if and only if the complete identifiers of λ and λ are equal.
A sequence of the form α = (ξ(V l (v)), f 1 , f 2 , . . ., f j ) is called a label, if the following conditions hold: (i) v is a node of G, and l > 0 and j > 0 are integers, (ii) f i is a binary mapping for V l (v) for each i = 1, . . ., j.
(iii) f 1 is the binary mapping for V l (v) that assigns 1 only to the root, and f i f i+1 for every index i = 2, . . ., j − 1.
Moreover, we say that j is the length of the label α, denoted by (α).Let L j be the set of all labels of length at most j.

The algorithm
In this section we give a high-level description of the algorithm and its pseudo-code formulation.
An important ingredient of the algorithm are meetings between agents during which information is exchanged.The method that guarantees that some meetings between pairs of agents will occur uses the idea of tunnels introduced in [11].The routes R = (e 1 , . . ., e j ) and R form a tunnel if R = (e i , e i−1 , . . ., e 1 , e 1 , . . ., e j ) for some i ∈ {1, . . ., j} and for some j ≥ 0.Moreover, we say that the route (e 1 , . . ., e i ) is the tunnel core with respect to R. Note that if C is the tunnel core with respect to R, then C is the tunnel core with respect to R .

Proposition 5.4 ([11]
) Let λ i be an agent with route R i , i = 1, 2. If R 1 and R 2 form a tunnel with the tunnel core C = (e 1 , . . ., e c ), then λ 1 and λ 2 are guaranteed to have a meeting such that (e 1 , e 2 , . . ., e i ) and (e c , e c−1 , . . ., e i ) are the routes of the agents traversed till the meeting, where i ∈ {1, . . ., c}.
Informally speaking, if the routes of two agents form a tunnel, then they are guaranteed to have a meeting with the property that the routes traversed to date by the agents give (by taking one of the routes and the reversal of the other) the tunnel core.
Let S n be the set of all integer sequences with terms in {0, . . ., n − 2}, whose length is even and equals at most 6(n − 1).Then, we define P n = (α, α , T ) : α, α ∈ L 3 and (α) = (α ) and T ∈ S n and (α = α ∨ (α = α ∧ T = T )) , and let P n i be the i-th triple in P n , i = 1, . . ., |P n |.In our leader election algorithm we will proceed in phases, and in each phase the label of each agent is fixed.(Due to the fact that the model is asynchronous, the adversary may force the agents to be in different phases in a particular point of time.)The total number of phases for each agent is 3.After the first phase each agent computes its label used in phase 2. These labels are defined in such a way that there exist two agents λ and λ with different labels.The aim of phase 2 is that agents λ and λ correctly identify each other's initial positions in their respective views.After phase 3 every agent can identify the initial positions of all agents in its view and hence is able to perform leader election.
The label of an agent λ used in phase p is denoted by α p (λ), p = 1, 2, 3. Label α 1 (λ) is computed before the start of phase 1, and α p+1 (λ) is computed at the end of phase p, for p = 1, 2, 3. Label α 4 (λ) is used to elect the leader at the end of the algorithm.Each phase is divided into |P n | stages.By R p,s (λ) we denote the route traversed by agent λ till the end of stage s in phase p, p = 1, 2, 3, s = 1, . . ., |P n |.As we prove later, each agent λ starts and ends each stage at its initial position h(λ).Let R p,0 (λ) be the route of an agent λ traversed till the beginning of phase p, and hence till the end of phase p − 1, whenever p > 0. Hence, R 1,0 (λ) is the route traversed by λ prior to the beginning of the first phase.Now we give an informal description of Algorithm Leader-Election.This algorithm is executed by each agent, and λ in the pseudo-code is used to refer to the executing agent.Note that the upper bound n on the number of nodes of G is given as an input.The pseudo-code of the algorithm and pseudo-codes of its subroutines are in frames.In the informal description we refer to lines of these pseudo-codes.
First, we discuss Procedure Initialization that is called at the beginning of Algorithm Leader-Election.The agent starts by computing P n .This can be done knowing n, without any exploration of the graph.Then, the agent computes V 3(n−1) (h(λ)) by performing a DFS traversal of G to the depth 3(n − 1) (line 2).The function f λ is set (line 3) to be the binary mapping for V 3(n−1) (h(λ)) that assigns 0 to all nodes of V 3(n−1) (h(λ)) except for the root.Hence, (V 3(n−1) (h(λ)), f λ ) is a partially enhanced view from h(λ).The value of α 1 (λ), that will be the label of λ in the first phase, is set to (ξ(V 3(n−1) (h(λ))), f λ ) (line 4).

Procedure Initialization(n)
Input: An upper bound n on the size of G. begin 1: Compute P n .2: Compute V 3(n−1) (h(λ)) by performing a DFS traversal of graph G to depth 3(n−1) that ends at h(λ).

3:
Let f λ be the binary mapping for V 3(n−1) (h(λ)) that assigns 1 only to the root of Now we informally describe the main part of Algorithm Leader-Election, refering to the lines of the pseudo-code given below.The p-th iteration of the main 'for' loop in lines 2-13 is responsible for the traversal performed by the agent in phase p, p ∈ {1, 2, 3}.An internal 'for' loop in lines 3-10 is executed and its s-th iteration determines the behavior of λ in stage s.The stage s of each phase 'processes' the s-th element (α , α , T ) of P n .If α p (λ) / ∈ {α , α }, then the agent λ does not move in this stage and proceeds to the next one.Otherwise let α p (λ) = α (we describe only this case as the other one is symmetric).The agent checks in line 5 whether a certain trail (T, H) is feasible from h(λ), and if it is not, then the stage ends.As we prove later, the verification of the feasibility of (T, H) can be done by inspecting V 3(n−1) (h(λ)).If (T, H) is feasible from h(λ), then λ follows the route R(h(λ), (T, H)) (line 6), which guarantees that: • if the agent λ is located at h(λ) at the beginning of stage s, then λ is located at h(λ) at the end of stage s (see Lemma 5.3), and • if the route R(h(λ), T ) leads from h(λ) to the initial position of another agent λ and α p (λ ) = α , then the routes R p,s (λ) and R p,s (λ ) form a tunnel.
The agent ends phase p by updating its label.This is done by calling Function Update-Label in line 11, which produces a binary mapping f λ that is used to update the label in line 12.After completing the tree phases (for p = 1, 2, 3) the agent calls Procedure Choose-Leader which completes the task of leader election.
In order to formally describe the trail H mentioned above we need the following notation.Let α ∈ L 3 be a label of length p ∈ {1, 2, 3}, let s ∈ {1, . . ., |P n |} and let v be a node of G.We define H(α , s) to be the trail that corresponds to the route performed till the end of stage s of phase p by an agent λ whose label equals α in phase p, α p (λ ) = α , and whose initial position corresponds to the root of the truncated view V 3(n−1) (h(λ )) in α .We prove (see Lemma 5.2) that, for any α and s the trail H(α, s) can be computed on the basis of α and s.The trail H mentioned above is H(α , s − 1).

Algorithm Leader-Election(n)
Input: An upper bound n on the size of G. begin 1: Call Initialization(n).
Although we use tunnels, we use them differently from [11].First, we are able to construct much simpler routes that form tunnels.This is due to the fact that [11] deals with the rendezvous problem in finite graphs of unknown size and in infinite graphs.As argued before, for leader election we have to assume that an upper bound n on the size of the graph is known, and we take advantage of knowing n to construct 'shorter' tunnels which simplifies our analysis.Second and more importantly, it is not sufficient for our purposes to just generate a meeting for a particular pair of agents -the meetings are generated to perform the exchange of information.In particular, as a result of a meeting that occurs in a tunnel an agent should be able to determine the node (in its own view) corresponding to the initial position of the other agent.This leads us to the following concept of meetings with 'confirmation' of a trail.Definition 5.1 Let T ∈ S n .Suppose that agents λ and λ meet.We say that λ confirms T as a result of this meeting if (i) λ is in stage s of phase p and λ is in stage s of phase p , where p < p, or p = p and s ≤ s, (ii) P n s = (α , α , T ), where α p (λ) ∈ {α , α }, (iii) if T λ and T λ are the trails traversed by λ and λ , respectively, till the meeting, then where T = T and α = α when α p (λ) = α , and T = T and α = α otherwise.
As we prove in Section 5.3, if an agent λ confirms T as a result of a meeting with λ , then d(R(h(λ), T )) = h(λ ). Figure 3 depicts the equation in part (iii) of Definition 5.1.Figure 3(a) presents the trail that is a perfix of the trail corresponding to the route R p,s (λ) followed by the agent λ till the end of stage s of phase p.

Function Update-Label(M )
Input: A memory state M of an agent λ.

2:
Let M 1 , . . ., M j be the memory states of all agents previously met by λ, at the times of the respective meetings.

3:
for i ← 1 to j do 4: Let T = T if α p (λ) = α , and let T = T if α p (λ) = α , where (α , α , T ) = P n s .5: if λ or the agent with the memory state M i confirms T then 6: f λ (x) ← 1, where x is the node of V 3(n−1) (h(λ)) at the end of T from the root.7: end if 14: end for 15: return f λ end Update-Label We start by giving intuition of the first of them.This procedure is crucial for the entire algorithm, as it takes advantage of memory state exchanges between agents that meet and permits every agent to insert initial positions of all agents in its view.This in turn allows the agents to learn asymmetries in the initial configuration and thus correctly perform leader election.Function Update-Label takes as an input the current memory state of an agent λ and returns a binary mapping f λ for its view V 3(n−1) (h(λ)), such that (V 3(n−1) (h(λ)), f λ ) is a partially enhanced view for agent λ.Agent λ considers memory states M 1 , . . ., M j of all previously met agents at the times of the meetings.The memory state M i , i ∈ {1, . . ., j}, of an agent λ and the memory state of λ at the time of their meeting permit the agent λ to verify whether λ or λ confirmed T as a result of their meeting.If one of the agents confirms T , then λ takes the advantage of this fact to determine the nodes of its view corresponding to initial positions of agents.In particular, λ is able to locate a node in its own view that corresponds to the initial position of λ , because there exists a route corresponding to T and connecting the initial positions of the two agents.Afterwards, if this route is of length at most n − 1, then λ recursively calls Function Update-Label for the memory state M i (which is shorter than the current memory state of λ and thus recursion is correct).Hence, λ can compute the binary mappings corresponding to memory states of all previously met agents at the times of the meetings.Using trails between initial positions of these agents and h(λ), as well as the obtained binary mappings, agent λ can correctly position all partially enhanced views of these agents in its own view.A call to Function Update-Label at the end of phase p executed by agent λ permits to compute α p+1 (λ).
In the formulation of Function Update-Label we use the following notions.Let u and v be two nodes of G.We say that a function ϕ assigning to each node of V 2(n−1) (u) a node of V 3(n−1) (v) is a transition from V 2(n−1) (u) to V 3(n−1) (v), if ϕ(x) and x correspond to the same node of G for each node x of V 2(n−1) (u).For any trail T and any node v, we say that a node x at depth i in V(v) is at the end of T from the root, if the length of T is 2i and the sequence of ports corresponding to the simple path from the root of V(v) to x is T .
In the following example we illustrate one iteration of the 'for' loop in lines 3-14 of Function Update-Label.The graph G is given in Figure 4(a), and let n = 4 be an upper bound that was initially provided to each agent.The black nodes of G are the initial positions of some agents.Denote by λ a , λ b and λ c the agents whose initial positions are a, b and c, respectively.Note that the views from any two nodes of G are identical in this case.However, the enhanced view from each node of G is unique.We focus on the instance of Function Update-Label executed by λ c during its meeting with λ b .For simplicity, we show only some subtrees of V 3(n−1) (c) and V 3(n−1) (b) in Figures 4(b) and 4(c), respectively.Note that the nodes of G, and therefore the nodes of any view, are unlabeled and we provide the labels only for the illustrative purpose.In this example the trail T , computed in line 4 of Function Update-Label equals (0, 0, 1, 1), which determines the node of the truncated view V 3(n−1) (c) that corresponds to the root of V 3(n−1) (b).The black nodes of both views correspond to the initial positions of agents that λ c and λ b determined prior to this meeting.The dotted arrows give the part of the transition ϕ that maps the nodes of V 2(n−1) (c) to the black nodes of V 3(n−1) (b).It follows from the definition of the view that, in general, more than one node of V n−1 (h(λ)) can be mapped by ϕ to a node of V 3(n−1) (v).We finally present Procedure Choose-Leader that is called by Algorithm Leader-Election after the third phase.The leader is selected by an agent λ on the basis of the label α 4 (λ) = (ξ(V 3(n−1) (h(λ))), f λ 1 , . . ., f λ 4 ).Let x be a node at depth at most n − 1 in V 3(n−1) (h(λ)) and satisfying f λ 4 (x) = 1.Let S be a subtree of depth n − 1 of V 3(n−1) (h(λ)) rooted at x.We prove later that the pair (S, f λ 4 ) is the complete identifier of some agent.Since the initial positions of all agents have been detected till the end of phase 3, the agent can determine all complete identifiers and hence elect the leader.
Procedure Choose-Leader begin 1: A ← ∅ 2: for each node x of V n−1 (h(λ)) such that f λ 4 (x) = 1 do 3: Let f be f λ 4 restricted to the nodes of V n−1 (v), where v corresponds to x.

4:
Compute trail T such that v = d(R(h(λ), T )).5: if (ξ(V n−1 (v)), f ) = I for each I such that (I, T ) ∈ A then 6: end for 8: Find (I, T ) ∈ A such that I = min{I : (I , T ) ∈ A}, where min is in lexicographic order.9: Elect the agent whose initial position is d(R(h(λ), T )) to be the leader.end Choose-Leader

Correctness of the algorithm
This section is devoted to the proof that Algorithm Leader-Election correctly elects a leader whenever an initial configuration satisfies condition EC, regardless of the actions of the adversary.The proof is split into a series of lemmas.The role of the first lemma is to show that knowing V 2n−1 (v) is enough to check if a trail of any length is feasible from v. Lemma 5.1 Let v be any node of G. Using V 2n−1 (v), the truncated view V l (v) can be computed for any positive integer l.
Proof: If l ≤ 2n − 1, then V l (v) is a subtree of V 2n−1 (v), so we may assume that l > 2n − 1.We extend the view V i (v) to V i+1 (v) for each i = 2n − 1, . . ., l − 1.To this end we perform the following computation for each node x at depth i − (n − 1) of V i (v).Let u be the node of G that corresponds to x.Note that the subtree of V i (v) rooted at x and containing all descendants of x in V i (v) is equal to V n−1 (u).Hence, there exists a node x in V n−1 (v) such that x corresponds to u, in view of the connectedness of G.This implies that there exists a node y in V n−1 (v) such that the subtree of V 2n−1 (v) consisting of y and all its descendants to depth n − 1 from y is equal to V n−1 (u).Hence, one can find any such node y of V n−1 (v).Let u be the node of G that corresponds to y. Due to Proposition 5.2, V n (u ) is equal to V n (u).Since y belongs to V n−1 (v) we obtain that V n (u ) is a subtree of V i (v) rooted at y, and therefore we can extend the subtree V n−1 (u) by replacing in V i (v) the subtree rooted at x with V n (u ).
Corollary 5.2 Let v be any node of G and let x be any node of V 2n−1 (v).Then, the subtree of V(v) to depth l and rooted at x can be computed for any l > 0, using V 2n−1 (v).
Corollary 5.3 Let T be any trail and let v be any node of G.
The next lemma shows the importance of confirmation of a trail.It implies that if an agent λ confirms T as a result of a meeting with λ , then it can correctly situate the initial position of λ in its view.
Lemma 5.4 Let p ∈ {1, 2, 3}, let s ∈ {1, . . ., |P n |} and let P n s = (α , α , T ).Let λ be an agent such that α p (λ) ∈ {α , α }.Suppose that the agent λ meets an agent λ , when λ is in stage s of phase p.If λ confirms T as a result of this meeting, then h(λ Proof: Suppose without loss of generality that α = α p (λ). Condition (iii) in Definition 5.1 implies that the route R The following lemma shows that processing an appropriate triple (α, α , T ) by two agents guarantees their meeting confirming T .Lemma 5.5 Let p ∈ {1, 2, 3}.Let λ and λ be two agents such that P n s = (α p (λ), α p (λ ), T ) for some T ∈ S n and s ∈ {1, . . ., |P n |}.If d(R(h(λ), T )) = h(λ ), then prior to the first moment when one of the agents completes phase p, the agents λ and λ have a meeting as a result of which either λ or λ confirms T .
Proof: Suppose without loss of generality that λ ends the traversal of R p,s−1 (λ) at the same time or earlier than λ ends the traversal of R p,s−1 (λ ).Let R p,s (λ) be the route traversed by λ in stage s of phase p.By Lemma 5.3, b(R p,s (λ)) = d(R p,s−1 (λ)) = h(λ).The route R p,s (λ) is constructed as a result of the execution of lines 5-6 of Algorithm Leader-Election by λ.Since α = α p (λ ) in line 6 of Algorithm Leader-Election, we obtain that R p,s (λ) and R p,s (λ ) form a tunnel with the tunnel core C = (R(h(λ), (T, H(α p (λ ), s − 1)))).By Proposition 5.4, λ and λ will have a meeting while λ is in stage s of phase p and before λ ends the traversal of R p,s (λ ).This implies that (i) of Definition 5.1 holds.Moreover, (ii) of Definition 5.1 is satisfied by assumption.Let T λ and T λ be the trails traversed by λ and λ , respectively, till the meeting.By Proposition 5.4, (T (R p,s−1 (λ)), T (C)) = (T λ , T λ ), where C is the tunnel core.This proves that (iii) of Definition 5.1 holds.Hence, the agent λ confirms T as a result of the meeting.
The role of the next lemma is to show that an agent never marks falsely an initial position of another agent in its view.Lemma 5.6 Let α p (λ) = (ξ(V 3(n−1) (h(λ))), f λ 1 , . . ., f λ p ) be the label of any agent λ in phase p ∈ {1, 2, 3}.If x is any node of V 3(n−1) (h(λ)) corresponding to a node of G that is not an initial position of an agent, then f λ p (x) = 0.
Proof: Suppose for a contradiction that an agent λ sets f λ (x) to be 1, and x corresponds to a node of G that is not an initial position of an agent.Suppose that the input memory state M of the agent λ is the shortest that satisfies this property.This assumption implies that if f is computed by agent λ in line 8 of Function Update-Label for any memory state M i , i = 1, . . ., j, then (V 3(n−1) (v), f ) is a partially enhanced view from v, where v corresponds to the node x at the end of T from the root in V 3(n−1) (h(λ)).Hence, if v is an initial position of an agent, then, due to the definition of transition, each node y from line 11 of Function Update-Label corresponds to an initial position of an agent.
The latter implies that the assignment of 1 to f λ (x) occurs in line 6 of Update-Label, as a consequence of a meeting with some agent λ whose memory state was M i at the time of the meeting.Hence, x is at the end of T from the root in V 3(n−1) (h(λ)).Due to line 5 of Update-Label, either λ or λ confirms T as a result of their meeting.By Lemma 5.4, d(h(λ), T ) = h(λ ), where T ∈ {T, T } is determined in line 4 of Update-Label.Thus, h(λ ) corresponds to the node at the end of T from the root in V 3(n−1) (h(λ)).The latter implies that h(λ ) corresponds to x, contradicting our assumption.
The next lemma is a companion result to Lemma 5.6.It says that if an agent confirms a trail T as a result of a meeting with λ , then both of them correctly mark their respective initial positions in their views.Lemma 5.7 Let p ∈ {1, 2, 3}.Let λ and λ be two agents with labels α p+1 (λ) = (α p (λ), f λ p+1 ) and α p+1 (λ ) = (α p (λ ), f λ p+1 ).If agent λ confirms T as a result of a meeting with agent λ in phase p , p ≤ p, then (i) f λ p+1 (x) = 1, where x is at the end of T from the root in V 3(n−1) (h(λ)), such that T ∈ {T, T } and d(R(h(λ), T )) = h(λ ).
Proof: Suppose that λ is in some stage of phase p , p ≤ p, when a meeting with λ occurs as a result of which λ confirms T .Hence, one of the memory states in line 2 of Function Update-Label called at the end of phase p is the memory state M i , i ∈ {1, . . ., j}, of λ at the time of the meeting.We consider the i-th iteration of the 'for' loop in lines 3-14 of Function Update-Label, i.e., informally speaking, the iteration in which λ 'analyzes' the meeting with λ .The agent λ determines in line 5 of Function Update-Label the fact that either λ or λ confirms T as a result of the meeting.Then, in line 6 of Function Update-Label, f λ (x) is set to 1, where x is at the end of T from the root of V 3(n−1) (h(λ)).By Lemma 5.4 and by the choice of T in line 4 of Function Update-Label, x corresponds to h(λ ).Function Update-Label returns f λ .Due to line 12 of Algorithm Leader-Election, f λ p+1 (x) = 1.In order to prove the second part of the lemma notice that agent λ has also access to the memory states of λ and λ at the time of the meeting.Hence, upon completing phase p it performs analogous computations as λ during its execution of Function Update-Label at the end of phase p and sets f λ p+1 (x ) = 1.
a third agent λ with a different label as an intermediary.Such an agent exists by Lemma 5.9.Agents λ and λ can correctly fill their initial positions to depth 2(n − 1) in their views due to the fact that the intermediary λ has their initial positions to depth 3(n − 1).
Proof: Since α p (λ ) = α p (λ) we obtain, by the definition of P n , that (α p (λ ), α p (λ), T ) = P n i for some i ∈ {1, . . ., |P n |}, where T is such a trail that the route R = R(h(λ ), T ) contains at most n − 1 edges and d(R ) = h(λ).We analyze the execution of Function Update-Label by λ at the end of phase p.By Lemma 5.5, λ or λ confirms T as a result of their meeting prior to the completion of phase p by λ , i.e., prior to the execution of Function Update-Label we consider.
The agent λ learns this fact in line 5 of Function Update-Label.Then, the condition in line 7 of Function Update-Label is satisfied by assumption, and λ verifies this condition by checking whether the length of T does not exceed 2(n − 1).Consequently, λ finds in line 9 of Function Update-Label a transition ϕ that maps the node at the end of T in V 3(n−1) (h(λ )) to the root of V 3(n−1) (h(λ)), because d(R ) = h(λ).Since R is of length at most n − 1, λ sets f λ (y) = 1 (in the 'for' loop in lines 10-11 of Function Update-Label) for each node y at depth at most 2(n − 1) in V 3(n−1) (h(λ )) corresponding to h(λ ).The latter is due to the fact that α p (λ) is complete with respect to λ .This proves that α p+1 (λ ) is semi-complete with respect to λ .See Figure 5, where the root and some nodes that correspond to the initial position of λ have been marked on V 3(n−1) (h(λ)), and we show a transition that allows to determine all nodes in the view of λ to the depth 2(n − 1) corresponding to h(λ ).In view of the next lemma, upon completion of phase 3 an agent has correctly situated all nodes corresponding to initial positions of all agents to depth 2(n − 1) in its view.Lemma 5.11 Let λ be any agent.Then, α 4 (λ) is semi-complete with respect to each agent λ .

.Figure 1 :
Figure 1: (a) configuration C 1 in a ring of size m = 5; (b) configuration C 2 in the corresponding ring of size 4tm.Special nodes are encircled.