Leader Election for Anonymous Asynchronous Agents in Arbitrary Networks
Abstract
We study 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.
keywords: leader election, anonymous network, asynchronous mobile agents
1 Introduction
1.1 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 have arbitrary fixed labelings . 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 , which is a (not necessarily simple) path in the graph.
We now describe the walk of an agent on its route. Let be the route of an agent. Let . Let , where , be an increasing sequence of reals, chosen by the adversary, that represent points in time. Let be any continuous function, chosen by the adversary, such that and . For any , we define . The interpretation of the walk is as follows: at time the agent is at the point 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 and and with walks and meet at time , if points and are identical. A meeting is guaranteed for routes and , if the agents using these routes meet at some time , 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 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 , where is known to the agents.
1.2 Our results
Assuming an upper bound 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 .
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.
1.3 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 messages was given in [22]. It was proved in [18] that this complexity is optimal for comparisonbased 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 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 lockstep, has been used, e.g., in [13, 14, 33], also in the context of rendezvous.
1.4 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.
2 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 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 of its initial position, i.e., its memory state becomes the sequence . 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 by port number , consists of appending the sequence to the current memory state of the agent. The change due to leaving a node by port consists of appending to the current memory state of the agent. The change due to meeting other agents is defined as follows. When entering a node 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 , 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 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 nonleader has to know which agent is the leader.
3 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 be a graph and a node of . We first define, for any , the truncated view at depth , by induction on . is a tree consisting of a single node . If is defined for any node in the graph, then is the portlabeled tree rooted at and defined as follows. For every node , , adjacent to , there is a child of in such that the port number at corresponding to edge is the same as the port number at corresponding to edge , and the port number at corresponding to edge is the same as the port number at corresponding to edge . Now node , for becomes the root of the truncated view .
The view from is the infinite rooted tree with labeled ports, such that is its truncation to level , for each . For an initial configuration in which node is the initial position of an agent, the view 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 and an initial configuration of agents in this graph. Let be a node occupied by an agent. A function that assigns either or to each node of is called a binary mapping for . A pair , where is a binary mapping for , such that if and only if corresponds to an initial position of an agent, is called the enhanced view from . 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 such that , we denote and , and we say that leads from to in . Since nodes of 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 nonnegative integers will be called a trail.
We define an operator , that provides the trail corresponding to a given route. More formally, if is a route in , then define to be the trail such that and are the port numbers of at and , respectively, for . We say that a trail is feasible from in , if there exists a route in such that and , and in such a case the route is denoted by .
For a sequence we denote by the sequence . For two sequences and we write to refer to the sequence .
For any agent , let denote its initial position. Consider two agents and . Consider any route leading from to and let . If , then we say that the route is a palindrome. For a given initial configuration, a palindrome is called uniform, if for any route such that , whenever is occupied by an agent, then 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 nonuniform 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 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.
4 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 nonuniform 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 is the trail corresponding to a route that leads from to , agent is the agent whose initial position is at the end of the route corresponding to and starting at . 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 the memory states of twins are identical. Consider twins and . In round they exit by the same port number and enter the next node by the same port number. If in round 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 are identical. If in round 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 . In round all agents choose the same port number and enter the next node by the same port number. There are no meetings in round . Indeed, the only meeting could be in the middle of an edge but this would mean that agents were joined by a oneedge palindrome at the beginning of round . If a pair of agents were joined by a palindrome after round , 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 . In round all agents choose the same port number and enter the next node by the same port number. If after round 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 , then no meeting occurred and the invariant carries on after round . If after round every pair of agents were at the ends of an edge with both ports and the agents chose this port in round , 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 and agents are again in pairs at the ends of edges with both ports . Thus the invariant holds at the end of round .
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 exists. Consider an “almost” oriented ring of size : 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 (cf. Fig. 1 (a)). This configuration satisfies condition CE: agents have different views. Hence algorithm 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 rounds.
Now consider a ring of size in which there are special nodes at distances : 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 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 (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 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 that is initially situated at the special node antipodal to the special node with both neighbors hosting agents. Consider the agent initially situated at the special node that is clockwise from and closest to . In the first rounds of the execution of starting from configuration , memory states of agents and are identical to memory states of the agent initially situated at the special node of configuration . This is due to the large size of the ring in configuration . Hence if in configuration agent elects itself, then in configuration agents and elect each of them itself as the leader after rounds. If in configuration agent elects its neighbor, then in configuration agents and elect each of them their neighbor as the leader after rounds. In both cases two different agents are elected, which is a contradiction.
5 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 , 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.
5.1 Additional notions and auxiliary results
Let be a graph and let be any node of . For any integer , we define the code of as the sequence of integers obtained as follows. Perform the complete depth first search traversal of , 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 is the th traversed edge, when going from to during the traversal of , then the th and th elements of are the port numbers of at and , respectively. The following is a direct consequence of this definition.
Proposition 5.1
Let and be any nodes of and let be an integer. if and only if .
Let be an integer. We extend the notion of binary mappings to the truncated views. We say that is a binary mapping for , if assigns either or to each node of . If is a binary mapping for (or for for some ), then (where , respectively) refers to restricted to the nodes of . Given two binary mappings for , we write if for each node of . If is the enhanced view from and is a binary mapping for such that , then the pair is called a partially enhanced view from . Intuitively, in a partially enhanced view only some nodes corresponding to initial positions of agents are marked.
Let be the enhanced view from , where is selected so that there exists an agent with . Then, 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 . Thus, as stated in Corollary 5.1, complete identifiers identify agents with different enhanced views.
Proposition 5.2
([29]) For a node graph and for all nodes and of , if and only if .
Proposition 5.3
([29]) For a node graph , for all nodes and of , if and are the enhanced views from and , respectively, then if and only if .
Corollary 5.1
For a node graph and for any agents and , the enhanced views from and are equal if and only if the complete identifiers of and are equal.
A sequence of the form is called a label, if the following conditions hold:

is a node of , and and are integers,

is a binary mapping for for each .

is the binary mapping for that assigns only to the root, and for every index .
Moreover, we say that is the length of the label , denoted by . Let be the set of all labels of length at most .
5.2 The algorithm
In this section we give a highlevel description of the algorithm and its pseudocode 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 and form a tunnel if for some and for some . Moreover, we say that the route is the tunnel core with respect to . Note that if is the tunnel core with respect to , then is the tunnel core with respect to .
Proposition 5.4
([11]) Let be an agent with route , . If and form a tunnel with the tunnel core , then and are guaranteed to have a meeting such that and are the routes of the agents traversed till the meeting, where .
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 be the set of all integer sequences with terms in , whose length is even and equals at most . Then, we define
(1) 
and let be the th triple in , .
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 . After the first phase each agent computes its label used in phase . These labels are defined in such a way that there exist two agents and with different labels. The aim of phase is that agents and correctly identify each other’s initial positions in their respective views. After phase 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 is denoted by , . Label is computed before the start of phase , and is computed at the end of phase , for . Label is used to elect the leader at the end of the algorithm. Each phase is divided into stages. By we denote the route traversed by agent till the end of stage in phase , , . As we prove later, each agent starts and ends each stage at its initial position . Let be the route of an agent traversed till the beginning of phase , and hence till the end of phase , whenever . Hence, is the route traversed by prior to the beginning of the first phase.
Now we give an informal description of Algorithm . This algorithm is executed by each agent, and in the pseudocode is used to refer to the executing agent. Note that the upper bound on the number of nodes of is given as an input. The pseudocode of the algorithm and pseudocodes of its subroutines are in frames. In the informal description we refer to lines of these pseudocodes.
First, we discuss Procedure that is called at the beginning of Algorithm . The agent starts by computing . This can be done knowing , without any exploration of the graph. Then, the agent computes by performing a DFS traversal of to the depth (line ). The function is set (line ) to be the binary mapping for that assigns to all nodes of except for the root. Hence, is a partially enhanced view from . The value of , that will be the label of in the first phase, is set to (line ).
Procedure Input: An upper bound on the size of . begin Compute . Compute by performing a DFS traversal of graph to depth that ends at . Let be the binary mapping for that assigns only to the root of . end
Now we informally describe the main part of Algorithm , refering to the lines of the pseudocode given below. The th iteration of the main ‘for’ loop in lines  is responsible for the traversal performed by the agent in phase , . An internal ‘for’ loop in lines  is executed and its th iteration determines the behavior of in stage . The stage of each phase ‘processes’ the th element of . If , then the agent does not move in this stage and proceeds to the next one. Otherwise let (we describe only this case as the other one is symmetric). The agent checks in line whether a certain trail is feasible from , and if it is not, then the stage ends. As we prove later, the verification of the feasibility of can be done by inspecting . If is feasible from , then follows the route (line ), which guarantees that:

if the agent is located at at the beginning of stage , then is located at at the end of stage (see Lemma 5.3), and

if the route leads from to the initial position of another agent and , then the routes and form a tunnel.
The agent ends phase by updating its label. This is done by calling Function in line , which produces a binary mapping that is used to update the label in line . After completing the tree phases (for ) the agent calls Procedure which completes the task of leader election.
In order to formally describe the trail mentioned above we need the following notation. Let be a label of length , let and let be a node of . We define to be the trail that corresponds to the route performed till the end of stage of phase by an agent whose label equals in phase , , and whose initial position corresponds to the root of the truncated view in . We prove (see Lemma 5.2) that, for any and the trail can be computed on the basis of and . The trail mentioned above is .
Algorithm Input: An upper bound on the size of . begin Call . for to do for to do if and is feasible from then Follow the route . else if and is feasible from then Follow the route . end if end for , where is the memory state of . end for Call . end
Figure 2 illustrates the routes of a pair of agents and that execute one iteration of the internal ‘for’ loop in lines  of , for the same values of and , such that . We assume in this example that leads from to in . Figure 2 gives the prefixes of two routes and traversed by the two agents. The fact that the routes form a tunnel (as shown in Figure 2) follows from Lemma 5.5 proven later.
The routes in Figure 2 are extended to and once goes from to its initial position by following the route in , and follows in order to return to , respectively. Note that the routes , and are not edge disjoint.
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 on the size of the graph is known, and we take advantage of knowing 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 . Suppose that agents and meet. We say that confirms as a result of this meeting if

is in stage of phase and is in stage of phase , where , or and ,

, where ,

if and are the trails traversed by and , respectively, till the meeting, then
where and when , and and otherwise.
As we prove in Section 5.3, if an agent confirms as a result of a meeting with , then .
Figure 3 depicts the equation in part 3 of Definition 5.1. Figure 3(a) presents the trail
that is a perfix of the trail corresponding to the route followed by the agent till the end of stage of phase . Figure 3(b) presents the trails (dashed line) and (dotted line).
It remains to describe Function and Procedure that are called in the Algorithm .
Function Input: A memory state of an agent . Output: A binary mapping for . begin Let be the binary mapping for that assigns only to the root of . Let be the memory states of all agents previously met by , at the times of the respective meetings. for to do Let if , and let if , where . if or the agent with the memory state confirms then , where is the node of at the end of from the root. if the length of is at most then Compute transition from to such that is the root of . for each such that do end if end if end for return end
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 takes as an input the current memory state of an agent and returns a binary mapping for its view , such that is a partially enhanced view for agent . Agent considers memory states of all previously met agents at the times of the meetings. The memory state , , of an agent and the memory state of at the time of their meeting permit the agent to verify whether or confirmed as a result of their meeting. If one of the agents confirms , 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 and connecting the initial positions of the two agents. Afterwards, if this route is of length at most , then recursively calls Function for the memory state (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 , 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 at the end of phase executed by agent permits to compute .
In the formulation of Function we use the following notions. Let and be two nodes of . We say that a function assigning to each node of a node of is a transition from to , if and correspond to the same node of for each node of . For any trail and any node , we say that a node at depth in is at the end of from the root, if the length of is and the sequence of ports corresponding to the simple path from the root of to is .
In the following example we illustrate one iteration of the ‘for’ loop in lines  of Function . The graph is given in Figure 4(a), and let be an upper bound that was initially provided to each agent.
The black nodes of are the initial positions of some agents. Denote by and the agents whose initial positions are and , respectively. Note that the views from any two nodes of are identical in this case. However, the enhanced view from each node of is unique. We focus on the instance of Function executed by during its meeting with . For simplicity, we show only some subtrees of and in Figures 4(b) and 4(c), respectively. Note that the nodes of , and therefore the nodes of any view, are unlabeled and we provide the labels only for the illustrative purpose. In this example the trail , computed in line of Function equals , which determines the node of the truncated view that corresponds to the root of . The black nodes of both views correspond to the initial positions of agents that and determined prior to this meeting. The dotted arrows give the part of the transition that maps the nodes of to the black nodes of . It follows from the definition of the view that, in general, more than one node of can be mapped by to a node of .
We finally present Procedure that is called by Algorithm after the third phase. The leader is selected by an agent on the basis of the label . Let be a node at depth at most in and satisfying . Let be a subtree of depth of rooted at . We prove later that the pair is the complete identifier of some agent. Since the initial positions of all agents have been detected till the end of phase , the agent can determine all complete identifiers and hence elect the leader.
Procedure begin for each node of such that do Let be restricted to the nodes of , where corresponds to . Compute trail such that . if for each such that then end for Find such that , where is in lexicographic order. Elect the agent whose initial position is to be the leader. end
5.3 Correctness of the algorithm
This section is devoted to the proof that Algorithm 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 is enough to check if a trail of any length is feasible from .
Lemma 5.1
Let be any node of . Using , the truncated view can be computed for any positive integer .
Proof: If , then is a subtree of , so we may assume that . We extend the view to for each . To this end we perform the following computation for each node at depth of . Let be the node of that corresponds to . Note that the subtree of rooted at and containing all descendants of in is equal to . Hence, there exists a node in such that corresponds to , in view of the connectedness of . This implies that there exists a node in such that the subtree of consisting of and all its descendants to depth from is equal to . Hence, one can find any such node of . Let be the node of that corresponds to . Due to Proposition 5.2, is equal to . Since belongs to we obtain that is a subtree of rooted at , and therefore we can extend the subtree by replacing in the subtree rooted at with .
Corollary 5.2
Let be any node of and let be any node of . Then, the subtree of to depth and rooted at can be computed for any , using .