This paper was converted on www.awesomepapers.org from LaTeX by an anonymous user.
Want to know more? Visit the Converter page.

A Near Time-optimal Population Protocol for Self-stabilizing Leader Election on Rings with a Poly-logarithmic Number of States

Daisuke Yokota Osaka UniversitySuitaOsakaJapan d-yokota@ist.osaka-u.ac.jp Yuichi Sudo Hosei UniversityKoganeiTokyoJapan sudo@hosei.ac.jp Fukuhito Ooshita Fukui University of TechnologyFukuiFukuiJapan f-oosita@fukui-ut.ac.jp  and  Toshimitsu Masuzawa Osaka UniversitySuitaOsakaJapan masuzawa@ist.osaka-u.ac.jp
(2023)
Abstract.

We propose a self-stabilizing leader election (SS-LE) protocol on ring networks in the population protocol model. Given a rough knowledge ψ=logn+O(1)\psi=\lceil\log n\rceil+O(1) on the population size nn, the proposed protocol lets the population reach a safe configuration within O(n2logn)O(n^{2}\log n) steps with high probability starting from any configuration. Thereafter, the population keeps the unique leader forever. Since no protocol solves SS-LE in o(n2)o(n^{2}) steps with high probability, the convergence time is near-optimal: the gap is only an O(logn)O(\log n) multiplicative factor. This protocol uses only polylog(n)\mathrm{polylog}(n) states. There exist two state-of-the-art algorithms in current literature that solve SS-LE on ring networks. The first algorithm uses a polynomial number of states and solves SS-LE in O(n2)O(n^{2}) steps, whereas the second algorithm requires exponential time but it uses only a constant number of states. Our proposed algorithm provides an excellent middle ground between these two.

population protocols, leader election, self-stabilization
copyright: acmcopyrightjournalyear: 2023doi: XXXXXXX.XXXXXXXconference: ACM Symposium on Principles of Distributed Computing; June 19–23, 2023; Orlando, FLprice: 15.00isbn: 978-1-4503-XXXX-X/18/06ccs: Theory of computation Distributed algorithms

1. Introduction

We consider the population protocol (PP) model (Angluin et al., 2006) in this paper. A network called population consists of a large number of finite-state automata, called agents. Agents make interactions (i.e., pairwise communication) with each other to update their states. A population is modeled by a graph G=(V,E)G=(V,E), where VV represents the set of agents, and EE indicates a set of possible interactions, that is, which pair of agents can interact. Each pair of agents (u,v)E(u,v)\in E has interactions infinitely often, while each pair of agents (u,v)E(u^{\prime},v^{\prime})\notin E never has an interaction. At each time step, one pair of agents chosen uniformly at random from all pairs in EE has an interaction. This assumption enables us to evaluate time complexities of population protocols in terms of in expectation and/or with high probability. Almost all studies in the population protocol model make this assumption when they evaluate time complexities of population protocols. In the field of population protocols, many efforts have been devoted to devising protocols for a complete graph, i.e., a population where every pair of agents interacts infinitely often, while several studies (Alistarh et al., 2022; Angluin et al., 2008b, 2006; Beauquier et al., 2013; Canepa and Potop-Butucaru, 2007; Chen and Chen, 2019; Cordasco and Gargano, 2017; Mertzios et al., 2014; Sudo et al., 2014, 2016, 2020a, 2018) have investigated populations forming graphs other than complete graphs.

Self-stabilization (Dijkstra, 1974) is a fault-tolerant property whereby, even when any number and kinds of faults occur, the network can autonomously recover from the faults. Formally, self-stabilization is defined as follows: (i) starting from an arbitrary configuration, a network eventually reaches a safe configuration (convergence), and (ii) once a network reaches a safe configuration, it maintains its specification forever (closure). Self-stabilization is of great importance in the PP model because this model typically represents a network consisting of a large number of inexpensive and unreliable nodes, which requires strong fault tolerance. Consequently, many studies have been devoted to self-stabilizing population protocols (Angluin et al., 2008b; Beauquier et al., 2013; Cai et al., 2012; Canepa and Potop-Butucaru, 2007; Chen and Chen, 2019; Fischer and Jiang, 2006; Izumi, 2015; Sudo et al., 2014, 2021a, 2016, 2012, 2020a, 2018, 2020b; Yokota et al., 2021). For example, Angluin, Aspnes, Fischer, and Jiang (Angluin et al., 2008b) proposed self-stabilizing protocols for a variety of problems, i.e., leader election in rings, token circulation in rings with a pre-selected leader, 2-hop coloring in degree-bounded graphs, consistent global orientation in undirected rings, and spanning tree construction in regular graphs. Sudo, Ooshita, Kakugawa, Masuzawa, Datta, and Larmore (Sudo et al., 2016, 2018) gave a self-stabilizing 2-hop coloring protocol that uses much smaller memory space of agents. Sudo, Shibata, Nakamura, Kim, and Masuzawa (Sudo et al., 2021b) investigated the possibility of self-stabilizing protocols for leader election, ranking, degree recognition, and neighbor recognition on arbitrary graphs.

The self-stabilizing leader election (SS-LE) has received the most attention among problems related to self-stabilization in the PP model. This is because leader election is one of the most fundamental problems, and several important protocols (Angluin et al., 2008b, 2006, a) assume a pre-selected unique leader. In particular, Angluin, Aspnes, Eisenstat (Angluin et al., 2008a) show that all semi-linear predicates can be solved very quickly (i.e., O~(n)\tilde{O}(n) steps with high probability) if we have a unique leader (although their algorithm is not self-stabilizing). Unfortunately, SS-LE is impossible to solve without an additional assumption even if we focus only on complete graphs (Angluin et al., 2008b; Cai et al., 2012; Sudo et al., 2021b). Many studies are devoted to overcome this impossibility by making an additional assumption, restricting topology, and/or slightly relaxing the requirements of SS-LE (Angluin et al., 2008b; Beauquier et al., 2013; Burman et al., 2021; Cai et al., 2012; Canepa and Potop-Butucaru, 2007; Chen and Chen, 2019, 2020; Fischer and Jiang, 2006; Izumi, 2015; Sudo et al., 2014, 2021a, 2016, 2012, 2020a, 2018, 2020b, 2021b; Yokota et al., 2021). sf

Some studies (Burman et al., 2021; Cai et al., 2012; Sudo et al., 2021b) assume that every agent knows the exact number of agents. With this assumption, Cai, Izumi, and Wada (Cai et al., 2012) gave an SS-LE protocol for complete graphs, Burman, Chen, Chen, Doty, Nowak, Severson, and Xu (Burman et al., 2021) gave faster protocols in the same setting, and Sudo et al. (Sudo et al., 2021b) gave an SS-LE protocol for arbitrary graphs.

Several studies (Beauquier et al., 2013; Canepa and Potop-Butucaru, 2007; Fischer and Jiang, 2006) employs oracles, a kind of failure detectors to overcome the impossibility of SS-LE. Fischer and Jiang (Fischer and Jiang, 2006) introduced an oracle Ω?\Omega? that eventually tells all agents whether or not at least one agent satisfy a given condition, e.g. being a leader or having a special token. They proposed two SS-LE protocols using Ω?\Omega?, one for complete graphs and the other for rings. After that, Canepa and Potop-Butucaru (Canepa and Potop-Butucaru, 2007) proposed two SS-LE protocols that use Ω?\Omega?, i.e., a deterministic protocol for trees and a randomized protocol for arbitrary graphs. Beauquier, Blanchard, and Burman (Beauquier et al., 2013) presented a deterministic SS-LE protocol for arbitrary graphs that uses two kinds of Ω?\Omega?.

Another class of studies (Angluin et al., 2008b; Chen and Chen, 2019, 2020; Fischer and Jiang, 2006; Yokota et al., 2021) restricts the topology of a graph to avoid the impossibility of SS-LE. A class 𝒢\mathcal{G} of graphs is called simple if there does not exist a graph in 𝒢\mathcal{G} which contains two disjoint subgraphs that are also in 𝒢\mathcal{G}. Angluin et al. (Angluin et al., 2008b) proved that there exists no SS-LE protocol that works for all the graphs in any non-simple class. If we focus on a simple class of graphs, there may exist an SS-LE protocol for all graphs in the class. As a typical example, the class of rings is simple. Angluin et al. (Angluin et al., 2008b) gave an SS-LE protocol that works for all rings whose sizes are not multiples of a given integer kk (for example, rings of odd size). They posed a question whether SS-LE is solvable or not for general rings (i.e., rings of any size) without any oracle, while Fischer and Jiang (Fischer and Jiang, 2006) solved SS-LE for general rings using oracle Ω?\Omega?. This question had been open for a decade until Chen and Chen (Chen and Chen, 2019) gave an SS-LE protocol for general rings. These three protocols given by (Angluin et al., 2008b; Chen and Chen, 2019; Fischer and Jiang, 2006) use only a constant number of states per agent. The expected convergence times (i.e., the expected numbers of steps required to elect a unique leader starting from any configuration) of the protocols proposed by (Angluin et al., 2008b; Fischer and Jiang, 2006) are Θ(n3)\Theta(n^{3}), while the protocol given by (Chen and Chen, 2019) requires an exponentially long convergence time. Here, the convergence time of the protocol of (Fischer and Jiang, 2006) is bounded by Θ(n3)\Theta(n^{3}) assuming that the oracle immediately reports the absence of the leader to each agent. Yokota, Sudo, and Masuzawa (Yokota et al., 2021) gave a time-optimal SS-LE protocol for rings: it elects a unique leader within Θ(n2)\Theta(n^{2}) steps in expectation starting from any configuration and uses O(n)O(n) states, given an upper bound NN on the population size nn such that N=n+O(n)N=n+O(n). Note that this knowledge is equivalent to the knowledge ψ=logn+O(1)\psi=\lceil\log n\rceil+O(1), which we will assume in this paper. Chen and Chen (Chen and Chen, 2020) extended their protocol on rings so that it can work on arbitrary regular graphs.

Several studies (Izumi, 2015; Sudo et al., 2014, 2021a, 2016, 2012, 2020a, 2018, 2020b) slightly relax the requirement of the original self-stabilization and gave loosely-stabilizing leader election protocols. Specifically, the studies of this category allow a population to deviate from the specification of the problem (i.e., a unique leader) after the population satisfies the specification for an extremely long time. This concept was introduced by (Sudo et al., 2012). The protocols given by (Izumi, 2015; Sudo et al., 2021a, 2012, 2020b) work for complete graphs and those given by (Sudo et al., 2014, 2016, 2020a, 2018) work for arbitrary graphs.

Table 1. Self-Stabilizing Leader Election on Rings (Convergence time is shown in the expected number of steps.)
Assumption Convergence Time #states
(Angluin et al., 2008b) nn is not multiple of a given kk Θ(n3)\Theta(n^{3}) O(1)O(1)
(Fischer and Jiang, 2006) oracle Ω?\Omega? Θ(n3)\Theta(n^{3}) O(1)O(1)
(Chen and Chen, 2019) none exponential O(1)O(1)
(Yokota et al., 2021)   knowledge ψ=logn+O(1)\psi=\lceil\log n\rceil+O(1) Θ(n2)\Theta(n^{2}) O(n)O(n)
this work   knowledge ψ=logn+O(1)\psi=\lceil\log n\rceil+O(1) O(n2logn)O(n^{2}\log n) polylog(n)\mathrm{polylog}(n)

Our Contribution

We propose an SS-LE protocol P𝑃𝐿P_{\mathit{PL}} that works only for rings. Specifically, given an integer ψ=logn+O(1)\psi=\lceil\log n\rceil+O(1), P𝑃𝐿P_{\mathit{PL}} elects a unique leader in O(n2logn)O(n^{2}\log n) steps both in expectation and with high probability on any ring and uses polylog(n)\mathrm{polylog}(n) states. The results on SS-LE on rings are summarized in Table 1. This work drastically reduces the number of agent states of (Yokota et al., 2021) by slightly sacrificing the expected convergence time under the same assumption. One can easily prove that no protocol solves SS-LE in o(n2)o(n^{2}) expected steps, thus our protocol is near time-optimal.

The main technical contribution of this paper is a novel mechanism that largely improves the number of states required to detect the absence of a leader in the population compared to (Yokota et al., 2021). The protocol given by (Yokota et al., 2021) requires O(n)O(n) states to detect the absence of a leader, but our mechanism requires only polylog(n)\mathrm{polylog}(n) states. In addition, protocol P𝑃𝐿P_{\mathit{PL}} uses the same method as (Yokota et al., 2021) to decrease the number of leaders to one. As a result, protocol P𝑃𝐿P_{\mathit{PL}} requires only O(n2logn)O(n^{2}\log n) expected steps, while the existing three SS-LE protocols for rings (Angluin et al., 2008b; Chen and Chen, 2019; Fischer and Jiang, 2006) requires Ω(n3)\Omega(n^{3}) expected steps.

Our protocol (and the protocol given in (Yokota et al., 2021)) assumes that the rings are oriented or directed. 111 The protocol with super-exponential convergence time in (Chen and Chen, 2019) is also designed for directed rings, but it works for undirected rings without sacrificing any complexity by using a known self-stabilizing ring-orientation protocol (Angluin et al., 2008b) that uses only O(1)O(1) states and requires a polynomial convergence time. Unfortunately, we cannot use this ring-orientation protocol (Angluin et al., 2008b) for our SS-LE protocol because we conjecture that the convergence time of the ring-orientation protocol is ω(n2logn)\omega(n^{2}\log n) steps. However, this does not lose generality because we can remove this assumption: in Section 5, we give a self-stabilizing ring orientation protocol that uses only a constant number of states and requires O(n2logn)O(n^{2}\log n) steps in expectation and with high probability.

Relation with SS-LE protocols in the standard distributed computing model

Generally, the model of population protocols is very different than the standard models of distributed computing such as the state-reading model and the message passing model. Unlike those models, in the population protocols, (i) nodes are anonymous, (ii) nodes cannot distinguish their neighbors or even recognize their degree, and (iii) nodes update their states in pairs (they do not have the ability to observe the current states of all their neighbors when they update their states). These are the weak points of population protocols. On the strong side, the population protocols usually assume the random scheduler: at each time step, one pair of neighboring agents is chosen uniformly at random to interact. The random scheduler enables us to (loosely) synchronize the population and utilize randomization even with deterministic algorithms. Our algorithm fully makes use of this assumption to achieve a fast convergence time with O(loglogn)O(\log\log n) bits per node.

When we focus on rings, the second weak point disappears because then every node knows that its degree is exactly two, thus the population protocols become a little bit close to the standard models. To the best of our knowledge, every SS-LE algorithm on standard models in the literature that has O(loglogn)O(\log\log n) bits and is designed for anonymous systems has a larger convergence time than ours. The fastest one among such algorithms is given by Awerbuch and Ostrovsky (Awerbuch and Ostrovsky, 1994) (Strictly speaking, some of those algorithms have much smaller convergence time, but we exclude them because they require strong knowledge such as the exact value of mnm_{n}, where mnm_{n} is the smallest integer not dividing the network size nn.) This algorithm uses O(logn)O(\log^{*}n) bits and requires O(nlog2n)O(n\log^{2}n) asynchronous rounds to solve SS-LE. Even if we can simulate their algorithm without additional cost in the model of population protocols, the convergence time would become O(n2log3n)O(n^{2}\log^{3}n) steps in expectation, which is larger than our algorithm. (Our algorithm converges in O(n2logn)O(n^{2}\log n) steps with O(loglogn)O(\log\log n) bits per node. And, it requires Θ(nlogn)\Theta(n\log n) steps in expectation to let every node have an interaction at least once.) Moreover, it requires careful discussion about the possibility to simulate algorithms designed for ordinary models by population protocols. In particular, when we use a small number of bits of agent memory such as O(loglogn)O(\log\log n) bits, there is no way in the literature to simulate the message passing model or state-reading model.

2. Preliminaries

A population is a weakly connected digraph G(V,E)G(V,E), where VV is a set of agents and EV×VE\subseteq V\times V is a set of arcs. Define n=|V|n=|V| and assume n2n\geq 2. Each arc represents a possible interaction (or communication between two agents): If (u,v)E(u,v)\in E, agents uu and vv can interact with each other, where uu serves as an initiator and vv serves as a responder. If (u,v)E(u,v)\notin E, such an interaction never occurs. In this paper, we consider only a population represented by a directed ring, i.e., we assume that V={u0,u1,,un1}V=\{u_{0},u_{1},\dots,u_{n-1}\} and E={(ui,ui+1modn)i=0,1,,n1}E=\{(u_{i},u_{i+1\bmod n})\mid i=0,1,\dots,n-1\}. Here, we use the indices of the agents only for simplicity of description, and the agents cannot access their indices. The agents are anonymous, i.e., they do not have unique identifiers. We call ui1modnu_{i-1\bmod n} and ui+1modnu_{i+1\bmod n} the left neighbor and the right neighbor of uiu_{i}, respectively. We omit “modulo by nn” (i.e., modn\bmod~{}n) in the indices of agents when no confusion occurs. We sometimes denote “left to right” direction by clockwise direction, and “right to left” direction by counter-clockwise direction.

A protocol P(Q,Y,T,π𝑜𝑢𝑡)P(Q,Y,T,\pi_{\mathit{out}}) consists of a finite set QQ of states, a finite set YY of output symbols, transition function T:Q×QQ×QT:Q\times Q\to Q\times Q, and an output function π𝑜𝑢𝑡:QY\pi_{\mathit{out}}:Q\to Y. When an interaction between two agents occurs, TT determines the next states of the two agents based on their current states. The output of an agent is determined by π𝑜𝑢𝑡\pi_{\mathit{out}}: the output of agent vv with state qQq\in Q is π𝑜𝑢𝑡(q)\pi_{\mathit{out}}(q). We assume that all agents have a common knowledge ψ=logn+O(1)\psi=\lceil\log n\rceil+O(1). Thus, the components QQ, TT, and π𝑜𝑢𝑡\pi_{\mathit{out}} may depend on ψ\psi. However, for simplicity, we do not explicitly write protocol PP as parameterized with ψ\psi, e.g., P(ψ)=(Q(ψ),T(ψ),π𝑜𝑢𝑡(ψ))P(\psi)=(Q(\psi),T(\psi),\pi_{\mathit{out}}(\psi)).

A configuration is a mapping C:VQC:V\to Q that specifies the states of all the agents. We denote the set of all configurations of protocol PP by 𝒞all(P)\mathcal{C}_{\mathrm{all}}(P). We simply denote it by 𝒞all\mathcal{C}_{\mathrm{all}} when protocol PP is clear from the context. We say that configuration CC changes to CC^{\prime} by an interaction e=(ui,ui+1)e=(u_{i},u_{i+1}), denoted by CeCC\stackrel{{\scriptstyle e}}{{\to}}C^{\prime} if we have (C(ui),C(ui+1))=T(C(ui),C(ui+1))(C^{\prime}(u_{i}),C^{\prime}(u_{i+1}))=T(C(u_{i}),C(u_{i+1})) and C(v)=C(v)C^{\prime}(v)=C(v) for all vV{ui,ui+1}v\in V\setminus\{u_{i},u_{i+1}\}. We simply write CCC\to C^{\prime} if there exists eEe\in E such that CeCC\stackrel{{\scriptstyle e}}{{\to}}C^{\prime}. We say that a configuration CC^{\prime} is reachable from CC if there exists a sequence of configurations C0,C1,,CkC_{0},C_{1},\dots,C_{k} such that C=C0C=C_{0}, C=CkC^{\prime}=C_{k}, and CiCi+1C_{i}\to C_{i+1} for all i=0,1,,k1i=0,1,\dots,k-1. We also say that a set 𝒞\mathcal{C} of configurations is closed if no configuration outside 𝒞\mathcal{C} is reachable from any configuration in 𝒞\mathcal{C}.

A scheduler determines which interaction occurs at each time step (or just step). In this paper, we consider a uniformly random scheduler 𝚪=Γ0,Γ1,\mathbf{\Gamma}=\Gamma_{0},\Gamma_{1},\dots: each ΓtE\Gamma_{t}\in E is a random variable such that Pr(Γt=(ui,ui+1))=1/n\Pr(\Gamma_{t}=(u_{i},u_{i+1}))=1/n for any t0t\geq 0 and i=0,1,,n1i=0,1,\dots,n-1. Each Γt\Gamma_{t} represents the interaction that occurs at step tt. Given an initial configuration C0C_{0}, the execution of protocol PP under 𝚪\mathbf{\Gamma} is defined as ΞP(C0,𝚪)=C0,C1,\Xi_{P}(C_{0},\mathbf{\Gamma})=C_{0},C_{1},\dots such that CtΓtCt+1C_{t}\stackrel{{\scriptstyle\Gamma_{t}}}{{\to}}C_{t+1} for all t0t\geq 0. We denote ΞP(C0,𝚪)\Xi_{P}(C_{0},\mathbf{\Gamma}) simply by ΞP(C0)\Xi_{P}(C_{0}) when no confusion occurs.

We address the self-stabilizing leader election problem in this paper. For simplicity, we give the definition of a self-stabilizing leader election protocol instead of giving the definitions of self-stabilization and the leader election problem separately.

Definition 2.1 (Self-stabilizing Leader Election).

For any protocol PP, we say that a configuration CC of PP is safe if (i) exactly one agent outputs LL (leader) and all other agents output FF (follower) in CC, and (ii) at every configuration reachable from CC, all agents keep the same outputs as those in CC. A protocol PP is a self-stabilizing leader election (SS-LE) protocol if ΞP(C0,𝚪)\Xi_{P}(C_{0},\mathbf{\Gamma}) reaches a safe configuration with probability 11 for any configuration C0𝒞all(P)C_{0}\in\mathcal{C}_{\mathrm{all}}(P).

We denote interaction (ui,ui+1)(u_{i},u_{i+1}) by eie_{i}. For any two sequences of interactions s=ek0,ek1,,ekhs=e_{k_{0}},e_{k_{1}},\dots,e_{k_{h}} and s=ek0,ek1,,ekjs^{\prime}=e_{k^{\prime}_{0}},e_{k^{\prime}_{1}},\dots,e_{k^{\prime}_{j}}, we define ss=ek0,ek1,,ekh,ek0,ek1,,ekjs\cdot s^{\prime}=e_{k_{0}},e_{k_{1}},\dots,e_{k_{h}},e_{k^{\prime}_{0}},e_{k^{\prime}_{1}},\dots,e_{k^{\prime}_{j}}. That is, we use “\cdot” for the concatenation operator. For any sequence ss of interactions and integer i1i\geq 1, sis^{i} denotes the ii-times repeating sequence of ss: s1=ss^{1}=s and si=ssi1s^{i}=s\cdot s^{i-1}. For any integer i{0,1,,n1}i\in\{0,1,\dots,n-1\} and any integer j0j\geq 0, we define 𝑠𝑒𝑞R(i,j)=ei,ei+1,,ei+j1\mathit{seq}_{R}(i,j)=e_{i},e_{i+1},\dots,e_{i+j-1} and 𝑠𝑒𝑞L(i,j)=ei1,ei2,,eij\mathit{seq}_{L}(i,j)=e_{i-1},e_{i-2},\dots,e_{i-j}. We say that a sequence ss of interactions have length \ell if it consists of \ell interactions.

Definition 2.2.

Let γ=ek1,ek2,,ekh\gamma=e_{k_{1}},e_{k_{2}},\dots,e_{k_{h}} be a sequence of interactions. We say that γ\gamma occurs within \ell steps when ek1,ek2,,ekhe_{k_{1}},e_{k_{2}},\dots,e_{k_{h}} occurs in this order (not necessarily in a row) within \ell steps. Formally, the event “γ\gamma occurs within \ell steps from a time step tt” is defined as the following event: Γti=eki\Gamma_{t_{i}}=e_{k_{i}} holds for all i=1,2,,hi=1,2,\dots,h for some sequence of integers tt1<t2<<tht+1t\leq t_{1}<t_{2}<\dots<t_{h}\leq t+\ell-1. We say that from step tt, γ\gamma completes at step t+1t+\ell-1 if γ\gamma occurs within \ell steps but does not occur within 1\ell-1 steps. When the starting step tt is clear from the context, we just write “γ\gamma occurs within \ell steps” and “γ\gamma completes at step t+1t+\ell-1”.

Lemma 2.3.

Let ss be a sequence of interactions with length \ell. Then, ss occurs within nn\ell steps in expectation. For any c1c\geq 1, ss occurs within O(cn(+logn))O(cn(\ell+\log n)) steps with probability 1nc1-n^{-c}.

Proof.

The first claim immediately follows from linearity of expectation and the fact that for any i1i\geq 1, the ii-th interaction of ss occurs with probability 1/n1/n at each step. The second claim follows from Chernoff bound (See Lemma A.1 in Appendix.). ∎

Throughout this paper, we use “with high probability”, abbreviated as w.h.p., to denote with probability 1O(1/n)1-O(1/n). The set of integers {i,i+1,,j}\{i,i+1,\dots,j\} for i<ji<j is denoted by [i,j][i,j].

Variables in Agents:
   𝚕𝚎𝚊𝚍𝚎𝚛{0,1}\mathtt{leader}\in\{0,1\},
   𝚋{0,1},𝚍𝚒𝚜𝚝[0,2ψ1],𝚕𝚊𝚜𝚝{0,1}\mathtt{b}\in\{0,1\},\mathtt{dist}\in[0,2\psi-1],\mathtt{last}\in\{0,1\},
   𝚝𝚘𝚔𝚎𝚗B,𝚝𝚘𝚔𝚎𝚗W{}(([ψ+1,1][1,ψ])×{0,1}×{0,1})\mathtt{token}_{B},\mathtt{token}_{W}\in\{\bot\}\cup(([-\psi+1,-1]\cup[1,\psi])\times\{0,1\}\times\{0,1\})
   𝚖𝚘𝚍𝚎{𝐷𝑒𝑡𝑒𝑐𝑡,𝐶𝑜𝑛𝑠𝑡𝑟𝑢𝑐𝑡},𝚌𝚕𝚘𝚌𝚔[0,κmax],𝚑𝚒𝚝𝚜[0,ψ],𝚜𝚒𝚐𝚗𝚊𝚕R[0,κmax]\mathtt{mode}\in\{\mathit{Detect},\mathit{Construct}\},\mathtt{clock}\in[0,\kappa_{\mathrm{max}}],\mathtt{hits}\in[0,\psi],\mathtt{signal}_{R}\in[0,\kappa_{\mathrm{max}}],
// κmax=Θ(ψ)=Θ(logn)\kappa_{\mathrm{max}}=\Theta(\psi)=\Theta(\log n)
   𝚋𝚞𝚕𝚕𝚎𝚝{0,1,2},𝚜𝚑𝚒𝚎𝚕𝚍{0,1},𝚜𝚒𝚐𝚗𝚊𝚕B{0,1}\mathtt{bullet}\in\{0,1,2\},\mathtt{shield}\in\{0,1\},\mathtt{signal}_{B}\in\{0,1\}
1
𝙲𝚛𝚎𝚊𝚝𝚎𝙻𝚎𝚊𝚍𝚎𝚛()\mathtt{CreateLeader}()
  // Create a leader when no leader exists.
𝙴𝚕𝚒𝚖𝚒𝚗𝚊𝚝𝚎𝙻𝚎𝚊𝚍𝚎𝚛𝚜()\mathtt{EliminateLeaders}()
  // Decrease #leaders to one when #leaders 2\geq 2.
Algorithm 1 P𝑃𝐿P_{\mathit{PL}}
Lemma 2.4.

For any SS-LE protocol PP and a function f:f:\mathbb{N}\to\mathbb{R}, the convergence time (i.e., the number of steps to reach a safe configuration) of PP is O(f(n))O(f(n)) steps in expectation if the convergence time of PP is bounded by f(n)f(n) steps w.h.p.

Proof.

Let X=maxC𝒞all(P)En(C)X=\max_{C\in\mathcal{C}_{\mathrm{all}}(P)}E_{n}(C), where En(C)E_{n}(C) is the expected convergence time when the initial configuration is CC. Then, we have Xf(n)+O(1/n)XX\leq f(n)+O(1/n)\cdot X because a self-stabilizing protocol must deal with an arbitrary initial configuration. Solving the inequality gives maxC𝒞all(P)En(C)=O(f(n))\max_{C\in\mathcal{C}_{\mathrm{all}}(P)}E_{n}(C)=O(f(n)). ∎

Note that this lemma depends on the assumption that PP is self-stabilizing. We cannot use this kind of translation from “w.h.p. time” to “expected time” for non-self-stabilizing algorithms.

3. Self-Stabilizing Leader Election on a Ring

In this section, we prove the following theorem.

Theorem 3.1.

If knowledge ψ=logn+O(1)\psi=\lceil\log n\rceil+O(1) is given, there exists a self-stabilizing leader election protocol PP that works for any directed ring such that (i) for any C0𝒞all(P)C_{0}\in\mathcal{C}_{\mathrm{all}}(P), ΞP(C0,𝚪)\Xi_{P}(C_{0},\mathbf{\Gamma}) reaches a safe configuration within O(n2logn)O(n^{2}\log n) steps both w.h.p. and in expectation, and (ii) each agent uses polylog(n)\mathrm{polylog}(n) states.

To prove the above theorem, we give an SS-LE protocol P𝑃𝐿P_{\mathit{PL}} that satisfies the requirements of the theorem. Thanks to Lemma 2.4, we consider the convergence time of P𝑃𝐿P_{\mathit{PL}} only in terms of “w.h.p.” in the rest of this paper. In addition, we assume ψ2\psi\geq 2 without loss of generality: we can solve SS-LE in a straightforward way if ψ=1\psi=1 because it yields n=2n=2.

The pseudocode of P𝑃𝐿P_{\mathit{PL}} is given in Algorithms 1, 2, 3, 4, and 5, which describes how two agents ll and rr update their states, i.e., their variables, when they have an interaction. Here, ll and rr represent the initiator and the responder in the interaction, respectively. That is, ll is the left neighbor of rr, and rr is the right neighbor of ll. We denote the value of variable 𝚟𝚊𝚛\mathtt{var} at agent vVv\in V by v.𝚟𝚊𝚛v.\mathtt{var}. Similarly, we denote the value of variable 𝚟𝚊𝚛\mathtt{var} in state qQq\in Q by q.𝚟𝚊𝚛q.\mathtt{var}. In this algorithm, each agent vVv\in V maintains an output variable v.𝚕𝚎𝚊𝚍𝚎𝚛{0,1}v.\mathtt{leader}\in\{0,1\}, according to which it determines its output. Agent vv outputs LL when v.𝚕𝚎𝚊𝚍𝚎𝚛=1v.\mathtt{leader}=1 and outputs FF when v.𝚕𝚎𝚊𝚍𝚎𝚛=0v.\mathtt{leader}=0. We say that vv is a leader if v.𝚕𝚎𝚊𝚍𝚎𝚛=1v.\mathtt{leader}=1; otherwise vv is called a follower. For each uiVu_{i}\in V, we define the distance to the nearest left leader and the distance to the nearest right leader of uiu_{i} as dLL(i)=min{j0uij.𝚕𝚎𝚊𝚍𝚎𝚛=1}d_{LL}(i)=\min\{j\geq 0\mid u_{i-j}.\mathtt{leader}=1\} and dRL(i)=min{j0ui+j.𝚕𝚎𝚊𝚍𝚎𝚛=1}d_{RL}(i)=\min\{j\geq 0\mid u_{i+j}.\mathtt{leader}=1\}, respectively. When there is no leader in the ring, we define dLL(i)=dRL(i)=d_{LL}(i)=d_{RL}(i)=\infty. By definition, dLL(i)=dRL(i)=0d_{LL}(i)=d_{RL}(i)=0 when uiu_{i} is a leader. Note that dLL(i)d_{LL}(i) and dRL(i)d_{RL}(i) are not variables maintained by agents, but just notations.

The pseudocode of the main function of P𝑃𝐿P_{\mathit{PL}} is shown in Algorithm 1, which consists of two functions 𝙲𝚛𝚎𝚊𝚝𝚎𝙻𝚎𝚊𝚍𝚎𝚛()\mathtt{CreateLeader}() and 𝙴𝚕𝚒𝚖𝚒𝚗𝚊𝚝𝚎𝙻𝚎𝚊𝚍𝚎𝚛𝚜()\mathtt{EliminateLeaders}(). To design a self-stabilizing protocol, we must consider an arbitrary initial configuration, where there may be no leader, or there may be two or more leaders. The goal of 𝙲𝚛𝚎𝚊𝚝𝚎𝙻𝚎𝚊𝚍𝚎𝚛()\mathtt{CreateLeader}() is to create a new leader when no leader exists in the population, while the goal of 𝙴𝚕𝚒𝚖𝚒𝚗𝚊𝚝𝚎𝙻𝚎𝚊𝚍𝚎𝚛𝚜()\mathtt{EliminateLeaders}() is to decrease the number of leaders to one when there are two or more leaders. Function 𝙴𝚕𝚒𝚖𝚒𝚗𝚊𝚝𝚎𝙻𝚎𝚊𝚍𝚎𝚛𝚜()\mathtt{EliminateLeaders}(), presented in (Yokota et al., 2021), decreases the number of leaders to one within O(n2logn)O(n^{2}\log n) steps with high probability using only a constant number of states. Although we use 𝙴𝚕𝚒𝚖𝚒𝚗𝚊𝚝𝚎𝙻𝚎𝚊𝚍𝚎𝚛𝚜()\mathtt{EliminateLeaders}() without any modification, we will present 𝙴𝚕𝚒𝚖𝚒𝚗𝚊𝚝𝚎𝙻𝚎𝚊𝚍𝚎𝚛𝚜()\mathtt{EliminateLeaders}() in Section 3.4 for the completeness of this paper.

3.1. Overview

The difficulty of designing 𝙲𝚛𝚎𝚊𝚝𝚎𝙻𝚎𝚊𝚍𝚎𝚛()\mathtt{CreateLeader}() lies in detecting the absence of a leader in a self-stabilizing fashion. Starting from an arbitrary configuration without a leader, the population must detect the absence of a leader and create a new leader.

The protocol presented in (Yokota et al., 2021) achieves the detection in a naive way using O(n)O(n) states, given knowledge N=n+O(n)N=n+O(n): each agent computes the distance from the nearest left leader and detects the absence of a leader when the computed distance is NN or larger. However, 𝙲𝚛𝚎𝚊𝚝𝚎𝙻𝚎𝚊𝚍𝚎𝚛()\mathtt{CreateLeader}() is allowed to use only polylog(n)\mathrm{polylog}(n) states, so we cannot take this approach. One may think that we can still use this strategy by maintaining approximate distance instead of the exact distance from the nearest left leader, in order to reduce the number of states to polylog(n)\mathrm{polylog}(n). We conjecture that this does not work. If we try to use approximate distance, the agents sometimes compute a far large distance, which results in misdetecting the absence of a leader and creating a new leader even if the population already has a unique leader. Such an event may occur extremely rarely, however, it eventually occurs even after an extremely long expected time. So, the resulting algorithm is not self-stabilizing.

The protocol presented in (Chen and Chen, 2019) detects the absence of a leader in a different way. Their protocol lets the population reach a safe configuration where exactly one leader exists and a bit-string that can prove the existence of a leader is embedded on the ring. Specifically, a prefix of the bit-string called Thue-Morse string (Thue, 1912) is embedded: each agent uiu_{i} has variable ui.B{0,1}u_{i}.B\in\{0,1\}, and sk,sk+1,,sk+n1s_{k},s_{k+1},\dots,s_{k+n-1} is a prefix of Thue-Morse string, where si=ui.Bs_{i}=u_{i}.B and uku_{k} is the unique leader. Although we do not write the definition of Thue-Morse string here, it has a good property called cube-freeness, that is, it does not contain wwwwww as a sub-string for any string ww. Using this property, the population declares the detection of the absence of a leader if and only if it finds a string wwwwww for some ww. After the population reaches a safe configuration, the cube-freeness of Thue-Morse string guarantees that the protocol does not find such a string. On the other hand, if there is no leader, the agents can eventually observe wwwwww for w=si,si+1,,si+n1w=s_{i},s_{i+1},\dots,s_{i+n-1} for some ii, letting them detect the absence of a leader. Chen and Chen (Chen and Chen, 2019) implement this idea with O(1)O(1) states per agent. However, implementing this idea is not easy, so that their protocol requires extremely long convergence time, i.e., a super-exponential number of steps in expectation and w.h.p.

Refer to caption
Figure 1. Example of embedding of segment IDs on the ring. LL represents a leader.

We embed a much simpler string on the ring to achieve much faster convergence time, i.e., O(n2logn)O(n^{2}\log n) steps, at the cost of increasing the number of states from O(1)O(1) to polylog(n)\mathrm{polylog}(n). Each uiu_{i} maintains two variables ui.𝚍𝚒𝚜𝚝{0,1,,2ψ1}u_{i}.\mathtt{dist}\in\{0,1,\dots,2\psi-1\} and ui.𝚋{0,1}u_{i}.\mathtt{b}\in\{0,1\} for the string embedding. When the embedding is complete,

(1) ui.𝚍𝚒𝚜𝚝={0if ui is a leader(ui1.𝚍𝚒𝚜𝚝+1)mod2ψotherwise\displaystyle u_{i}.\mathtt{dist}=\begin{cases}0&\text{if }u_{i}\text{ is a leader}\\ (u_{i-1}.\mathtt{dist}+1)\bmod{2\psi}&\text{otherwise}\end{cases}

must hold. We call an agent uiu_{i} that satisfies ui.𝚍𝚒𝚜𝚝{0,ψ}u_{i}.\mathtt{dist}\in\{0,\psi\} a border. We say that a sequence of agents ui,ui+1,,ui+1u_{i},u_{i+1},\dots,u_{i+\ell-1} is a segment when uiu_{i} and ui+u_{i+\ell} are borders and ui+1,ui+2,,ui+1u_{i+1},u_{i+2},\dots,u_{i+\ell-1} are not borders. Let bi=ui.𝚋b_{i}=u_{i}.\mathtt{b}. We define the ID of a segment S=ui,ui+1,,ui+1S=u_{i},u_{i+1},\dots,u_{i+\ell-1} as ι(S)=j=01bi+j2j\iota(S)=\sum_{j=0}^{\ell-1}b_{i+j}\cdot 2^{j}, that is, ι(S)\iota(S) is the integer that corresponds to a bit string bi+1bi+2bib_{i+\ell-1}b_{i+\ell-2}\dots b_{i} in the base-2 numeral system. For a segment S=ui,ui+1,,ui+1S=u_{i},u_{i+1},\dots,u_{i+\ell-1}, we denote the previous segment uj,uj+1,,ui1u_{j},u_{j+1},\dots,u_{i-1} by 𝑝𝑟𝑒𝑣(S)\mathit{prev}(S). When the embedding is complete, a segment S=ui,ui+1,,ui+1S=u_{i},u_{i+1},\dots,u_{i+\ell-1} must satisfy

(2) ι(S)=(ι(𝑝𝑟𝑒𝑣(S))+1)mod2ψorui or ui+ is a leader.\displaystyle\iota(S)=(\iota(\mathit{prev}(S))+1)\bmod{2^{\psi}}\hskip 14.22636pt\text{or}\hskip 14.22636ptu_{i}\text{ or }u_{i+\ell}\text{ is a leader.}

We say that a configuration CC is perfect if no violation occurs against (1) or (2) in CC. For any nn and ψ\psi, there exists a perfect configuration with one leader. See examples in Figure 1 (a) and (b). The segment IDs increase one by one in the clockwise direction starting with the segment that contains a leader, while we do not need to care about the IDs of the first and the last segments, which are drawn in bold curves in Figure 1. Importantly, a perfect assignment requires the existence of a leader. That is, every configuration containing no leader violates (1) or (2). For example, in Figure 1 (c) with ψ=7\psi=7, the segment with ID 8 violates condition (2) because 8(15+1)mod278\neq(15+1)\bmod{2^{7}}. This claim can be easily proved from the fact that 2ψ2logn=n2^{\psi}\geq 2^{\log n}=n and ψ2\psi\geq 2, as follows.

Lemma 3.2.

A configuration without a leader is not perfect.

Proof.

Assume for contradiction that there is a perfect configuration CC that does not have a leader. Since (1) holds for all uiu_{i} and there is no leader in CC, the length of all segments is ψ\psi, thus the number of segments is exactly n/ψ<n2ψn/\psi<n\leq 2^{\psi} in CC. This yields that there is at least one segment SS that violates (2), which contradicts the assumption. ∎

3
4𝙳𝚎𝚝𝚎𝚛𝚖𝚒𝚗𝚎𝙼𝚘𝚍𝚎()\mathtt{DetermineMode}()
5
6𝚝𝚖𝚙{0r.𝚕𝚎𝚊𝚍𝚎𝚛=1l.𝚍𝚒𝚜𝚝+1mod2ψotherwise\mathtt{tmp}\leftarrow\begin{cases}0&r.\mathtt{leader}=1\\ l.\mathtt{dist}+1\bmod{2\psi}&\text{otherwise}\end{cases}
7
  // 𝚝𝚖𝚙\mathtt{tmp} is a temporary variable
8
9if r.𝚖𝚘𝚍𝚎=𝐷𝑒𝑡𝑒𝑐𝑡𝚝𝚖𝚙r.𝚍𝚒𝚜𝚝r.\mathtt{mode}=\mathit{Detect}\land\mathtt{tmp}\neq r.\mathtt{dist} then
       (r.𝚕𝚎𝚊𝚍𝚎𝚛,r.𝚋𝚞𝚕𝚕𝚎𝚝,r.𝚜𝚑𝚒𝚎𝚕𝚍,r.𝚜𝚒𝚐𝚗𝚊𝚕B)(1,2,1,0)(r.\mathtt{leader},r.\mathtt{bullet},r.\mathtt{shield},r.\mathtt{signal}_{B})\leftarrow(1,2,1,0)
        // Create a leader.
10      
11if r.𝚖𝚘𝚍𝚎=𝐶𝑜𝑛𝑠𝑡𝑟𝑢𝑐𝑡r.\mathtt{mode}=\mathit{Construct} then
12       r.𝚍𝚒𝚜𝚝𝚝𝚖𝚙r.\mathtt{dist}\leftarrow\mathtt{tmp}
13l.𝚕𝚊𝚜𝚝{1r.𝚕𝚎𝚊𝚍𝚎𝚛=10r.𝚕𝚎𝚊𝚍𝚎𝚛=0r.𝚍𝚒𝚜𝚝{0,ψ}r.𝚕𝚊𝚜𝚝otherwisel.\mathtt{last}\leftarrow\begin{cases}1&r.\mathtt{leader}=1\\ 0&r.\mathtt{leader}=0\land r.\mathtt{dist}\in\{0,\psi\}\\ r.\mathtt{last}&\text{otherwise}\end{cases}
14 𝙼𝚘𝚟𝚎𝚃𝚘𝚔𝚎𝚗(𝚝𝚘𝚔𝚎𝚗B,0)\mathtt{MoveToken}(\mathtt{token}_{B},0)
15 𝙼𝚘𝚟𝚎𝚃𝚘𝚔𝚎𝚗(𝚝𝚘𝚔𝚎𝚗W,ψ)\mathtt{MoveToken}(\mathtt{token}_{W},\psi)
Algorithm 2 𝙲𝚛𝚎𝚊𝚝𝚎𝙻𝚎𝚊𝚍𝚎𝚛()\mathtt{CreateLeader}()   ll is the initiator and rr is the responder of an interaction.

The basic structure of 𝙲𝚛𝚎𝚊𝚝𝚎𝙻𝚎𝚊𝚍𝚎𝚛()\mathtt{CreateLeader}(), whose pseudocode is shown in Algorithm 2, is as follows.

  1. (1)

    Each agent uiu_{i} maintains a variable ui.𝚖𝚘𝚍𝚎{𝐷𝑒𝑡𝑒𝑐𝑡,𝐶𝑜𝑛𝑠𝑡𝑟𝑢𝑐𝑡}u_{i}.\mathtt{mode}\in\{\mathit{Detect},\mathit{Construct}\}. We say that uiu_{i} is in the detection mode if ui.𝚖𝚘𝚍𝚎=𝐷𝑒𝑡𝑒𝑐𝑡u_{i}.\mathtt{mode}=\mathit{Detect}; Otherwise uiu_{i} is in the construction mode. Function
    𝙳𝚎𝚝𝚎𝚛𝚖𝚒𝚗𝚎𝙼𝚘𝚍𝚎()\mathtt{DetermineMode}(), called at Line 3, determines which mode the agents in the population should be in. As we will see later, 𝙳𝚎𝚝𝚎𝚛𝚖𝚒𝚗𝚎𝙼𝚘𝚍𝚎()\mathtt{DetermineMode}() guarantees that

    • once a leader exists in the population, all agents will enter the construction mode within O(n2)O(n^{2}) steps and keep the construction mode in the next cn2logncn^{2}\log n steps for arbitrarily large constant cc w.h.p 222 Actually, this constant cc depends on the parameter κmax\kappa_{\mathrm{max}}. We can increase cc arbitrarily by increasing κmax\kappa_{\mathrm{max}} so that the whole population stays in the construction mode in a sufficiently long time. , and

    • if there is no leader, a new leader is created or all the agents will enter the detection mode within O(n2logn)O(n^{2}\log n) steps w.h.p., after which no agent goes back to the construction mode until a new leader is created.

  2. (2)

    The agents in the construction mode try to let the population reach a perfect configuration by updating variables 𝚍𝚒𝚜𝚝\mathtt{dist} and 𝚋\mathtt{b}. If all agents are in the construction mode and there is one leader, they will, within O(n2logn)O(n^{2}\log n) steps w.h.p., make a perfect configuration from which no agent changes 𝚍𝚒𝚜𝚝\mathtt{dist} and 𝚋\mathtt{b}.

  3. (3)

    The agents in the detection mode try to detect the imperfection of the current configuration. If all agents are in the detection mode and there is no leader, they will detect the imperfection and create a new leader within O(n2logn)O(n^{2}\log n) steps w.h.p.

Thus, the combination of 𝙲𝚛𝚎𝚊𝚝𝚎𝙻𝚎𝚊𝚍𝚎𝚛()\mathtt{CreateLeader}() and 𝙴𝚕𝚒𝚖𝚒𝚗𝚊𝚝𝚎𝙻𝚎𝚊𝚍𝚎𝚛𝚜()\mathtt{EliminateLeaders}() lets the population reach, within O(n2logn)O(n^{2}\log n) steps w.h.p., a safe configuration such that there is exactly one leader and no leader will be created in the following execution. Function 𝙴𝚕𝚒𝚖𝚒𝚗𝚊𝚝𝚎𝙻𝚎𝚊𝚍𝚎𝚛𝚜()\mathtt{EliminateLeaders}() may kill (i.e., remove) a leader even if it is the unique leader in the population. This is due to the inconsistency of variables that might occur in some configurations. (Recall that we must consider an arbitrary initial configuration to design a self-stabilizing protocol.) However, as we will see in Section 4, 𝙲𝚛𝚎𝚊𝚝𝚎𝙻𝚎𝚊𝚍𝚎𝚛()\mathtt{CreateLeader}() and 𝙴𝚕𝚒𝚖𝚒𝚗𝚊𝚝𝚎𝙻𝚎𝚊𝚍𝚎𝚛𝚜()\mathtt{EliminateLeaders}() will remove this inconsistency within O(n2)O(n^{2}) steps w.h.p. Thereafter, 𝙴𝚕𝚒𝚖𝚒𝚗𝚊𝚝𝚎𝙻𝚎𝚊𝚍𝚎𝚛𝚜()\mathtt{EliminateLeaders}() will never kill the last leader in the population, i.e., will remove a leader only when there are two or more leaders. If there is no leader, 𝙳𝚎𝚝𝚎𝚛𝚖𝚒𝚗𝚎𝙼𝚘𝚍𝚎()\mathtt{DetermineMode}() lets all agents enter the detection mode, after which 𝙲𝚛𝚎𝚊𝚝𝚎𝙻𝚎𝚊𝚍𝚎𝚛()\mathtt{CreateLeader}() lets the agents detect the imperfection of the current configuration and create a new leader (not necessarily a single leader), which requires O(n2logn)O(n^{2}\log n) steps w.h.p. Once a leader appears in the population, 𝙳𝚎𝚝𝚎𝚛𝚖𝚒𝚗𝚎𝙼𝚘𝚍𝚎()\mathtt{DetermineMode}() lets all agents enter the construction mode within O(n2)O(n^{2}) steps and keep the construction mode for a sufficiently large Θ(n2logn)\Theta(n^{2}\log n) steps w.h.p. As mentioned above, 𝙴𝚕𝚒𝚖𝚒𝚗𝚊𝚝𝚎𝙻𝚎𝚊𝚍𝚎𝚛𝚜()\mathtt{EliminateLeaders}() decreases the number of leaders to one within O(n2logn)O(n^{2}\log n) steps w.h.p. Thus, during the period where all agents are in the construction mode, 𝙴𝚕𝚒𝚖𝚒𝚗𝚊𝚝𝚎𝙻𝚎𝚊𝚍𝚎𝚛𝚜()\mathtt{EliminateLeaders}() elects a unique leader, and 𝙲𝚛𝚎𝚊𝚝𝚎𝙻𝚎𝚊𝚍𝚎𝚛()\mathtt{CreateLeader}() updates 𝚍𝚒𝚜𝚝\mathtt{dist} and 𝚋\mathtt{b} so that the population reaches a configuration CC such that (i) CC is perfect, and (ii) no agent changes 𝚍𝚒𝚜𝚝\mathtt{dist} or 𝚋\mathtt{b} from CC unless a new leader is created. Thereafter, no agent creates a new leader even if some agent goes back to the detection mode. Thus, the population keeps the unique leader forever.

The rest of this section is organized as follows. In Section 3.2, we explain how 𝙲𝚛𝚎𝚊𝚝𝚎𝙻𝚎𝚊𝚍𝚎𝚛()\mathtt{CreateLeader}() constructs a perfect configuration when the agents are in the construction mode and how it detects the imperfection of the current configuration when the agents are in the detection mode and there is no leader. In Section 3.3, we explain how 𝙳𝚎𝚝𝚎𝚛𝚖𝚒𝚗𝚎𝙼𝚘𝚍𝚎()\mathtt{DetermineMode}() determines the mode of the agents and how it shows the desirable behavior mentioned above. In Section 3.4, we explain how 𝙴𝚕𝚒𝚖𝚒𝚗𝚊𝚝𝚎𝙻𝚎𝚊𝚍𝚎𝚛𝚜()\mathtt{EliminateLeaders}() given by (Yokota et al., 2021) eliminates the number of leaders to one for the completeness of this paper.

Macros:
   𝐼𝑛𝑣𝑎𝑙𝑖𝑑𝑇𝑜𝑘𝑒𝑛(v,d)={1v.𝚝𝚘𝚔𝚎𝚗[1]>0(v.𝚍𝚒𝚜𝚝+v.𝚝𝚘𝚔𝚎𝚗[1]+d)mod2ψ[ψ,2ψ1]1v.𝚝𝚘𝚔𝚎𝚗[1]<0(v.𝚍𝚒𝚜𝚝+v.𝚝𝚘𝚔𝚎𝚗[1]+d)mod2ψ[1,ψ1]0otherwise\mathit{InvalidToken}(v,d)=\begin{cases}1&v.\mathtt{token}[1]>0\land(v.\mathtt{dist}+v.\mathtt{token}[1]+d)\bmod 2\psi\in[\psi,2\psi-1]\\ 1&v.\mathtt{token}[1]<0\land(v.\mathtt{dist}+v.\mathtt{token}[1]+d)\bmod 2\psi\in[1,\psi-1]\\ 0&\text{otherwise}\end{cases}
12 if l.𝚍𝚒𝚜𝚝=dl.𝚕𝚊𝚜𝚝=0l.𝚝𝚘𝚔𝚎𝚗=l.\mathtt{dist}=d\land l.\mathtt{last}=0\land l.\mathtt{token}=\bot then
13       l.𝚝𝚘𝚔𝚎𝚗(ψ,1l.𝚋,l.𝚋)l.\mathtt{token}\leftarrow(\psi,1-l.\mathtt{b},l.\mathtt{b})
14if l.𝚝𝚘𝚔𝚎𝚗(r.𝚝𝚘𝚔𝚎𝚗r.𝚕𝚊𝚜𝚝=1)l.\mathtt{token}\neq\bot\land(r.\mathtt{token}\neq\bot\lor r.\mathtt{last}=1) then
15       l.𝚝𝚘𝚔𝚎𝚗l.\mathtt{token}\leftarrow\bot
16
17if l.𝚝𝚘𝚔𝚎𝚗l.𝚝𝚘𝚔𝚎𝚗[1]=1l.\mathtt{token}\neq\bot\land l.\mathtt{token}[1]=1 then // the token reaches the target
18       if r.𝚖𝚘𝚍𝚎=𝐷𝑒𝑡𝑒𝑐𝑡l.𝚝𝚘𝚔𝚎𝚗[2]r.𝚋r.\mathtt{mode}=\mathit{Detect}\land l.\mathtt{token}[2]\neq r.\mathtt{b} then
             (r.𝚕𝚎𝚊𝚍𝚎𝚛,r.𝚋𝚞𝚕𝚕𝚎𝚝,r.𝚜𝚑𝚒𝚎𝚕𝚍,r.𝚜𝚒𝚐𝚗𝚊𝚕B)(1,2,1,0)(r.\mathtt{leader},r.\mathtt{bullet},r.\mathtt{shield},r.\mathtt{signal}_{B})\leftarrow(1,2,1,0)
              // Create a leader.
19            
20      else if r.𝚖𝚘𝚍𝚎=𝐶𝑜𝑛𝑠𝑡𝑟𝑢𝑐𝑡r.\mathtt{mode}=\mathit{Construct} then
21             r.𝚋l.𝚝𝚘𝚔𝚎𝚗[2]r.\mathtt{b}\leftarrow l.\mathtt{token}[2]
22      r.𝚝𝚘𝚔𝚎𝚗(1ψ,l.𝚝𝚘𝚔𝚎𝚗[2],l.𝚝𝚘𝚔𝚎𝚗[3])r.\mathtt{token}\leftarrow(1-\psi,l.\mathtt{token}[2],l.\mathtt{token}[3])
23       l.𝚝𝚘𝚔𝚎𝚗l.\mathtt{token}\leftarrow\bot
24      
25 else if l.𝚝𝚘𝚔𝚎𝚗l.𝚝𝚘𝚔𝚎𝚗[1]2l.\mathtt{token}\neq\bot\land l.\mathtt{token}[1]\geq 2 then
26       r.𝚝𝚘𝚔𝚎𝚗(l.𝚝𝚘𝚔𝚎𝚗[1]1,l.𝚝𝚘𝚔𝚎𝚗[2],l.𝚝𝚘𝚔𝚎𝚗[3])r.\mathtt{token}\leftarrow(l.\mathtt{token}[1]-1,l.\mathtt{token}[2],l.\mathtt{token}[3])
27       l.𝚝𝚘𝚔𝚎𝚗l.\mathtt{token}\leftarrow\bot
28      
29
30else if r.𝚝𝚘𝚔𝚎𝚗r.𝚝𝚘𝚔𝚎𝚗[1]=1r.\mathtt{token}\neq\bot\land r.\mathtt{token}[1]=-1 then // the token reaches the target
31       l.𝚝𝚘𝚔𝚎𝚗{(ψ,1l.𝚋,l.𝚋)r.𝚝𝚘𝚔𝚎𝚗[3]=1(ψ,l.𝚋,0)r.𝚝𝚘𝚔𝚎𝚗[3]=0l.\mathtt{token}\leftarrow\begin{cases}(\psi,1-l.\mathtt{b},l.\mathtt{b})&r.\mathtt{token}[3]=1\\ (\psi,l.\mathtt{b},0)&r.\mathtt{token}[3]=0\end{cases}
32       r.𝚝𝚘𝚔𝚎𝚗r.\mathtt{token}\leftarrow\bot
33 else if r.𝚝𝚘𝚔𝚎𝚗r.𝚝𝚘𝚔𝚎𝚗[1]2r.\mathtt{token}\neq\bot\land r.\mathtt{token}[1]\leq-2 then
34       l.𝚝𝚘𝚔𝚎𝚗(r.𝚝𝚘𝚔𝚎𝚗[1]+1,l.𝚝𝚘𝚔𝚎𝚗[2],l.𝚝𝚘𝚔𝚎𝚗[3])l.\mathtt{token}\leftarrow(r.\mathtt{token}[1]+1,l.\mathtt{token}[2],l.\mathtt{token}[3])
35       r.𝚝𝚘𝚔𝚎𝚗r.\mathtt{token}\leftarrow\bot
36      
37
38if v{l,r}:v.𝚝𝚘𝚔𝚎𝚗(v.𝚕𝚊𝚜𝚝=1𝐼𝑛𝑣𝑎𝑙𝑖𝑑𝑇𝑜𝑘𝑒𝑛(v,d)=1)\exists v\in\{l,r\}:v.\mathtt{token}\neq\bot\land(v.\mathtt{last}=1\lor\mathit{InvalidToken}(v,d)=1) then
39       v.𝚝𝚘𝚔𝚎𝚗v.\mathtt{token}\leftarrow\bot
Algorithm 3 𝙼𝚘𝚟𝚎𝚃𝚘𝚔𝚎𝚗(𝚝𝚘𝚔𝚎𝚗,d)\mathtt{MoveToken}(\mathtt{token},d)   ll is the initiator and rr is the responder of an interaction.

3.2. Construction and Detection

In this section, we explain how 𝙲𝚛𝚎𝚊𝚝𝚎𝙻𝚎𝚊𝚍𝚎𝚛()\mathtt{CreateLeader}() guarantees that

  • when all agents are in the construction mode and there is exactly one leader, the population reaches a perfect configuration within O(n2logn)O(n^{2}\log n) steps w.h.p., and

  • when all agents are in the detection mode and there is no leader, the imperfection of the current configuration is detected and a new leader is created within O(n2logn)O(n^{2}\log n) steps w.h.p.

Thus, we do not consider the case where there are two or more leaders in the population throughout this section.

The pseudocode of 𝙲𝚛𝚎𝚊𝚝𝚎𝙻𝚎𝚊𝚍𝚎𝚛()\mathtt{CreateLeader}(), shown in Algorithm 2, consists of three parts: the first part manages variable 𝚖𝚘𝚍𝚎\mathtt{mode} by invoking 𝙳𝚎𝚝𝚎𝚛𝚖𝚒𝚗𝚎𝙼𝚘𝚍𝚎()\mathtt{DetermineMode}() (Line 3), the second part manages variables 𝚍𝚒𝚜𝚝\mathtt{dist} and 𝚕𝚊𝚜𝚝\mathtt{last} (Lines 4–9), and the third part manages variable 𝚋\mathtt{b} by invoking a function 𝙼𝚘𝚟𝚎𝚃𝚘𝚔𝚎𝚗()\mathtt{MoveToken}() (Lines 10–11). The first part is left to Section 3.3. The second and third parts guarantee the above specification by updating and checking variables 𝚍𝚒𝚜𝚝\mathtt{dist}, 𝚕𝚊𝚜𝚝\mathtt{last}, and 𝚋\mathtt{b}.

The second part is simple. When uju_{j} and uj+1u_{j+1} have an interaction, the right agent uj+1u_{j+1} tries to compute its distance to the nearest left leader modulo 2ψ2\psi on a temporary variable 𝚝𝚖𝚙\mathtt{tmp} by executing 𝚝𝚖𝚙0\mathtt{tmp}\leftarrow 0 if rr is a leader; otherwise 𝚝𝚖𝚙l.𝚍𝚒𝚜𝚝+1mod2ψ\mathtt{tmp}\leftarrow l.\mathtt{dist}+1\bmod 2\psi. If uj+1u_{j+1} is in the construction mode, it just substitutes the computed value for uj+1.𝚍𝚒𝚜𝚝u_{j+1}.\mathtt{dist}. If uj+1u_{j+1} is in the detection mode and 𝚝𝚖𝚙uj+1.𝚍𝚒𝚜𝚝\mathtt{tmp}\neq u_{j+1}.\mathtt{dist}, this difference yields that the current configuration is not perfect. Then, uj+1u_{j+1} creates a new leader. (Ignore variables 𝚋𝚞𝚕𝚕𝚎𝚝\mathtt{bullet}, 𝚜𝚑𝚒𝚎𝚕𝚍\mathtt{shield}, and 𝚜𝚒𝚐𝚗𝚊𝚕B\mathtt{signal}_{B} at Line 6 for now. We will explain these variables in Section 3.4.) The variable v.𝚕𝚊𝚜𝚝{0,1}v.\mathtt{last}\in\{0,1\} indicates whether agent vv belongs to the last segment, i.e., the segment ui,ui+1,,ui+1u_{i},u_{i+1},\dots,u_{i+\ell-1} such that ui+u_{i+\ell} is a leader. At each interaction, the left agent updates 𝚕𝚊𝚜𝚝\mathtt{last} at Line 9 irrespective of its mode.

Consider that interaction sequence 𝑠𝑒𝑞R(i,n)𝑠𝑒𝑞L(i,n)\mathit{seq}_{R}(i,n)\cdot\mathit{seq}_{L}(i,n) occurs, during which uiu_{i} is always a unique leader and all agents are in the construction mode. Then, the population reaches a configuration where no agent violates the first condition of perfection, i.e., (1), and the agents in the last segment have 𝚕𝚊𝚜𝚝=1\mathtt{last}=1 and the other agents have 𝚕𝚊𝚜𝚝=0\mathtt{last}=0. Consider that 𝑠𝑒𝑞R(i,n)𝑠𝑒𝑞L(i,n)\mathit{seq}_{R}(i,n)\cdot\mathit{seq}_{L}(i,n) occurs for some i[0,n1]i\in[0,n-1], during which there is no leader and all agents are in the detection mode. If the population has some inconsistency in variable 𝚍𝚒𝚜𝚝\mathtt{dist}, i.e., uj+1.𝚍𝚒𝚜𝚝uj.𝚍𝚒𝚜𝚝+1modψu_{j+1}.\mathtt{dist}\neq u_{j}.\mathtt{dist}+1\bmod\psi for some jj, at least one agent detects the inconsistency and creates a leader in this period. Otherwise, the population reaches a configuration where v.𝚕𝚊𝚜𝚝=0v.\mathtt{last}=0 holds for all agents vv in this period. In both cases, 𝑠𝑒𝑞R(i,n)𝑠𝑒𝑞L(i,n)\mathit{seq}_{R}(i,n)\cdot\mathit{seq}_{L}(i,n) occurs within O(n2)O(n^{2}) steps w.h.p. by Lemma 2.3.

Thus, in the rest of Section 3.2, we explain how the third part works assuming that there is no agent violating the first condition of perfection and v.𝚕𝚊𝚜𝚝=1v.\mathtt{last}=1 holds if and only if vv belongs to the last segment. Again, we consider only two cases in this section (Section 3.2): (i) there is exactly one leader, and (ii) there is no leader. Without loss of generality, we assume that u0u_{0} is the unique leader in the first case, while we assume u0.𝚍𝚒𝚜𝚝=0u_{0}.\mathtt{dist}=0 in the second case. Then, we have ζ=defn/ψ\zeta\overset{\text{def}}{=}\lceil n/\psi\rceil segments S0,S1,,Sζ1S_{0},S_{1},\dots,S_{\zeta-1} in the population where Si=uiψ,uiψ+1,,uiψ+ψ1S_{i}=u_{i\psi},u_{i\psi+1},\dots,u_{i\psi+\psi-1} for i[0,ζ2]i\in[0,\zeta-2] and Sζ1=u(ζ1)ψ,u(ζ1)ψ+1,,un1S_{\zeta-1}=u_{(\zeta-1)\psi},u_{(\zeta-1)\psi+1},\dots,u_{n-1}. We say that a segment SiS_{i} is black if ii is even; Otherwise SiS_{i} is white. We call the border agent in a black (resp. white) segment a black border (resp. white border).

Refer to caption
Figure 2. The trajectory of black and white tokens. (ψ=4\psi=4.)

The goal of the third part is as follows: for each i[0,ζ3]i\in[0,\zeta-3], it embeds (ι(Si)+1)mod2ψ(\iota(S_{i})+1)\bmod 2^{\psi} on variable 𝚋\mathtt{b} on the agents in Si+1S_{i+1} to satisfy ι(Si+1)=(ι(Si)+1)mod2ψ\iota(S_{i+1})=(\iota(S_{i})+1)\bmod 2^{\psi} in the construction mode, while it creates a new leader when it finds ι(Si+1)(ι(Si)+1)mod2ψ\iota(S_{i+1})\neq(\iota(S_{i})+1)\bmod 2^{\psi} in the detection mode. To achieve this goal, we use two kinds of tokens, black tokens and white tokens. For each i[0,ζ2]i\in[0,\zeta-2], the border agent uiψu_{i\psi} in SiS_{i} creates a black (resp. white) token if it is black (resp. white), and the generated token moves back and forth in the trajectory shown in Figure 2, conveying two bits bb^{\prime} and b′′b^{\prime\prime}. These two bits are used to compute (ι(Si)+1)mod2ψ(\iota(S_{i})+1)\bmod 2^{\psi}: bb^{\prime} maintains the binary value that will be set to the target index and b′′b^{\prime\prime} maintains the carry flag. Specifically, the agents in two segments SiS_{i} and Si+1S_{i+1} move the token in the following steps:

  1. (1)

    When uiψu_{i\psi} creates a token, it initializes bb^{\prime} and b′′b^{\prime\prime} as

    (b,b′′){(0,1)uiψ.𝚋=1(1,0)uiψ.𝚋=0,(b^{\prime},b^{\prime\prime})\leftarrow\begin{cases}(0,1)&u_{i\psi}.\mathtt{b}=1\\ (1,0)&u_{i\psi}.\mathtt{b}=0,\end{cases}

    and set the target index T=ψT=\psi.

  2. (2)

    The token moves right toward ur=uiψ+Tu_{r}=u_{i\psi+T}. It disappears if it enters the last segment.

  3. (3)

    The token arrives at uru_{r} eventually. If uru_{r} is in the construction mode at that time, it copies bb^{\prime} to ur.𝚋u_{r}.\mathtt{b}. Otherwise, it does not update ur.𝚋u_{r}.\mathtt{b}. Instead, it checks whether b=ur.𝚋b^{\prime}=u_{r}.\mathtt{b} holds. If it does not hold, uru_{r} becomes a leader.

  4. (4)

    The token disappears if T=2ψ1T=2\psi-1, i.e., it has already reached the final destination uiψ+2ψ1u_{i\psi+2\psi-1}. Otherwise, it begins to move left toward ul=uiψ+Tψ+1u_{l}=u_{i\psi+T-\psi+1}.

  5. (5)

    The token moves left toward ulu_{l}.

  6. (6)

    The token arrives at ulu_{l} eventually. It updates bb^{\prime} and b′′b^{\prime\prime} as

    (b,b′′){(1ul.𝚋,ul.𝚋)b′′=1(ul.𝚋,0)b′′=0,(b^{\prime},b^{\prime\prime})\leftarrow\begin{cases}(1-u_{l}.\mathtt{b},u_{l}.\mathtt{b})&b^{\prime\prime}=1\\ (u_{l}.\mathtt{b},0)&b^{\prime\prime}=0,\end{cases}

    and increments the target index TT by one and goes back to Step 2.

This behavior of the token obviously achieves the above goal. We realize this behavior with two variables 𝚝𝚘𝚔𝚎𝚗B,𝚝𝚘𝚔𝚎𝚗W{}(([ψ+1,1][1,ψ])×{0,1}×{0,1})\mathtt{token}_{B},\mathtt{token}_{W}\in\{\bot\}\cup(([-\psi+1,-1]\cup[1,\psi])\times\{0,1\}\times\{0,1\}), which represent black and white tokens, respectively. For any agent uiu_{i}, ui.𝚝𝚘𝚔𝚎𝚗B=u_{i}.\mathtt{token}_{B}=\bot (resp. ui.𝚝𝚘𝚔𝚎𝚗W=u_{i}.\mathtt{token}_{W}=\bot) means that uiu_{i} is not carrying a black (resp. white) token currently. In the following, we only explain how the agents realize the behavior of a black token with variable 𝚝𝚘𝚔𝚎𝚗B\mathtt{token}_{B}. The behavior of a white token is realized in completely the same way. If ui.𝚝𝚘𝚔𝚎𝚗Bu_{i}.\mathtt{token}_{B}\neq\bot, the black token consists of three elements. The first element ui.𝚝𝚘𝚔𝚎𝚗B[1][ψ+1,1][1,ψ]u_{i}.\mathtt{token}_{B}[1]\in[-\psi+1,-1]\cup[1,\psi] represents the relative position of the target. When ui.𝚝𝚘𝚔𝚎𝚗B[1]1u_{i}.\mathtt{token}_{B}[1]\geq 1, the black token at uiu_{i} is moving right toward ui+ui.𝚝𝚘𝚔𝚎𝚗B[1]u_{i+u_{i}.\mathtt{token}_{B}[1]}. When ui.𝚝𝚘𝚔𝚎𝚗B[1]1u_{i}.\mathtt{token}_{B}[1]\leq-1, the token is moving left toward ui+ui.𝚝𝚘𝚔𝚎𝚗B[1]u_{i+u_{i}.\mathtt{token}_{B}[1]}. The second element ui.𝚝𝚘𝚔𝚎𝚗B[2]{0,1}u_{i}.\mathtt{token}_{B}[2]\in\{0,1\} and the third element ui.𝚝𝚘𝚔𝚎𝚗B[3]{0,1}u_{i}.\mathtt{token}_{B}[3]\in\{0,1\} respectively correspond to the two bits bb^{\prime} and b′′b^{\prime\prime} that were used to describe the behavior specified by Steps 1–6. Each step 1,2,,61,2,\dots,6 is realized by the following lines at Algorithm 3:

  • Step 1: Lines 12–13,

  • Step 2: Lines 14–15 and 23–25,

  • Step 3: Lines 16–20,

  • Step 4: Lines 21–22 and 32–33,

  • Step 5: Lines 29–31,

  • Step 6: Lines 26–28.

Note that in the pseudocode, we have d=0d=0 when we deal with a black token, while we have d=ψd=\psi when we deal with a white token. (See Lines 10 and 11 in Algorithm 2.) The above implementation of the behavior of the tokens is straightforward and requires no explanation except for Lines 14–15 and 32–33. Lines 14–15 specify what happens if two black tokens meet. At that time, the left token disappears. This destruction does not cause live-lock because the rightmost black token in the segments SiS_{i} and Si+1S_{i+1} is never killed by any token until it reaches the final destination uiψ+2ψ1u_{i\psi+2\psi-1}. Lines 32–33 have three roles: the first one is deleting a token that has reached the final destination. The second one is deleting the invalid tokens. Roughly speaking, we say that a token is invalid if it is out of its trajectory. Formally, we define invalid tokens as follows.

Definition 3.3.

A token located at agent uju_{j} is invalid if

uj.𝚝𝚘𝚔𝚎𝚗[1]>0(uj.𝚍𝚒𝚜𝚝+uj.𝚝𝚘𝚔𝚎𝚗[1]+d)mod2ψ[ψ,2ψ1],\displaystyle u_{j}.\mathtt{token}[1]>0\land(u_{j}.\mathtt{dist}+u_{j}.\mathtt{token}[1]+d)\bmod 2\psi\in[\psi,2\psi-1],
or uj.𝚝𝚘𝚔𝚎𝚗[1]<0(uj.𝚍𝚒𝚜𝚝+uj.𝚝𝚘𝚔𝚎𝚗[1]+d)mod2ψ[1,ψ1],\displaystyle\text{or }u_{j}.\mathtt{token}[1]<0\land(u_{j}.\mathtt{dist}+u_{j}.\mathtt{token}[1]+d)\bmod 2\psi\in[1,\psi-1],

where d=0d=0 if the token is black, and d=ψd=\psi otherwise. A token is valid if it is not invalid.

A valid token never gets invalid before it reaches its final destination, at which point it disappears. (See Figure 2.) Invalid tokens may exist in an initial configuration, which the adversary can arbitrarily choose. However, Lines 32–33 delete all invalid tokens during the period 𝑠𝑒𝑞R(0,n)\mathit{seq}_{R}(0,n) occurs, which requires only O(n2)O(n^{2}) steps w.h.p. by Lemma 2.3. The third one is deleting a token located at the last segment.

The length of the trajectory of a token is exactly (ψ+ψ1)(ψ1)+ψ=2ψ22ψ+1(\psi+\psi-1)\cdot(\psi-1)+\psi=2\psi^{2}-2\psi+1. Thus, under the assumption that variable 𝚍𝚒𝚜𝚝\mathtt{dist} is correctly computed, every token moves at most 2ψ22ψ+12\psi^{2}-2\psi+1 times.

Definition 3.4.

We say that a token completes its trajectory when it moves 2ψ22ψ+12\psi^{2}-2\psi+1 times.

Lemma 3.5.

Let k[0,n1]k\in[0,n-1] and d{0,ψ}d\in\{0,\psi\}. Let 𝒞d\mathcal{C}_{d} be a set of all configurations where uk+i.𝚍𝚒𝚜𝚝=i+dmod2ψu_{k+i}.\mathtt{dist}=i+d\bmod 2\psi and uk+i.𝚕𝚊𝚜𝚝=0u_{k+i}.\mathtt{last}=0 hold for all i[0,2ψ1]i\in[0,2\psi-1]. Consider execution ΞP𝑃𝐿(C0,𝚪)=C0,C1,\Xi_{P_{\mathit{PL}}}(C_{0},\mathbf{\Gamma})=C_{0},C_{1},\dots. If C0,C1,,C𝒞dC_{0},C_{1},\dots,C_{\ell}\in\mathcal{C}_{d} holds and interaction sequence (𝑠𝑒𝑞R(k,2ψ1)𝑠𝑒𝑞L(k+2ψ1,2ψ1))2ψ(\mathit{seq}_{R}(k,2\psi-1)\cdot\mathit{seq}_{L}(k+2\psi-1,2\psi-1))^{2\psi} occurs in the first \ell steps, there is at least one token zz such that (i) zz does not exist in C0C_{0}, (ii) zz is generated by uku_{k}, and (iii) zz completes its trajectory in C0,C1,,CC_{0},C_{1},\dots,C_{\ell}.

Proof.

We will prove the lemma for the case d=0d=0. The case d=ψd=\psi can be dealt with in the same way. Since d=0d=0, uku_{k} is a black border. Let t()t\ (\leq\ell) be the time step at which the first (𝑠𝑒𝑞R(k,2ψ1)𝑠𝑒𝑞L(k+2ψ1,2ψ1))ψ(\mathit{seq}_{R}(k,2\psi-1)\cdot\mathit{seq}_{L}(k+2\psi-1,2\psi-1))^{\psi} completes. Then, all black tokens that exist at uk,uk+1,,uk+2ψ1u_{k},u_{k+1},\dots,u_{k+2\psi-1} in C0C_{0} disappear in C0,C1,,CtC_{0},C_{1},\dots,C_{t}. If there are one or more black tokens at uk,uk+1,,uk+2ψ2u_{k},u_{k+1},\dots,u_{k+2\psi-2} in CtC_{t}, let zz be the rightmost token among them. The token zz does not exist in C0C_{0}, is generated in the first tt steps, and completes its trajectory in Ct,Ct+1,,CC_{t},C_{t+1},\dots,C_{\ell}. Otherwise, the first token generated by uku_{k} after step tt completes its trajectory in Ct,Ct+1,,CC_{t},C_{t+1},\dots,C_{\ell}. ∎

Consider the case that there exists exactly one leader and all agents are in the construction mode. Then, the third part (i.e., the movement of black and white tokens) correctly constructs the segment IDs so that ι(Si+1)=(ι(Si)+1)mod2ψ\iota(S_{i+1})=(\iota(S_{i})+1)\bmod 2^{\psi} holds for all i[0,ζ2]i\in[0,\zeta-2], i.e., lets the population reach a perfect configuration, while (𝑠𝑒𝑞R(0,2ψ1)𝑠𝑒𝑞L(2ψ1,2ψ1))2ψ(𝑠𝑒𝑞R(ψ,2ψ1)𝑠𝑒𝑞L(3ψ1,2ψ1))2ψ(𝑠𝑒𝑞R((ζ2)ψ,2ψ1)𝑠𝑒𝑞L(ζψ1,2ψ1))2ψ(\mathit{seq}_{R}(0,2\psi-1)\cdot\mathit{seq}_{L}(2\psi-1,2\psi-1))^{2\psi}\cdot(\mathit{seq}_{R}(\psi,2\psi-1)\cdot\mathit{seq}_{L}(3\psi-1,2\psi-1))^{2\psi}\cdot\dots\cdot(\mathit{seq}_{R}((\zeta-2)\psi,2\psi-1)\cdot\mathit{seq}_{L}(\zeta\psi-1,2\psi-1))^{2\psi} occurs, by Lemma 3.5. This interaction sequence has length at most (4ψ2)(2ψ)(ζ1)8nψ(4\psi-2)\cdot(2\psi)\cdot(\zeta-1)\leq 8n\psi, thus occurs within at most O(n2ψ)=O(n2logn)O(n^{2}\psi)=O(n^{2}\log n) steps w.h.p. by Lemma 2.3.

Consider the case that there is no leader and all agents are in the detection mode. Then, under the aforementioned assumption, all segments S0,S1,,Sζ1S_{0},S_{1},\dots,S_{\zeta-1} have length ψ\psi and all agents have 𝚕𝚊𝚜𝚝=0\mathtt{last}=0. Thus, by Lemma 3.2, there exists a segment SiS_{i} such that ι(S(i+1)modζ)(ι(Si)+1)mod2ψ\iota(S_{(i+1)\bmod\zeta})\neq(\iota(S_{i})+1)\bmod 2^{\psi}. Then, the third part detects the inconsistency and creates a new leader while (𝑠𝑒𝑞R(iψ,2ψ1)𝑠𝑒𝑞L((i+2)ψ1,2ψ1))2ψ(\mathit{seq}_{R}(i\psi,2\psi-1)\cdot\mathit{seq}_{L}((i+2)\psi-1,2\psi-1))^{2\psi} occurs. This interaction sequence occurs within at most O(nψ2)=O(nlog2n)O(n\psi^{2})=O(n\log^{2}n) steps w.h.p. by Lemma 2.3.

3.3. Mode Determination

To describe the goal of 𝙳𝚎𝚝𝚎𝚛𝚖𝚒𝚗𝚎𝙼𝚘𝚍𝚎()\mathtt{DetermineMode}() properly, we define three sets of configurations, 1\mathcal{L}_{\geq 1}, 0\mathcal{L}_{0} and 𝒞NZ\mathcal{C}_{\mathrm{NZ}}. We define 1𝒞all(P𝑃𝐿)\mathcal{L}_{\geq 1}\subseteq\mathcal{C}_{\mathrm{all}}(P_{\mathit{PL}}) as the set of configurations with at least one leader. We define 0=𝒞all(P𝑃𝐿)1\mathcal{L}_{0}=\mathcal{C}_{\mathrm{all}}(P_{\mathit{PL}})\setminus\mathcal{L}_{\geq 1}. We define 𝒞NZ1\mathcal{C}_{\mathrm{NZ}}\subset\mathcal{L}_{\geq 1} as the set of all configurations CC such that an execution of P𝑃𝐿P_{\mathit{PL}} starting from CC will never enter 0\mathcal{L}_{0}, i.e., never kill the last leader. We will prove in Section 4 that 𝒞NZ\mathcal{C}_{\mathrm{NZ}}\neq\emptyset holds, and an execution of P𝑃𝐿P_{\mathit{PL}} reaches a configuration in 𝒞NZ\mathcal{C}_{\mathrm{NZ}} within O(n2logn)O(n^{2}\log n) steps w.h.p. starting from any configuration. The goal of this section is to give 𝙳𝚎𝚝𝚎𝚛𝚖𝚒𝚗𝚎𝙼𝚘𝚍𝚎()\mathtt{DetermineMode}() such that the following two lemmas hold for a parameter κmax=c1ψ=Θ(logn)\kappa_{\mathrm{max}}=c_{1}\psi=\Theta(\log n) with a sufficiently large constant c1c_{1}. We assume c132c_{1}\geq 32, i.e., κmax32ψ\kappa_{\mathrm{max}}\geq 32\psi.

Lemma 3.6.

There exists a set 𝒞mid\mathcal{C}_{\mathrm{mid}} of configurations such that (i) an execution of P𝑃𝐿P_{\mathit{PL}} starting from any configuration in 𝒞NZ\mathcal{C}_{\mathrm{NZ}} reaches a configuration in 𝒞mid\mathcal{C}_{\mathrm{mid}} within O(n2)O(n^{2}) steps w.h.p., and (ii) all agents are in the construction mode in the first Ω(κmaxn2)\Omega(\kappa_{\mathrm{max}}\cdot n^{2}) steps w.h.p. in an execution of P𝑃𝐿P_{\mathit{PL}} starting from any configuration in 𝒞mid\mathcal{C}_{\mathrm{mid}}.

Lemma 3.7.

Let 𝒞det\mathcal{C}_{\mathrm{det}} be the set of all configurations C0C\in\mathcal{L}_{0} such that, in an execution of P𝑃𝐿P_{\mathit{PL}} starting from CC, all agents are always in the detection mode before a leader is created. Let C0𝒞all(P𝑃𝐿)C_{0}\in\mathcal{C}_{\mathrm{all}}(P_{\mathit{PL}}). Execution ΞP𝑃𝐿(C0,𝚪)\Xi_{P_{\mathit{PL}}}(C_{0},\mathbf{\Gamma}) reaches a configuration in 𝒞det1\mathcal{C}_{\mathrm{det}}\cup\mathcal{L}_{\geq 1} within O(n2logn)O(n^{2}\log n) steps w.h.p.

34
35if l.𝚕𝚎𝚊𝚍𝚎𝚛=1l.\mathtt{leader}=1 then
36       l.𝚜𝚒𝚐𝚗𝚊𝚕Rκmaxl.\mathtt{signal}_{R}\leftarrow\kappa_{\mathrm{max}}
37      
38l.𝚑𝚒𝚝𝚜0l.\mathtt{hits}\leftarrow 0
39 r.𝚑𝚒𝚝𝚜min(r.𝚑𝚒𝚝𝚜+1,ψ)r.\mathtt{hits}\leftarrow\min(r.\mathtt{hits}+1,\psi)
40 if l.𝚜𝚒𝚐𝚗𝚊𝚕R>0r.𝚜𝚒𝚐𝚗𝚊𝚕R>0l.\mathtt{signal}_{R}>0\lor r.\mathtt{signal}_{R}>0 then
41       (l.𝚌𝚕𝚘𝚌𝚔,r.𝚌𝚕𝚘𝚌𝚔)(0,0)(l.\mathtt{clock},r.\mathtt{clock})\leftarrow(0,0)
42       if l.𝚜𝚒𝚐𝚗𝚊𝚕Rr.𝚜𝚒𝚐𝚗𝚊𝚕R>0l.\mathtt{signal}_{R}\geq r.\mathtt{signal}_{R}>0 then // the left signal absorbs the right signal
43             r.𝚑𝚒𝚝𝚜0r.\mathtt{hits}\leftarrow 0
44      (l.𝚜𝚒𝚐𝚗𝚊𝚕R,r.𝚜𝚒𝚐𝚗𝚊𝚕R)(0,max(l.𝚜𝚒𝚐𝚗𝚊𝚕R,r.𝚜𝚒𝚐𝚗𝚊𝚕R))(l.\mathtt{signal}_{R},r.\mathtt{signal}_{R})\leftarrow(0,\max(l.\mathtt{signal}_{R},r.\mathtt{signal}_{R}))
45       if r.𝚑𝚒𝚝𝚜=ψr.\mathtt{hits}=\psi then
46             r.𝚜𝚒𝚐𝚗𝚊𝚕Rr.𝚜𝚒𝚐𝚗𝚊𝚕R1r.\mathtt{signal}_{R}\leftarrow r.\mathtt{signal}_{R}-1
47             r.𝚑𝚒𝚝𝚜0r.\mathtt{hits}\leftarrow 0
48            
49      
50 else if r.𝚑𝚒𝚝𝚜=ψr.\mathtt{hits}=\psi then
51       r.𝚌𝚕𝚘𝚌𝚔min(r.𝚌𝚕𝚘𝚌𝚔+1,κmax)r.\mathtt{clock}\leftarrow\min(r.\mathtt{clock}+1,\kappa_{\mathrm{max}})
52       r.𝚑𝚒𝚝𝚜0r.\mathtt{hits}\leftarrow 0
53      
54foreach v{l,r}v\in\{l,r\} do
55       v.𝚖𝚘𝚍𝚎{𝐷𝑒𝑡𝑒𝑐𝑡v.𝚌𝚕𝚘𝚌𝚔=κmax𝐶𝑜𝑛𝑠𝑡𝑟𝑢𝑐𝑡v.𝚌𝚕𝚘𝚌𝚔<κmaxv.\mathtt{mode}\leftarrow\begin{cases}\mathit{Detect}&v.\mathtt{clock}=\kappa_{\mathrm{max}}\\ \mathit{Construct}&v.\mathtt{clock}<\kappa_{\mathrm{max}}\end{cases}
Algorithm 4 𝙳𝚎𝚝𝚎𝚛𝚖𝚒𝚗𝚎𝙼𝚘𝚍𝚎()\mathtt{DetermineMode}()   ll is the initiator and rr is the responder of an interaction.

We present 𝙳𝚎𝚝𝚎𝚛𝚖𝚒𝚗𝚎𝙼𝚘𝚍𝚎()\mathtt{DetermineMode}() in the first half of this section, and prove Lemmas 3.6 and 3.7 in the second half.

We design 𝙳𝚎𝚝𝚎𝚛𝚖𝚒𝚗𝚎𝙼𝚘𝚍𝚎()\mathtt{DetermineMode}() with a variable 𝚌𝚕𝚘𝚌𝚔[0,κmax]\mathtt{clock}\in[0,\kappa_{\mathrm{max}}]. We use this variable as a barometer of the absence of a leader: high value of ui.𝚌𝚕𝚘𝚌𝚔u_{i}.\mathtt{clock} indicates a high chance that there is no leader. The mode (detection or construction) of an agent uiu_{i} is uniquely determined by this variable: ui.𝚖𝚘𝚍𝚎=𝐷𝑒𝑡𝑒𝑐𝑡u_{i}.\mathtt{mode}=\mathit{Detect} if and only if ui.𝚌𝚕𝚘𝚌𝚔=κmaxu_{i}.\mathtt{clock}=\kappa_{\mathrm{max}} (Lines 49–50). The basic idea is as follows. A leader always generates a resetting signal, which indicates that there is a leader in the population. This signal moves in the ring in the clockwise direction, i.e., from left to right, resetting the clocks of the agents it visits. To implement the resetting signal, each agent maintains a variable 𝚜𝚒𝚐𝚗𝚊𝚕R[0,κmax]\mathtt{signal}_{R}\in[0,\kappa_{\mathrm{max}}]. The value of ui.𝚜𝚒𝚐𝚗𝚊𝚕Ru_{i}.\mathtt{signal}_{R} represents the TTL (Time To Live) of the signal that uiu_{i} carries, and ui.𝚜𝚒𝚐𝚗𝚊𝚕R=0u_{i}.\mathtt{signal}_{R}=0 means that uiu_{i} does not carry a resetting signal. A leader generates a new signal when it interacts with its left neighbor (Lines 34–35). Each time an agent with a signal interacts with its right neighbor, the signal moves from left to right (Line 42). If the right neighbor also carries a signal, the two signals are merged at the right neighbor and the merged signal will get the higher TTL. Each agent resets the clock to zero when it observes the signal (Line 39). Thus, the existence of a leader prevents the clock of each agent from reaching κmax\kappa_{\mathrm{max}}, while all agents increase their clocks to κmax\kappa_{\mathrm{max}} and thus will enter the detection mode in O(n2logn)O(n^{2}\log n) steps w.h.p. when there is no leader: as we will see later, each uiu_{i} requires Θ(n2logn)\Theta(n^{2}\log n) steps with probability 1O(1/n2)1-O(1/n^{2}) to increase its clock by κmax/2\kappa_{\mathrm{max}}/2.

We have to decrease the TTL of resetting signals in some way because we must remove all signals from the population when no leader exists. On the other hand, we require that a newly generated signal traverses the whole ring (i.e., moves right nn times) w.h.p. before it disappears, which is necessary to reset the clocks of all agents. To achieve this with polylog(n)\mathrm{polylog}(n) states, we implement signals using the lottery game (Alistarh et al., 2017). Each agent maintains a variable 𝚑𝚒𝚝𝚜[0,ψ]\mathtt{hits}\in[0,\psi]. Agent uiu_{i} increases ui.𝚑𝚒𝚝𝚜u_{i}.\mathtt{hits} by one when it interacts with its left neighbor (Line 37), while it resets ui.𝚑𝚒𝚝𝚜u_{i}.\mathtt{hits} when it interacts with its right neighbor (Line 36). The uniform randomness of the scheduler assures that uiu_{i} interacts with its right neighbor with probability 1/21/2 each time uiu_{i} has an interaction. If a signal at agent uiu_{i} observes ui.𝚑𝚒𝚝𝚜=ψu_{i}.\mathtt{hits}=\psi, it decreases its TTL by one and ui.𝚑𝚒𝚝𝚜u_{i}.\mathtt{hits} is reset to zero (Lines 43–45). Consider that uiu_{i} and ui+1u_{i+1} have an interaction when both have resetting signals, thus those signals are merged. Then, we say that uiu_{i}’s signal absorbs ui+1u_{i+1}’s signal if ui.𝚜𝚒𝚐𝚗𝚊𝚕Rui+1.𝚜𝚒𝚐𝚗𝚊𝚕Ru_{i}.\mathtt{signal}_{R}\geq u_{i+1}.\mathtt{signal}_{R}; otherwise we say that ui+1u_{i+1}’s signal absorbs uiu_{i}’s signal. To simplify the analysis, we reset ui+1.𝚑𝚒𝚝𝚜u_{i+1}.\mathtt{hits} to zero in the former case, i.e., when uiu_{i}’s signal moves right absorbing ui+1u_{i+1}’s signal (Lines 40–42). Note that a signal at uiu_{i} moves right if and only if uiu_{i} interacts with its right neighbor. Thus, a signal decreases its TTL if and only if it observes ψ\psi interactions without moving right. Thus, every signal requires Θ(κmax2ψ)=Θ(nlogn)\Theta(\kappa_{\mathrm{max}}\cdot 2^{\psi})=\Theta(n\log n) interactions (i.e., Θ(n2logn)\Theta(n^{2}\log n) steps) with probability 1O(1/n2)1-O(1/n^{2}) before it is absorbed or it disappears (i.e., decreases its TTL to zero).333 This requires careful analysis. We will prove this fact as Lemma 3.11 later. Since a signal moves right nn times in O(n2)O(n^{2}) steps w.h.p. by Lemma 2.3, the signal can visit all agents w.h.p. On the other hand, when no leader exists, the population will reach a configuration with no signals in O(n2logn)O(n^{2}\log n) steps w.h.p. because no signal is newly generated.

We use completely the same mechanism to increase a variable 𝚌𝚕𝚘𝚌𝚔\mathtt{clock}. Each time uiu_{i} observes ui.𝚑𝚒𝚝𝚜=ψu_{i}.\mathtt{hits}=\psi, it increases ui.𝚌𝚕𝚘𝚌𝚔u_{i}.\mathtt{clock} by one (Lines 38–41). Thus, when no signal exists in the population, each uiu_{i} requires Θ(n2logn)\Theta(n^{2}\log n) steps with probability 1O(1/n2)1-O(1/n^{2}) to increase its clock by κmax/2\kappa_{\mathrm{max}}/2. Therefore, when no leader exists, a new leader is created or all agents enter the detection mode within O(n2logn)O(n^{2}\log n) steps w.h.p. On the other hand, when there is at least one leader, the population reaches a configuration where the clocks of all agents are not more than κmax/2\kappa_{\mathrm{max}}/2 within Θ(n2)\Theta(n^{2}) steps w.h.p., and all agents remain in the construction mode (i.e., no agent increases its clock to κmax\kappa_{\mathrm{max}}) in the next Θ(κmax2ψ)\Theta(\kappa_{\mathrm{max}}\cdot 2^{\psi}) steps w.h.p.

To prove Lemmas 3.6 and 3.7, we define the lottery game formally.

Definition 3.8.

Let kk and \ell be positive integers. Consider that a player makes independent coin flips repeatedly. The result of each flip is head with probability 1/21/2 and tail with probability 1/21/2. One round of the lottery game ends each time the player sees a tail or consecutive kk heads. If a round ends in the former case (i.e., the round ends with the observation of a tail), the player looses the game in that round; Otherwise, the player wins the game in that round. Define a random variable WLG(k,)W_{\mathrm{LG}}(k,\ell) as the number of rounds that the player wins in the first \ell flips.

Lemma 3.9.

Pr(WLG(k,4ck2k)8ck)=11/2ck\Pr(W_{\mathrm{LG}}(k,4ck\cdot 2^{k})\leq 8ck)=1-1/2^{ck} holds for any k1k\geq 1 and c1c\geq 1.

Proof.

Let =4ck2k\ell=4ck\cdot 2^{k}. The player wins the game with probability 2k2^{-k} at each round independently from other rounds. Therefore, by Chernoff bound (Lemma A.1), the player wins the game at most 8ck8ck times in the first \ell rounds with probability at least 1exp((4ck)/3)11/2ck1-\exp(-(4ck)/3)\geq 1-1/2^{ck}. Obviously, the player plays at most \ell rounds in the first \ell flips, which completes the proof. ∎

Lemma 3.10.

Pr(WLG(k,64ck2k)16ck)=11/2ck\Pr(W_{\mathrm{LG}}(k,64ck\cdot 2^{k})\geq 16ck)=1-1/2^{ck} holds for any k2k\geq 2 and c1c\geq 1.

Proof.

Let =64ck2k\ell=64ck\cdot 2^{k}. The player wins the lottery game in at least 16ck16ck rounds in the first \ell flips if (i) the player plays at least /4\ell/4 rounds in the first \ell flips, and (ii) the players wins the game at least 16ck16ck rounds in the first /4\ell/4 rounds. By Chernoff bound (Lemma A.1), the first event occurs with probability at least 1exp((32ck2k)/8)11/2ck+11-\exp(-(32ck\cdot 2^{k})/8)\geq 1-1/2^{ck+1}. The player wins the game with probability 2k2^{-k} at each round independently from other rounds. Therefore, by Chernoff bound (Lemma A.1), the second event occurs with probability at least 1exp((16ck)/8)1eck=11/2ck+11-\exp(-(16ck)/8)\geq 1-e^{-ck}=1-1/2^{ck+1}. Thus, the proof follows from the union bound. ∎

We say that a signal at agent uiu_{i} encounters an interaction when uiu_{i} has an interaction.

Proof of Lemma 3.6.

We prove that the claim of the lemma holds when we define 𝒞mid\mathcal{C}_{\mathrm{mid}} as the set of all configurations in 𝒞NZ\mathcal{C}_{\mathrm{NZ}} where ui.𝚌𝚕𝚘𝚌𝚔κmax/2u_{i}.\mathtt{clock}\leq\kappa_{\mathrm{max}}/2 and ui.𝚖𝚘𝚍𝚎=𝐶𝑜𝑛𝑠𝑡𝑟𝑢𝑐𝑡u_{i}.\mathtt{mode}=\mathit{Construct} for all uiVu_{i}\in V.

First, we consider execution ΞP𝑃𝐿(C0,𝚪)=C0,C1,\Xi_{P_{\mathit{PL}}}(C_{0},\mathbf{\Gamma})=C_{0},C_{1},\dots, where C0𝒞NZC_{0}\in\mathcal{C}_{\mathrm{NZ}}. Since C0𝒞NZ1C_{0}\in\mathcal{C}_{\mathrm{NZ}}\subset\mathcal{L}_{\geq 1}, we can assume that u0u_{0} is a leader in C0C_{0} without loss of generality. The leader u0u_{0} generates a new signal when it interacts with u1u_{1}.444 Strictly speaking, u0u_{0} may be killed within a short time, but there must be always at least one leader because C0𝒞NZC_{0}\in\mathcal{C}_{\mathrm{NZ}}; thus we can shift indices of the agents so that u0u_{0} is still a leader. This event occurs within nlognn\log n steps with probability 1(11/n)nlogn=1O(1/n)1-(1-1/n)^{n\log n}=1-O(1/n). The generated signal visits all agents and resets their clocks in the next cn2c^{\prime}n^{2} steps for a constant cc^{\prime} if all of the following events occur:

(A):

𝑠𝑒𝑞R(0,n1)\mathit{seq}_{R}(0,n-1) occurs in the cn2c^{\prime}n^{2} steps,

(B):

The signal encounters at most 4cn4c^{\prime}n interactions in the cn2c^{\prime}n^{2} steps, and

(C):

The signal does not decrease its TTL to zero in the first 4cn4c^{\prime}n interactions it encounters.

Event (A) occurs w.h.p. by Lemma 2.3, while event (B) also occurs w.h.p. by Chernoff bound (Lemma A.1) because the signal encounters an interaction with probability 2/n2/n at each step. Event (C) holds w.h.p. by Lemma 3.9 with k=ψk=\psi and c=1c=1 for a sufficiently large κmax=Θ(ψ)\kappa_{\mathrm{max}}=\Theta(\psi). Thus, by the union bound, the clock of every agent is reset to zero at least once in the cn2c^{\prime}n^{2} steps. Again, by Lemma 3.9 with k=ψk=\psi and c=2c=2, it holds w.h.p. that no agent increases its clock κmax/2\kappa_{\mathrm{max}}/2 times in the cn2c^{\prime}n^{2} steps. Hence, the population will enter 𝒞mid\mathcal{C}_{\mathrm{mid}} within nlogn+cn2=O(n2)n\log n+c^{\prime}n^{2}=O(n^{2}) steps w.h.p.

Next, we consider execution ΞP𝑃𝐿(C0,𝚪)=C0,C1,\Xi_{P_{\mathit{PL}}}(C_{0},\mathbf{\Gamma})=C_{0},C_{1},\dots, where C0𝒞midC_{0}\in\mathcal{C}_{\mathrm{mid}}. In this execution, all agents remain in the construction mode until some agent increases its clock κmax/2\kappa_{\mathrm{max}}/2 times. By Lemma 3.9 with k=ψk=\psi and c=κmax/(16ψ)c=\kappa_{\mathrm{max}}/(16\psi), each agent uiu_{i} increases its clock κmax/2\kappa_{\mathrm{max}}/2 or more times in its next (κmax/4)2ψ(\kappa_{\mathrm{max}}/4)\cdot 2^{\psi} interactions with probability at most 12κmax/16=1O(1/n2)1-2^{\kappa_{\mathrm{max}}/16}=1-O(1/n^{2}). By Chernoff bound (Lemma A.1), uiu_{i} requires at least (nκmax/8)2ψ(n\kappa_{\mathrm{max}}/8)\cdot 2^{\psi} steps to have (κmax/4)2ψ(\kappa_{\mathrm{max}}/4)\cdot 2^{\psi} interactions with probability 1O(1/n2)1-O(1/n^{2}). Hence, by the union bound, in an execution starting from a configuration in 𝒞mid\mathcal{C}_{\mathrm{mid}}, all agents remain in the construction mode in the first (nκmax/8)2ψ=Ω(n2κmax)(n\kappa_{\mathrm{max}}/8)\cdot 2^{\psi}=\Omega(n^{2}\kappa_{\mathrm{max}}) steps w.h.p. ∎

Lemma 3.11.

Every resetting signal will be absorbed or disappear in O(n2κmax)O(n^{2}\kappa_{\mathrm{max}}) steps with probability 1O(1/n2)1-O(1/n^{2}).

Proof.

The TTL of a resetting signal never increases unless it is absorbed and merged with another signal. Hence, by Lemma 3.10 with k=ψk=\psi and c=κmax/(16ψ)c=\kappa_{\mathrm{max}}/(16\psi), the resetting signal is absorbed or disappears in the first 4κmax2ψ4\kappa_{\mathrm{max}}\cdot 2^{\psi} interactions it encounters with probability 11/2κmax/16=1O(1/n2)1-1/2^{\kappa_{\mathrm{max}}/16}=1-O(1/n^{2}). By Chernoff bound (Lemma A.1), a signal encounters at least 4κmax2ψ4\kappa_{\mathrm{max}}\cdot 2^{\psi} interactions or disappears within 4nκmax2ψ=O(n2κmax)4n\kappa_{\mathrm{max}}\cdot 2^{\psi}=O(n^{2}\kappa_{\mathrm{max}}) steps with probability 1O(1/n2)1-O(1/n^{2}). Thus, the union bound gives the lemma. ∎

Proof of Lemma 3.7.

It is clear that a configuration CC is in 𝒞det\mathcal{C}_{\mathrm{det}} if there is no leader, all agents are in the detection mode, and no resetting signal exists in CC. We will prove that ΞP𝑃𝐿(C0,𝚪)\Xi_{P_{\mathit{PL}}}(C_{0},\mathbf{\Gamma}) reaches such a configuration within O(n2logn)O(n^{2}\log n) steps w.h.p. Assume C00C_{0}\in\mathcal{L}_{0}. The number of resetting signals is monotonically non-increasing as long as there is no leader. Thus, the union bound and Lemma 3.11 yield that the population reaches a configuration where there is no signal or there is a leader within O(n2logn)O(n^{2}\log n) steps w.h.p. If there is no leader at this time, by Lemma 3.10 with k=ψk=\psi and c=κmax/(16ψ)c=\kappa_{\mathrm{max}}/(16\psi), each agent uiu_{i} increases its clock to κmax\kappa_{\mathrm{max}} in its next 4κmax2ψ4\kappa_{\mathrm{max}}\cdot 2^{\psi} interactions or some agent becomes a leader during the period with probability 1O(1/n2)1-O(1/n^{2}). By Chernoff bound (Lemma A.1), uiu_{i} has at least 4κmax2ψ4\kappa_{\mathrm{max}}\cdot 2^{\psi} interactions within 4nκmax2ψ=O(n2κmax)4n\kappa_{\mathrm{max}}\cdot 2^{\psi}=O(n^{2}\kappa_{\mathrm{max}}) steps with probability 1O(1/n2)1-O(1/n^{2}). Thus, the union bound gives the lemma. ∎

3.4. Leader Elimination

We use the leader elimination part of the protocol given by Yokota, Sudo, and Masuzawa (Yokota et al., 2021) as Function 𝙴𝚕𝚒𝚖𝚒𝚗𝚊𝚝𝚎𝙻𝚎𝚊𝚍𝚎𝚛𝚜()\mathtt{EliminateLeaders}() without any modification. The pseudocode is given in Algorithm 5. In this module, leaders try to kill each other by firing bullets to decrease the number of leaders to one. This module uses Shields, which removes bullets, to avoid killing all leaders from the population. An SS-LE protocol with bullets and shields in the ring is first introduced in Fischer and Jiang (Fischer and Jiang, 2006), but it requires Θ(n3)\Theta(n^{3}) expected steps for convergence. Yokota et al. (Yokota et al., 2021) improves the bullets-and-shields-war strategy to elect exactly one leader within O(n2)O(n^{2}) steps in expectation and O(n2logn)O(n^{2}\log n) steps with high probability.

The basic strategy is as follows. A leader fires a bullet to kill another leader. The fired bullet moves from left to right in the ring until it reaches a leader. A leader does not always fire a bullet: it fires a bullet only after it detects that the last bullet it fired reaches a (possibly different) leader. A leader may have a shield: a shielded leader is never killed even if it meets a bullet. There are two kinds of bullets: live bullets and dummy bullets. A live bullet kills an unshielded leader. However, a dummy bullet does not have capability to kill a leader. When a leader decides to fire a new bullet, the bullet becomes live or dummy with probability 1/21/2 each. When a leader fires a live bullet, it simultaneously generates a shield (if it is unshielded). When a leader fires a dummy bullet, it breaks the shield (if it is shielded). Thus, roughly speaking, each leader is shielded with probability 1/21/2 at each step. Therefore, when a live bullet reaches a leader, the leader becomes a follower with probability 1/21/2. This strategy is well designed: not all leaders kill each other simultaneously because a leader must be shielded if it fired a live bullet in the last shot. As a result, the number of leaders eventually decreases to one, but not to zero.

In what follows, we explain how we implement this strategy. Each agent vv maintains variables v.𝚋𝚞𝚕𝚕𝚎𝚝{0,1,2}v.\mathtt{bullet}\in\{0,1,2\}, v.𝚜𝚑𝚒𝚎𝚕𝚍{0,1}v.\mathtt{shield}\in\{0,1\}, and v.𝚜𝚒𝚐𝚗𝚊𝚕B{0,1}v.\mathtt{signal}_{B}\in\{0,1\}. As their names imply, v.𝚋𝚞𝚕𝚕𝚎𝚝=0v.\mathtt{bullet}=0 (resp. v.𝚋𝚞𝚕𝚕𝚎𝚝=1v.\mathtt{bullet}=1, v.𝚋𝚞𝚕𝚕𝚎𝚝=2v.\mathtt{bullet}=2) indicates that vv is now conveying no bullet (resp. a dummy bullet, a live bullet), while v.𝚜𝚑𝚒𝚎𝚕𝚍=1v.\mathtt{shield}=1 indicates that vv is shielded. A variable 𝚜𝚒𝚐𝚗𝚊𝚕B\mathtt{signal}_{B} is used by a leader to detect that the last bullet it fired already disappeared. Specifically, v.𝚜𝚒𝚐𝚗𝚊𝚕B=1v.\mathtt{signal}_{B}=1 indicates that vv is propagating a bullet-absence signal. A leader always generates a bullet-absence signal in its left neighbor when it interacts with its left neighbor (Line 62). This signal propagates from right to left (Line 62), while a bullet moves from left to right (Lines 58-60). A bullet disables a bullet-absence signal regardless of whether it is live or dummy, i.e., ui+1.𝚜𝚒𝚐𝚗𝚊𝚕Bu_{i+1}.\mathtt{signal}_{B} is reset to 0 when two agents uiu_{i} and ui+1u_{i+1} such that ui.𝚋𝚞𝚕𝚕𝚎𝚝>0u_{i}.\mathtt{bullet}>0 and ui+1.𝚜𝚒𝚐𝚗𝚊𝚕B=1u_{i+1}.\mathtt{signal}_{B}=1 have an interaction (Line 61). Thus, a bullet-absence signal propagates to a leader only after the last bullet fired by the leader disappears. When a leader uiu_{i} receives a bullet-absence signal from its right neighbor ui+1u_{i+1}, uiu_{i} waits for its next interaction to extract randomness from the uniformly random scheduler. At the next interaction, by the definition of the uniformly random scheduler, uiu_{i} interacts with its right neighbor ui+1u_{i+1} with probability 1/21/2 and its left neighbor ui1u_{i-1} with probability 1/21/2. In the former case, uiu_{i} fires a live bullet and becomes shielded (Lines 51-52). In the latter case, uiu_{i} fires a dummy bullet and becomes unshielded (Lines 53-54). In both cases, the received signal is deleted (Lines 52 and 54). The fired bullet moves from left to right each time the agent with the bullet, say uiu_{i}, interacts with its right neighbor ui+1u_{i+1} (Lines 59-60). However, the bullet disappears without moving to ui+1u_{i+1} if ui+1u_{i+1} already has another bullet at this time. Suppose that the bullet now reaches a leader. If the bullet is live and the leader is not shielded at that time, the leader is killed by the bullet (Line 56). The bullet disappears at this time regardless of whether the bullet is alive and/or the leader is shielded (Line 57).

Yokota et al. (Yokota et al., 2021) proves that this method decreases the number of leaders to one within O(n2)O(n^{2}) steps in expectation (thus within O(n2logn)O(n^{2}\log n) steps w.h.p. ) starting from any configuration in 𝒞NZ1\mathcal{C}_{\mathrm{NZ}}\subseteq\mathcal{L}_{\geq 1}. (See Lemma 4.11 in Section 4.2.)

51 if l.𝚕𝚎𝚊𝚍𝚎𝚛=l.𝚜𝚒𝚐𝚗𝚊𝚕B=1l.\mathtt{leader}=l.\mathtt{signal}_{B}=1 then
52       (l.𝚋𝚞𝚕𝚕𝚎𝚝,l.𝚜𝚑𝚒𝚎𝚕𝚍,l.𝚜𝚒𝚐𝚗𝚊𝚕B)(2,1,0)(l.\mathtt{bullet},l.\mathtt{shield},l.\mathtt{signal}_{B})\leftarrow(2,1,0)
53if r.𝚕𝚎𝚊𝚍𝚎𝚛=r.𝚜𝚒𝚐𝚗𝚊𝚕B=1r.\mathtt{leader}=r.\mathtt{signal}_{B}=1 then
54       (r.𝚋𝚞𝚕𝚕𝚎𝚝,r.𝚜𝚑𝚒𝚎𝚕𝚍,r.𝚜𝚒𝚐𝚗𝚊𝚕B)(1,0,0)(r.\mathtt{bullet},r.\mathtt{shield},r.\mathtt{signal}_{B})\leftarrow(1,0,0)
55if l.𝚋𝚞𝚕𝚕𝚎𝚝>0r.𝚕𝚎𝚊𝚍𝚎𝚛=1l.\mathtt{bullet}>0\land r.\mathtt{leader}=1 then
56       r.𝚕𝚎𝚊𝚍𝚎𝚛{0l.𝚋𝚞𝚕𝚕𝚎𝚝=2r.𝚜𝚑𝚒𝚎𝚕𝚍=01otherwiser.\mathtt{leader}\leftarrow\begin{cases}0&l.\mathtt{bullet}=2\land r.\mathtt{shield}=0\\ 1&\text{otherwise}\end{cases}
57       l.𝚋𝚞𝚕𝚕𝚎𝚝0l.\mathtt{bullet}\leftarrow 0
58      
59 else if l.𝚋𝚞𝚕𝚕𝚎𝚝>0r.𝚕𝚎𝚊𝚍𝚎𝚛=0l.\mathtt{bullet}>0\land r.\mathtt{leader}=0 then
60       r.𝚋𝚞𝚕𝚕𝚎𝚝{l.𝚋𝚞𝚕𝚕𝚎𝚝r.𝚋𝚞𝚕𝚕𝚎𝚝=0r.𝚋𝚞𝚕𝚕𝚎𝚝r.𝚋𝚞𝚕𝚕𝚎𝚝>0r.\mathtt{bullet}\leftarrow\begin{cases}l.\mathtt{bullet}&r.\mathtt{bullet}=0\\ r.\mathtt{bullet}&r.\mathtt{bullet}>0\end{cases}
61      
62      l.𝚋𝚞𝚕𝚕𝚎𝚝0l.\mathtt{bullet}\leftarrow 0
63       r.𝚜𝚒𝚐𝚗𝚊𝚕B0r.\mathtt{signal}_{B}\leftarrow 0
64      
l.𝚜𝚒𝚐𝚗𝚊𝚕Bmax(l.𝚜𝚒𝚐𝚗𝚊𝚕B,r.𝚜𝚒𝚐𝚗𝚊𝚕B,r.𝚕𝚎𝚊𝚍𝚎𝚛)l.\mathtt{signal}_{B}\leftarrow\max(l.\mathtt{signal}_{B},r.\mathtt{signal}_{B},r.\mathtt{leader})
Algorithm 5 𝙴𝚕𝚒𝚖𝚒𝚗𝚊𝚝𝚎𝙻𝚎𝚊𝚍𝚎𝚛𝚜()\mathtt{EliminateLeaders}()   ll is the initiator and rr is the responder of an interaction.

4. Correctness and Convergence Time

In this section, we prove Theorem 3.1 by showing that P𝑃𝐿P_{\mathit{PL}} is an SS-LE protocol on directed rings of any size nn given knowledge ψ=logn+O(1)\psi=\log n+O(1) and that the convergence time of P𝑃𝐿P_{\mathit{PL}} is O(n2logn)O(n^{2}\log n) steps w.h.p. First, in Section 4.1, we introduce a set 𝒮PL\mathcal{S}_{\mathrm{PL}} of configurations and prove that every configuration in 𝒮PL\mathcal{S}_{\mathrm{PL}} is safe. Next, in Section 4.2, we prove that the population reaches a configuration in 𝒮PL\mathcal{S}_{\mathrm{PL}} within O(n2logn)O(n^{2}\log n) steps w.h.p. starting from any configuration.

We use several functions whose return values depend on a configuration, such as dLL(i)d_{LL}(i) and dRL(i)d_{RL}(i). When a configuration should be specified, we explicitly write a configuration as the first argument of those functions. For example, we denote dLL(C,i)d_{LL}(C,i) and dRL(C,i)d_{RL}(C,i) to denote dLL(i)d_{LL}(i) and dRL(i)d_{RL}(i) in a configuration CC, respectively.

4.1. Safe Configurations

We introduce a set of safe configurations 𝒮PL\mathcal{S}_{\mathrm{PL}} here. Define 1\mathcal{L}_{1} as the set of configurations where there is exactly one leader. In the rest of this paper, whenever we consider a configuration C1C\in\mathcal{L}_{1}, we always assume that u0u_{0} is the unique leader in CC without loss of generality.

Of course, 𝒮PL1\mathcal{S}_{\mathrm{PL}}\subseteq\mathcal{L}_{1} must hold. Moreover, an execution starting from 𝒮PL\mathcal{S}_{\mathrm{PL}} must keep exactly one leader. Thus, it must not kill the unique leader u0u_{0}. Let us discuss what configurations have this property. We say that a live bullet located at agent uiu_{i} is peaceful when the following predicate holds:

𝑃𝑒𝑎𝑐𝑒𝑓𝑢𝑙(i)\displaystyle\mathit{Peaceful}(i) def(dLL(i)uidLL(i).𝚜𝚑𝚒𝚎𝚕𝚍=1j=0,1,,dLL(i):uij.𝚜𝚒𝚐𝚗𝚊𝚕B=0).\displaystyle\stackrel{{\scriptstyle\mathrm{def}}}{{\equiv}}\left(d_{LL}(i)\neq\infty\land u_{i-d_{LL}(i)}.\mathtt{shield}=1\land\forall j=0,1,\dots,d_{LL}(i):u_{i-j}.\mathtt{signal}_{B}=0\right).

A peaceful bullet never kills the last leader in the population because its nearest left leader uidLL(i)u_{i-d_{LL(i)}} is shielded. A peaceful bullet never becomes non-peaceful; because letting uiu_{i} be the agent at which the bullet is located, the agents uidLL(i),uidLL(i)+1,,uiu_{i-d_{LL}(i)},u_{i-d_{LL}(i)+1},\allowbreak\dots,u_{i} will never have a bullet-absence signal thus uidLL(i)u_{i-d_{LL}(i)} never becomes unshielded before the bullet disappears. At the beginning of an execution, there may be one or more non-peaceful live bullets. However, every newly-fired live bullet is peaceful because a leader becomes shielded and disables the bullet-absence signal when it fires a live bullet. Thus, once the population reaches a configuration where every live bullet is peaceful and there are one or more leaders, the number of leaders never becomes zero. Formally, we define the set of such configurations as follows:

𝒞PB={C1|uiV:C(ui).𝚋𝚞𝚕𝚕𝚎𝚝=2𝑃𝑒𝑎𝑐𝑒𝑓𝑢𝑙(C,i)}\displaystyle\mathcal{C}_{\mathrm{PB}}=\left\{C\in\mathcal{L}_{\geq 1}\mathrel{}\middle|\mathrel{}\forall u_{i}\in V:C(u_{i}).\mathtt{bullet}=2\Rightarrow\mathit{Peaceful}(C,i)\right\}

The following lemmas hold from the above discussion.

Lemma 4.1.

𝒞PB\mathcal{C}_{\mathrm{PB}} is closed.

Lemma 4.2.

𝒞PB𝒞NZ\mathcal{C}_{\mathrm{PB}}\subseteq\mathcal{C}_{\mathrm{NZ}}.

Then, is 𝒞PB1\mathcal{C}_{\mathrm{PB}}\cap\mathcal{L}_{1} closed? If the answer is yes, every configuration in 𝒞PB1\mathcal{C}_{\mathrm{PB}}\cap\mathcal{L}_{1} is safe; thus we can define 𝒮PL=𝒞PB1\mathcal{S}_{\mathrm{PL}}=\mathcal{C}_{\mathrm{PB}}\cap\mathcal{L}_{1}. Unfortunately, the answer is no: an execution starting from a configuration in 𝒞PB1\mathcal{C}_{\mathrm{PB}}\cap\mathcal{L}_{1} never kills the unique leader u0u_{0}, however it may create a new leader. We must specify the condition that the population never creates a leader. First, we define 𝒞DL𝒞PB1\mathcal{C}_{\mathrm{DL}}\subset\mathcal{C}_{\mathrm{PB}}\cap\mathcal{L}_{1} as the set of configurations where 𝚍𝚒𝚜𝚝\mathtt{dist} and 𝚕𝚊𝚜𝚝\mathtt{last} are correctly computed at every agent. Formally, we define

𝒞DL={C𝒞PB1|i[0,n1]:ui.𝚍𝚒𝚜𝚝=imod2ψ(ui.𝚕𝚊𝚜𝚝=1i[ψ(ζ1),n1])}.\mathcal{C}_{\mathrm{DL}}=\left\{C\in\mathcal{C}_{\mathrm{PB}}\cap\mathcal{L}_{1}\mathrel{}\middle|\mathrel{}\forall i\in[0,n-1]:u_{i}.\mathtt{dist}=i\bmod 2\psi\land(u_{i}.\mathtt{last}=1\Leftrightarrow i\in[\psi\cdot(\zeta-1),n-1])\right\}.

(Recall ζ=n/ψ\zeta=\lceil n/\psi\rceil.) Second, we consider the condition on a variable 𝚋\mathtt{b}. We define Si=uiψ,uiψ+1,,uiψ+ψ1S_{i}=u_{i\psi},u_{i\psi+1},\dots,u_{i\psi+\psi-1} for any i[0,ζ2]i\in[0,\zeta-2] and call SiS_{i} as the ii-th segment. Each segment SiS_{i} is a sequence of agents, but we sometimes use SiS_{i} as a set by abuse of notation. If a configuration CC is safe, we expect ι(C,Si+1)=ι(C,Si)+1mod2ψ\iota(C,S_{i+1})=\iota(C,S_{i})+1\bmod 2^{\psi} for any i[0,ζ3]i\in[0,\zeta-3], that is, CC must be perfect. This condition is still insufficient because a token may hold an inconsistent value so that it will change variable 𝚋\mathtt{b} or create a new leader even if the current configuration is perfect. Thus, we also expect that there is no such token. For any token zz located at uku_{k}, we call agent uk+uk.𝚝𝚘𝚔𝚎𝚗[1]u_{k+u_{k}.\mathtt{token}[1]} the target of zz, denoted by T(z)T(z). Recall that a token changes its moving direction every time it reaches its target. For any i[0,ζ2]i\in[0,\zeta-2], we say that a valid token zz located at uku_{k} is working for (Si,Si+1)(S_{i},S_{i+1}) if both uku_{k} and T(z)T(z) are in SiSi+1S_{i}\cup S_{i+1}. Recall the definition of valid tokens (Definition 3.3). Since zz is valid, ii is an even number if and only if zz is black. For any x[0,ψ1]x\in[0,\psi-1], we say that a valid token zz working for (Si,Si+1)(S_{i},S_{i+1}) is in the xx-th round if its target is uiψ+ψ+xu_{i\psi+\psi+x} or uiψ+x+1u_{i\psi+x+1}. In each round ii, the token zz moves right from uiψ+xu_{i\psi+x}, reaches the target uiψ+ψ+xu_{i\psi+\psi+x}, changes the direction to the left, and finally reaches the target uiψ+x+1u_{i\psi+x+1}. Then, we can define the correctness of tokens. Recall that 𝚝𝚘𝚔𝚎𝚗[2]\mathtt{token}[2] stores the binary value to set (check) at the target and 𝚝𝚘𝚔𝚎𝚗[3]\mathtt{token}[3] stores the carry flag.

Definition 4.3.

Consider that a valid token zz working for (Si,Si+1)(S_{i},S_{i+1}) is in the xx-th round and is located at uku_{k}. Let jj be the minimum integer in [0,ψ1][0,\psi-1] such that uiψ+j.𝚋=0u_{i\psi+j}.\mathtt{b}=0. Define j=ψj=\psi if no such jj exists in [0,ψ1][0,\psi-1]. Then, we say that zz is correct if all of the followings hold:

  • uk.𝚝𝚘𝚔𝚎𝚗[3]=1u_{k}.\mathtt{token}[3]=1 if and only if xjx\leq j, and

  • uk.𝚝𝚘𝚔𝚎𝚗[2]=uiψ+x.𝚋uk.𝚝𝚘𝚔𝚎𝚗[3]u_{k}.\mathtt{token}[2]=u_{i\psi+x}.\mathtt{b}\oplus u_{k}.\mathtt{token}[3].

The following lemmas immediately follow from the definition of correct tokens.

Lemma 4.4.

Let i[0,ζ3]i\in[0,\zeta-3], and let zz be a correct token which is working for Si,Si+1S_{i},S_{i+1}, located at uku_{k}, and in the xx-th round in a configuration C𝒞DLC\in\mathcal{C}_{\mathrm{DL}}. Then, zz satisfies uk.𝚝𝚘𝚔𝚎𝚗[2]=bxu_{k}.\mathtt{token}[2]=b_{x}, where b0,b1,,bψ1b_{0},b_{1},\dots,b_{\psi-1} is a sequence of bits such that j[0,ψ1]bj2j=ι(Si)+1mod2ψ\sum_{j\in[0,\psi-1]}b_{j}\cdot 2^{j}=\iota(S_{i})+1\bmod 2^{\psi} in CC.

Lemma 4.5.

A correct token working for (Si,Si+1)(S_{i},S_{i+1}) becomes incorrect only when ι(Si)\iota(S_{i}) changes, as long as the population is in 𝒞DL\mathcal{C}_{\mathrm{DL}}.

Now, we have all ingredients to define 𝒮PL\mathcal{S}_{\mathrm{PL}}.

Definition 4.6.

Define 𝒮PL\mathcal{S}_{\mathrm{PL}} as the set of configurations in 𝒞DL\mathcal{C}_{\mathrm{DL}} where all tokens are valid and correct, and ι(Si+1)=ι(Si)+1mod(2ψ)\iota(S_{i+1})=\iota(S_{i})+1\bmod(2^{\psi}) holds for all i[0,ζ3]i\in[0,\zeta-3].

Lemma 4.7.

𝒮PL\mathcal{S}_{\mathrm{PL}} is closed. Every configuration in 𝒮PL\mathcal{S}_{\mathrm{PL}} is safe.

Proof.

Since 𝒮PL𝒞PB1\mathcal{S}_{\mathrm{PL}}\subset\mathcal{C}_{\mathrm{PB}}\cap\mathcal{L}_{1}, every configuration in 𝒮PL\mathcal{S}_{\mathrm{PL}} is safe if 𝒮PL\mathcal{S}_{\mathrm{PL}} is closed. Thus, it suffices to prove the first claim: 𝒮PL\mathcal{S}_{\mathrm{PL}} is closed. Let C𝒮PL,C𝒞all(P𝑃𝐿)C\in\mathcal{S}_{\mathrm{PL}},C^{\prime}\in\mathcal{C}_{\mathrm{all}}(P_{\mathit{PL}}) be configurations such that CC changes to CC^{\prime} by one interaction. Since all tokens are correct in CC, by Lemma 4.4, no agent changes variable 𝚋\mathtt{b} and no agent becomes a new leader in that interaction. The population can deviate from 𝒞DL\mathcal{C}_{\mathrm{DL}} only when a new leader is created. Thus, C𝒞DLC^{\prime}\in\mathcal{C}_{\mathrm{DL}} and ι(C,Si+1)=ι(C,Si)+1mod(2ψ)\iota(C^{\prime},S_{i+1})=\iota(C^{\prime},S_{i})+1\bmod(2^{\psi}) holds. By Lemma 4.5, all tokens that appear in CC are still correct in CC^{\prime}. Moreover, every token is valid and correct when it is generated by a leader by definition of correctness. Thus, all tokens are valid and correct in CC^{\prime}. Hence, CC^{\prime} is still in 𝒮PL\mathcal{S}_{\mathrm{PL}}, which proves the lemma. ∎

4.2. Convergence

In this subsection, we prove that an execution of P𝑃𝐿P_{\mathit{PL}} starting from any configuration in 𝒞all(P𝑃𝐿)\mathcal{C}_{\mathrm{all}}(P_{\mathit{PL}}) reaches a configuration in 𝒮PL\mathcal{S}_{\mathrm{PL}} within O(n2logn)O(n^{2}\log n) steps w.h.p. We give this upper bound in two steps: we first show that execution ΞP𝑃𝐿(C0,𝚪)\Xi_{P_{\mathit{PL}}}(C_{0},\mathbf{\Gamma}) enters 𝒞PB\mathcal{C}_{\mathrm{PB}} within O(n2logn)O(n^{2}\log n) steps w.h.p. for any C0𝒞all(P𝑃𝐿)C_{0}\in\mathcal{C}_{\mathrm{all}}(P_{\mathit{PL}}), and next show that ΞP𝑃𝐿(C0,𝚪)\Xi_{P_{\mathit{PL}}}(C_{0},\mathbf{\Gamma}) enters 𝒮PL\mathcal{S}_{\mathrm{PL}} within O(n2logn)O(n^{2}\log n) steps w.h.p. if C0𝒞PBC_{0}\in\mathcal{C}_{\mathrm{PB}}.

To prove the first claim, we introduce two sets of configurations 𝒞NoLB\mathcal{C}_{\mathrm{NoLB}} and 𝒞NoBAS\mathcal{C}_{\mathrm{NoBAS}}: 𝒞NoLB\mathcal{C}_{\mathrm{NoLB}} is the set of all configurations where there is no live bullets in the population, and 𝒞NoBAS\mathcal{C}_{\mathrm{NoBAS}} is the set of all configurations where there is no bullet-absence signal in the population.

Lemma 4.8.

Let C0𝒞all(P𝑃𝐿)C_{0}\in\mathcal{C}_{\mathrm{all}}(P_{\mathit{PL}}). Then, Ξ=ΞP𝑃𝐿(C0,𝚪)\Xi=\Xi_{P_{\mathit{PL}}}(C_{0},\mathbf{\Gamma}) enters 𝒞PB𝒞NoLB𝒞NoBAS\mathcal{C}_{\mathrm{PB}}\cup\mathcal{C}_{\mathrm{NoLB}}\cup\mathcal{C}_{\mathrm{NoBAS}} within O(n2)O(n^{2}) steps w.h.p.

Proof.

By Lemma 2.3, it suffices to show that Ξ\Xi enters 𝒞PB𝒞NoLB𝒞NoBAS\mathcal{C}_{\mathrm{PB}}\cup\mathcal{C}_{\mathrm{NoLB}}\cup\mathcal{C}_{\mathrm{NoBAS}} before or when (𝑠𝑒𝑞R(0,n))2(\mathit{seq}_{R}(0,n))^{2} completes. Assume C0𝒞PB𝒞NoLB𝒞NoBASC_{0}\notin\mathcal{C}_{\mathrm{PB}}\cup\mathcal{C}_{\mathrm{NoLB}}\cup\mathcal{C}_{\mathrm{NoBAS}} because otherwise we do not need to prove anything. Then, there are one or more live bullets in C0C_{0}. Let bb be any such live bullet. The sequence of interactions (𝑠𝑒𝑞R(0,n))2(\mathit{seq}_{R}(0,n))^{2} lets bb visit all agents in the clockwise direction or disappear. Consider that bb survives in (𝑠𝑒𝑞R(0,n))2(\mathit{seq}_{R}(0,n))^{2}. If there is a leader in the population at that time, bb must be peaceful because there is no bullet-absence signal between bb and its nearest left leader. Otherwise, bb has removed all bullet-absence signals from the population. Since we picked up any live bullet for bb and a newly generated live bullet is always peaceful, we can conclude that at least one of the followings holds when (𝑠𝑒𝑞R(0,n))2(\mathit{seq}_{R}(0,n))^{2} completes: (i) there is no live bullet, (ii) there is no bullet-absence signal, or (iii) there is a leader and all live bullets are peaceful. This completes the proof. ∎

Lemma 4.9.

Let C0𝒞NoLB𝒞NoBASC_{0}\in\mathcal{C}_{\mathrm{NoLB}}\cup\mathcal{C}_{\mathrm{NoBAS}}. Then, Ξ=ΞP𝑃𝐿(C0,𝚪)=C0,C1,\Xi=\Xi_{P_{\mathit{PL}}}(C_{0},\mathbf{\Gamma})=C_{0},C_{1},\dots enters 𝒞PB\mathcal{C}_{\mathrm{PB}} within O(n2logn)O(n^{2}\log n) steps w.h.p.

Proof.

1(𝒞NoLB𝒞NoBAS)𝒞PB\mathcal{L}_{\geq 1}\cap(\mathcal{C}_{\mathrm{NoLB}}\cup\mathcal{C}_{\mathrm{NoBAS}})\subset\mathcal{C}_{\mathrm{PB}} holds by definition of 𝒞PB\mathcal{C}_{\mathrm{PB}}. Hence, let us assume C00C_{0}\in\mathcal{L}_{0} because otherwise C0𝒞PBC_{0}\in\mathcal{C}_{\mathrm{PB}} and the proof is already done. Let tt be the minimum positive integer such that Ct10C_{t-1}\in\mathcal{L}_{0} and Ct1C_{t}\in\mathcal{L}_{\geq 1}. Only leaders generate bullet-absence signals or fire live bullets. Thus, Ct1𝒞NoLB𝒞NoBASC_{t-1}\in\mathcal{C}_{\mathrm{NoLB}}\cup\mathcal{C}_{\mathrm{NoBAS}}. An agent gets shielded and fires a live bullet when it becomes a leader (Lines 6 and 18). If Ct1𝒞NoLBC_{t-1}\in\mathcal{C}_{\mathrm{NoLB}}, the fired bullet is peaceful and the only live bullet in the population, thus Ct𝒞PBC_{t}\in\mathcal{C}_{\mathrm{PB}}. If Ct1𝒞NoBASC_{t-1}\in\mathcal{C}_{\mathrm{NoBAS}}, all live bullets become peaceful by the event of leader creation, thus Ct𝒞PBC_{t}\in\mathcal{C}_{\mathrm{PB}}. Therefore, in any case, we have Ct𝒞PBC_{t}\in\mathcal{C}_{\mathrm{PB}}.

Thus, it suffices to show that a leader is created within O(n2logn)O(n^{2}\log n) steps w.h.p. All agents enter the detection mode and all resetting signals disappear from the population in O(n2logn)O(n^{2}\log n) steps w.h.p. by Lemma 3.7. Thereafter, all agents are in the detection mode until a new leader is created. We can assume that nn can be divided by ψ\psi and ui+1.𝚍𝚒𝚜𝚝=ui.𝚍𝚒𝚜𝚝+1mod2ψu_{i+1}.\mathtt{dist}=u_{i}.\mathtt{dist}+1\bmod 2\psi holds for all i[0,n1]i\in[0,n-1] because otherwise the inconsistency is detected and a new leader is created (Line 6) within O(nlogn)O(n\log n) steps w.h.p. We assume u0.𝚍𝚒𝚜𝚝=0u_{0}.\mathtt{dist}=0 without loss of generality. Then, all agents will have 𝚕𝚊𝚜𝚝=0\mathtt{last}=0 before or when 𝑠𝑒𝑞L(0,n)\mathit{seq}_{L}(0,n) completes, which requires O(n2)O(n^{2}) steps w.h.p. by Lemma 2.3. Thereafter, no agent changes 𝚍𝚒𝚜𝚝\mathtt{dist} or 𝚕𝚊𝚜𝚝\mathtt{last} until a leader is created. Let Si=uiψ,uiψ+1,,uiψ+ψ1S_{i}=u_{i\psi},u_{i\psi+1},\dots,u_{i\psi+\psi-1} for all i[0,ζ1]i\in[0,\zeta-1], where ζ=n/ψ\zeta=n/\psi. At this time, by Lemma 3.2, there must be i[0,ζ1]i\in[0,\zeta-1] such that ι(Si+1)ι(Si)+1mod2ψ\iota(S_{i+1})\neq\iota(S_{i})+1\bmod 2^{\psi}. Agents in the detection mode never update variable 𝚋\mathtt{b}, thus ι(Si)\iota(S_{i}) never changes until a leader is created. Since a newly generated token is always correct, by Lemmas 3.5, 4.4, and 4.5, ι(Si+1)ι(Si)+1mod2ψ\iota(S_{i+1})\neq\iota(S_{i})+1\bmod 2^{\psi} will be detected and a new leader will be created before or when (𝑠𝑒𝑞R(iψ,2ψ1)𝑠𝑒𝑞L(iψ+2ψ1,2ψ1))2ψ(\mathit{seq}_{R}(i\psi,2\psi-1)\cdot\mathit{seq}_{L}(i\psi+2\psi-1,2\psi-1))^{2\psi} completes, which requires O(nlog2n)O(n\log^{2}n) steps w.h.p. by Lemma 2.3. To conclude, a new leader is created within O(n2logn)O(n^{2}\log n) steps w.h.p. ∎

Lemma 4.10.

Let C0𝒞all(P𝑃𝐿)C_{0}\in\mathcal{C}_{\mathrm{all}}(P_{\mathit{PL}}). Then, Ξ=ΞP𝑃𝐿(C0,𝚪)\Xi=\Xi_{P_{\mathit{PL}}}(C_{0},\mathbf{\Gamma}) enters 𝒞PB\mathcal{C}_{\mathrm{PB}} within O(n2logn)O(n^{2}\log n) steps w.h.p.

Proof.

Immediately follows from Lemmas 4.8 and 4.9. ∎

Next, we prove the second claim, i.e., ΞP𝑃𝐿(C0,𝚪)\Xi_{P_{\mathit{PL}}}(C_{0},\mathbf{\Gamma}) enters 𝒮PL\mathcal{S}_{\mathrm{PL}} within O(n2logn)O(n^{2}\log n) steps w.h.p. for any C0𝒞PBC_{0}\in\mathcal{C}_{\mathrm{PB}}. To prove the claim, we introduce a new protocol P𝑃𝐿P_{\mathit{PL}}^{\prime}, which can be obtained by removing Lines 6 and 18, i.e., by disabling the ability to create a leader. Note that 𝒞all(P𝑃𝐿)=𝒞all(P𝑃𝐿)\mathcal{C}_{\mathrm{all}}(P_{\mathit{PL}})=\mathcal{C}_{\mathrm{all}}(P_{\mathit{PL}}^{\prime}) holds because P𝑃𝐿P_{\mathit{PL}} and P𝑃𝐿P_{\mathit{PL}}^{\prime} have the same set of variables. Importantly, two executions Ξ=ΞP𝑃𝐿(C0,𝚪)\Xi=\Xi_{P_{\mathit{PL}}}(C_{0},\mathbf{\Gamma}) and Ξ=ΞP𝑃𝐿(C0,𝚪)\Xi^{\prime}=\Xi_{P_{\mathit{PL}}^{\prime}}(C_{0},\mathbf{\Gamma}) are the same until a new leader is created in Ξ\Xi.

Lemma 4.11 ((Yokota et al., 2021)).

Let D0𝒞PBD_{0}\in\mathcal{C}_{\mathrm{PB}}. Then, Ξ=ΞP𝑃𝐿(D0,𝚪)\Xi^{\prime}=\Xi_{P_{\mathit{PL}}^{\prime}}(D_{0},\mathbf{\Gamma}) enters 𝒞PB1\mathcal{C}_{\mathrm{PB}}\cap\mathcal{L}_{1} within O(n2logn)O(n^{2}\log n) steps w.h.p.

Proof.

Yokota et al. (Yokota et al., 2021) shows that 𝙴𝚕𝚒𝚖𝚒𝚗𝚊𝚝𝚎𝙻𝚎𝚊𝚍𝚎𝚛𝚜()\mathtt{EliminateLeaders}() decreases the number of leaders to one within O(n2)O(n^{2}) steps in expectation as long as a new leader is not created. Since P𝑃𝐿P_{\mathit{PL}}^{\prime} does not have ability to create a new leader, Ξ\Xi^{\prime} reaches a configuration in 𝒞PB1\mathcal{C}_{\mathrm{PB}}\cap\mathcal{L}_{1} within O(n2)O(n^{2}) steps in expectation. By Markov’s inequality, Ξ\Xi^{\prime} enters 𝒞PB1\mathcal{C}_{\mathrm{PB}}\cap\mathcal{L}_{1} within O(n2)O(n^{2}) steps with probability 1/21/2. Since 𝒞PB\mathcal{C}_{\mathrm{PB}} is closed by Lemma 4.1, Ξ\Xi^{\prime} enters 𝒞PB1\mathcal{C}_{\mathrm{PB}}\cap\mathcal{L}_{1} within O(n2logn)O(n^{2}\log n) steps with probability at least 1(11/2)logn=1O(1/n)1-(1-1/2)^{\log n}=1-O(1/n). ∎

Lemma 4.12.

Let D0𝒞PBD_{0}\in\mathcal{C}_{\mathrm{PB}}. Then, Ξ=ΞP𝑃𝐿(D0,𝚪)\Xi^{\prime}=\Xi_{P_{\mathit{PL}}^{\prime}}(D_{0},\mathbf{\Gamma}) enters 𝒮PL\mathcal{S}_{\mathrm{PL}} within O(n2logn)O(n^{2}\log n) steps w.h.p.

Proof.

We can assume D0𝒞PB1D_{0}\in\mathcal{C}_{\mathrm{PB}}\cap\mathcal{L}_{1} by Lemma 4.11. As mentioned above, we always assume that u0u_{0} is the unique leader in a configuration in 1\mathcal{L}_{1}. Then, 𝑠𝑒𝑞R(0,n1)𝑠𝑒𝑞L(0,n1)\mathit{seq}_{R}(0,n-1)\cdot\mathit{seq}_{L}(0,n-1) let the population enter 𝒞DL\mathcal{C}_{\mathrm{DL}}, which requires O(n2)O(n^{2}) steps w.h.p. by Lemma 2.3. Since a newly generated token is always correct, the next (𝑠𝑒𝑞R(0,2ψ1)𝑠𝑒𝑞L(2ψ1,2ψ1))2ψ(𝑠𝑒𝑞R(ψ,2ψ1)𝑠𝑒𝑞L(3ψ1,2ψ1))2ψ(𝑠𝑒𝑞R((ζ3)ψ,2ψ1)𝑠𝑒𝑞L((ζ1)ψ1,2ψ1))2ψ(\mathit{seq}_{R}(0,2\psi-1)\cdot\mathit{seq}_{L}(2\psi-1,2\psi-1))^{2\psi}\cdot(\mathit{seq}_{R}(\psi,2\psi-1)\cdot\mathit{seq}_{L}(3\psi-1,2\psi-1))^{2\psi}\cdot\dots\cdot(\mathit{seq}_{R}((\zeta-3)\psi,2\psi-1)\cdot\mathit{seq}_{L}((\zeta-1)\psi-1,2\psi-1))^{2\psi}, where ζ=n/ψ\zeta=\lceil n/\psi\rceil, lets the population enter 𝒮PL\mathcal{S}_{\mathrm{PL}} by Lemmas 3.5, 4.4, and 4.5. This requires O(nψ2ζ)=O(n2ψ)=O(n2logn)O(n\psi^{2}\zeta)=O(n^{2}\psi)=O(n^{2}\log n) steps w.h.p. by Lemma 2.3. ∎

Lemma 4.13.

Let C0𝒞PBC_{0}\in\mathcal{C}_{\mathrm{PB}}. Then, Ξ=ΞP𝑃𝐿(C0,𝚪)\Xi=\Xi_{P_{\mathit{PL}}}(C_{0},\mathbf{\Gamma}) enters 𝒮PL\mathcal{S}_{\mathrm{PL}} within O(n2logn)O(n^{2}\log n) steps w.h.p. for a sufficiently large κmax=Θ(ψ)=Θ(logn)\kappa_{\mathrm{max}}=\Theta(\psi)=\Theta(\log n).

Proof.

By Lemma 3.6, there exists a set 𝒞mid\mathcal{C}_{\mathrm{mid}} of configurations such that (i) Ξ\Xi enters 𝒞mid\mathcal{C}_{\mathrm{mid}} within O(n2)O(n^{2}) steps w.h.p., and (ii) letting Ct𝒞midC_{t}\in\mathcal{C}_{\mathrm{mid}}, all agents are in the construction mode in the first Ω(κmaxn2)\Omega(\kappa_{\mathrm{max}}n^{2}) steps of ΞP𝑃𝐿(Ct,𝚪)=Ct,Ct+1,Ct+2,\Xi_{P_{\mathit{PL}}}(C_{t},\mathbf{\Gamma})=C_{t},C_{t+1},C_{t+2},\dots w.h.p. Thus, ΞP𝑃𝐿(Ct,𝚪)\Xi_{P_{\mathit{PL}}}(C_{t},\mathbf{\Gamma}) does not create a leader in the first Ω(κmaxn2)\Omega(\kappa_{\mathrm{max}}n^{2}) steps w.h.p. Therefore, ΞP𝑃𝐿(Ct,𝚪)\Xi_{P_{\mathit{PL}}}(C_{t},\mathbf{\Gamma}) and ΞP𝑃𝐿(Ct,𝚪)\Xi_{P_{\mathit{PL}}^{\prime}}(C_{t},\mathbf{\Gamma}) are the same in the first Ω(κmaxn2)\Omega(\kappa_{\mathrm{max}}n^{2}) steps w.h.p. Since κmax\kappa_{\mathrm{max}} is a sufficiently large O(logn)O(\log n) value, by Lemma 4.12, we conclude that Ξ\Xi enters 𝒮PL\mathcal{S}_{\mathrm{PL}} within O(n2logn)O(n^{2}\log n) steps w.h.p. ∎

Theorem 3.1 immediately follows from Lemmas 4.7 and 4.13.

65
Variables in Agents:
   𝚌𝚘𝚕𝚘𝚛,𝚌𝟷,𝚌𝟸{0,1,,ξ1}\mathtt{color},\mathtt{c1},\mathtt{c2}\in\{0,1,\dots,\xi-1\}, // input variables
   𝚍𝚒𝚛{0,1,,ξ1}\mathtt{dir}\in\{0,1,\dots,\xi-1\},    𝚜𝚝𝚛𝚘𝚗𝚐{0,1}\mathtt{strong}\in\{0,1\}
66
67if u.𝚍𝚒𝚛=v.𝚌𝚘𝚕𝚘𝚛v.𝚍𝚒𝚛=u.𝚌𝚘𝚕𝚘𝚛u.\mathtt{dir}=v.\mathtt{color}\land v.\mathtt{dir}=u.\mathtt{color} then
68       if u.𝚜𝚝𝚛𝚘𝚗𝚐=0v.𝚜𝚝𝚛𝚘𝚗𝚐=1u.\mathtt{strong}=0\land v.\mathtt{strong}=1 then
69             u.𝚍𝚒𝚛u.\mathtt{dir}\leftarrow (the unique c{u.𝚌𝟷,u.𝚌𝟸}c\in\{u.\mathtt{c1},u.\mathtt{c2}\} such that cv.𝚌𝚘𝚕𝚘𝚛c\neq v.\mathtt{color})
70             (u.𝚜𝚝𝚛𝚘𝚗𝚐,v.𝚜𝚝𝚛𝚘𝚗𝚐)(1,0)(u.\mathtt{strong},v.\mathtt{strong})\leftarrow(1,0)
71            
72       else
73             v.𝚍𝚒𝚛v.\mathtt{dir}\leftarrow (the unique c{v.𝚌𝟷,v.𝚌𝟸}c\in\{v.\mathtt{c1},v.\mathtt{c2}\} such that cu.𝚌𝚘𝚕𝚘𝚛c\neq u.\mathtt{color})
74             (u.𝚜𝚝𝚛𝚘𝚗𝚐,v.𝚜𝚝𝚛𝚘𝚗𝚐)(0,1)(u.\mathtt{strong},v.\mathtt{strong})\leftarrow(0,1)
75            
76      
77 else if u.𝚍𝚒𝚛=v.𝚌𝚘𝚕𝚘𝚛u.\mathtt{dir}=v.\mathtt{color} then
78       u.𝚜𝚝𝚛𝚘𝚗𝚐0u.\mathtt{strong}\leftarrow 0
79      
80 else if v.𝚍𝚒𝚛=u.𝚌𝚘𝚕𝚘𝚛v.\mathtt{dir}=u.\mathtt{color} then
81       v.𝚜𝚝𝚛𝚘𝚗𝚐0v.\mathtt{strong}\leftarrow 0
82      
Algorithm 6 P𝑂𝑅P_{\mathit{OR}}

5. Removal of the Orientation Assumption

In this section, we present how to remove the assumption that the population is a directed ring. Specifically, we present a self-stabilizing ring orientation algorithm that uses only O(1)O(1) states and converges in O(n2logn)O(n^{2}\log n) steps w.h.p. on any (non-directed) ring G=(V,E)G=(V,E). As in the previous sections, we assume V={u0,u1,,un1}V=\{u_{0},u_{1},\dots,u_{n-1}\}, but do not assume E={(ui,ui+1modn)i=0,1,,n1}E=\{(u_{i},u_{i+1\bmod n})\mid i=0,1,\dots,n-1\}. Instead, we assume E={(ui,ui+1modn)i=0,1,,n1}{(ui+1modn,ui)i=0,1,,n1}E=\{(u_{i},u_{i+1\bmod n})\mid i=0,1,\dots,n-1\}\cup\{(u_{i+1\bmod n},u_{i})\mid i=0,1,\dots,n-1\} in this section. We define a self-stabilizing ring orientation algorithm as follows.

Definition 5.1 (Self-stabilizing Ring Orientation (SS-RO)).

Let PP be a protocol that has output variables 𝚌𝚘𝚕𝚘𝚛,𝚍𝚒𝚛[0,ξ1]\mathtt{color},\mathtt{dir}\in[0,\xi-1], where ξ\xi is a positive integer. We say that a configuration CC of PP is safe if (i) ui.𝚌𝚘𝚕𝚘𝚛ui+2.𝚌𝚘𝚕𝚘𝚛u_{i}.\mathtt{color}\neq u_{i+2}.\mathtt{color} for any i[0,n1]i\in[0,n-1], (ii) ui.𝚍𝚒𝚛=ui+1.𝚌𝚘𝚕𝚘𝚛u_{i}.\mathtt{dir}=u_{i+1}.\mathtt{color} holds for any i[0,n1]i\in[0,n-1] or uj.𝚍𝚒𝚛=uj1.𝚌𝚘𝚕𝚘𝚛u_{j}.\mathtt{dir}=u_{j-1}.\mathtt{color} holds for any j[0,n1]j\in[0,n-1], and (iii) at every configuration reachable from CC, no agent changes the values of the output variables 𝚌𝚘𝚕𝚘𝚛\mathtt{color} or 𝚍𝚒𝚛\mathtt{dir}. A protocol PP is a self-stabilizing ring orientation (SS-RO) protocol if ΞP(C0,𝚪)\Xi_{P}(C_{0},\mathbf{\Gamma}) reaches a safe configuration with probability 11 for any configuration C0𝒞all(P)C_{0}\in\mathcal{C}_{\mathrm{all}}(P).

The first condition is the specification of a well-known problem called two-hop coloring, by which each agent can distinguish its two neighbors. The second condition give the agents a common sense of direction: each agent points at one of its neighbors, and two neighboring agents uiu_{i} and ui+1u_{i+1} never points at each other, i.e., ui.𝚍𝚒𝚛=ui+1.𝚌𝚘𝚕𝚘𝚛ui+1.𝚍𝚒𝚛ui.𝚌𝚘𝚕𝚘𝚛u_{i}.\mathtt{dir}=u_{i+1}.\mathtt{color}\ \Leftrightarrow\ u_{i+1}.\mathtt{dir}\neq u_{i}.\mathtt{color}.

Fortunately, there are several self-stabilizing two-hop coloring protocols (Angluin et al., 2008b; Sudo et al., 2018). We use the protocol presented in (Sudo et al., 2018) here. This protocol uses a polynomial number of colors (i.e., C=poly(n)C=\mathrm{poly}(n)) to guarantee fast convergence time for arbitrary graphs. However, for a constant degree graph, this protocol converges in sufficiently short time (i.e., O(n2logn)O(n^{2}\log n) steps) w.h.p. with a constant number of colors. Moreover, once two-hop coloring is achieved, the agents can memorize the set of the colors of their two neighbors in O(nlogn)O(n\log n) steps w.h.p. with O(1)O(1) states by the following simple protocol:

Each agent memorizes the two different colors that it observes most recently.

Therefore, without loss of generality, we give an SS-RO protocol under the assumption that the first condition of Definition 5.1 is always satisfied, each agent maintains two variables 𝚌𝟷,𝚌𝟸[0,ξ1]\mathtt{c1},\mathtt{c2}\in[0,\xi-1], and these variables always satisfy {ui.𝚌𝟷,ui.𝚌𝟸}={ui1.𝚌𝚘𝚕𝚘𝚛,ui+1.𝚌𝚘𝚕𝚘𝚛}\{u_{i}.\mathtt{c1},u_{i}.\mathtt{c2}\}=\{u_{i-1}.\mathtt{color},u_{i+1}.\mathtt{color}\} for any i[0,n1]i\in[0,n-1].

The proposed SS-RO protocol, named P𝑂𝑅P_{\mathit{OR}}, is shown in Algorithm 6. In this pseudocode, uu is the initiator and vv is the responder. We call a maximal sequence of agents ui,ui+1,,ui+ku_{i},u_{i+1},\dots,u_{i+k} such that ui+j.𝚍𝚒𝚛=ui+j+1.𝚌𝚘𝚕𝚘𝚛u_{i+j}.\mathtt{dir}=u_{i+j+1}.\mathtt{color} with every j[0,k1]j\in[0,k-1] a right segment. We call ui+ku_{i+k} a head in this segment. We call a maximal sequence of agents ui,ui1,,uiku_{i},u_{i-1},\dots,u_{i-k} such that uij.𝚍𝚒𝚛=uij1.𝚌𝚘𝚕𝚘𝚛u_{i-j}.\mathtt{dir}=u_{i-j-1}.\mathtt{color} with every j[0,k1]j\in[0,k-1] a left segment. We call uiku_{i-k} a head in this segment. We collectively call those segments just segments. In P𝑂𝑅P_{\mathit{OR}}, each head always tries to extend its segment. When two heads meet, only one of the two heads wins and succeeds in extending its segment (Line 63-69). The lost segment decreases its size by one. Segment extension occurs only when two heads meet. Thus, the number of segments in the population is monotonically non-increasing. When a segment with size one loses, the segment disappears and the number of segments decreases by one or two. Usually, the number of segments decreases by two because when a segment disappears, its two neighboring segments are merged. Only exception is the case where there are only two segments and one of them disappers. Thus, the population will eventually reach a configuration where there is only one segment, at which the ring orientation is achieved.

To speed up the protocol, we introduce a variable 𝚜𝚝𝚛𝚘𝚗𝚐{0,1}\mathtt{strong}\in\{0,1\}. An agent uiu_{i} is called strong if ui.𝚜𝚝𝚛𝚘𝚗𝚐=1u_{i}.\mathtt{strong}=1. Otherwise, the agent is weak. We have the following rule (Lines 64–69):

  • When a strong head and a weak head meets, a strong head always wins.

  • When two strong heads meet, the initiator wins.

  • When two weak heads meet, the initiator wins and becomes strong.

Moreover, if a non-head agent is strong, it becomes weak in the next interaction (Lines 70–73). Consider that two segments AA and BB face each other, i.e., their heads are neighboring. As long as both the segments survive, the number of strong non-heads in those segments is monotonically non-increasing and becomes zero within O(nlogn)O(n\log n) steps with probability 1O(1/n2)1-O(1/n^{2}). Then, once the head of a segment AA wins, the head of AA always wins thereafter until BB disappears. This event must occur during a sequence of interactions 𝑠𝑒𝑞R(0,n1)𝑠𝑒𝑞L(0,n1)\mathit{seq}_{R}(0,n-1)\cdot\mathit{seq}_{L}(0,n-1) occurs, which requires O(n2)O(n^{2}) steps with probability 1O(1/n2)1-O(1/n^{2}) by Lemma 2.3. Therefore, AA or BB disappears in O(n2)O(n^{2}) steps with probability 1O(1/n2)1-O(1/n^{2}). This means that the number of segments in the population decreases by half in each O(n2)O(n^{2}) steps with probability 1O(1/n2)1-O(1/n^{2}). In total, the number of segments becomes one, i.e., the ring orientation is done, in O(n2logn)O(n^{2}\log n) steps w.h.p.

By Lemma 2.4, we have the following theorem.

Theorem 5.2.

There is a self-stabilizing ring orientation (SS-RO) protocol that converges in O(n2logn)O(n^{2}\log n) steps both w.h.p. and in expectation and uses O(1)O(1) states per agent.

Acknowledgements.
This work was supported by JSPS KAKENHI Grant Numbers 19H04085, 20H04140, 20KK0232, 21K19770, and 22K11903.

References

  • (1)
  • Alistarh et al. (2017) Dan Alistarh, James Aspnes, David Eisenstat, Rati Gelashvili, and Ronald L Rivest. 2017. Time-space trade-offs in population protocols. In Proceedings of the Twenty-Eighth Annual ACM-SIAM Symposium on Discrete Algorithms. SIAM, 2560–2579.
  • Alistarh et al. (2022) Dan Alistarh, Joel Rybicki, and Sasha Voitovych. 2022. Near-Optimal Leader Election in Population Protocols on Graphs. In Proceedings of the 43rd ACM Symposium on Principles of Distributed Computing. 246–256.
  • Angluin et al. (2006) Dana Angluin, James Aspnes, Zoë Diamadi, Michael J. Fischer, and René Peralta. 2006. Computation in networks of passively mobile finite-state sensors. Distributed Computing 18, 4 (2006), 235–253.
  • Angluin et al. (2008a) Dana Angluin, James Aspnes, and David Eisenstat. 2008a. Fast computation by population protocols with a leader. Distributed Computing 21, 3 (2008), 183–199.
  • Angluin et al. (2008b) Dana. Angluin, J. Aspnes, Michael. J Fischer, and Hong. Jiang. 2008b. Self-stabilizing population protocols. ACM Transactions on Autonomous and Adaptive Systems 3, 4 (2008), 1–28.
  • Awerbuch and Ostrovsky (1994) Baruch Awerbuch and Rafail Ostrovsky. 1994. Memory-efficient and self-stabilizing network reset. In Proceedings of the thirteenth annual ACM symposium on Principles of distributed computing. 254–263.
  • Beauquier et al. (2013) Joffroy Beauquier, Peva Blanchard, and Janna Burman. 2013. Self-stabilizing leader election in population protocols over arbitrary communication graphs. In International Conference on Principles of Distributed Systems. 38–52.
  • Burman et al. (2021) Janna Burman, Ho-Lin Chen, Hsueh-Ping Chen, David Doty, Thomas Nowak, Eric Severson, and Chuan Xu. 2021. Time-optimal self-stabilizing leader election in population protocols. In Proceedings of the 2021 ACM Symposium on Principles of Distributed Computing. 33–44.
  • Cai et al. (2012) Shukai Cai, Taisuke Izumi, and Koichi Wada. 2012. How to prove impossibility under global fairness: On space complexity of self-stabilizing leader election on a population protocol model. Theory of Computing Systems 50, 3 (2012), 433–445.
  • Canepa and Potop-Butucaru (2007) Davide Canepa and Maria G. Potop-Butucaru. 2007. Stabilizing leader election in population protocols. http://hal.inria.fr/inria-00166632 (2007).
  • Chen and Chen (2019) Hsueh-Ping Chen and Ho-Lin Chen. 2019. Self-stabilizing leader election. In Proceedings of the 38th ACM Symposium on Principles of Distributed Computing. 53–59.
  • Chen and Chen (2020) Hsueh-Ping Chen and Ho-Lin Chen. 2020. Self-Stabilizing Leader Election in Regular Graphs. In Proceedings of the 39th ACM Symposium on Principles of Distributed Computing. 210–217.
  • Cordasco and Gargano (2017) Gennaro Cordasco and Luisa Gargano. 2017. Space-optimal proportion consensus with population protocols. In International Symposium on Stabilization, Safety, and Security of Distributed Systems. 384–398.
  • Dijkstra (1974) Edger W. Dijkstra. 1974. Self-stabilizing systems in spite of distributed control. Commun. ACM 17, 11 (1974), 643–644.
  • Fischer and Jiang (2006) Michael J. Fischer and Hong Jiang. 2006. Self-stabilizing Leader Election in Networks of Finite-State Anonymous Agents. In International Conference on Principles of Distributed Systems. 395–409.
  • Izumi (2015) Taisuke Izumi. 2015. On Space and Time Complexity of Loosely-Stabilizing Leader Election. In International Colloquium on Structural Information and Communication Complexity. 299–312.
  • Mertzios et al. (2014) George B Mertzios, Sotiris E Nikoletseas, Christoforos L Raptopoulos, and Paul G Spirakis. 2014. Determining majority in networks with local interactions and very small local memory. In International Colloquium on Automata, Languages, and Programming. 871–882.
  • Mitzenmacher and Upfal (2005) Michael Mitzenmacher and Eli Upfal. 2005. Probability and Computing: Randomized Algorithms and Probabilistic Analysis. Cambridge University Press.
  • Sudo et al. (2021a) Yuichi Sudo, Ryota Eguchi, Taisuke Izumi, and Toshimitsu Masuzawa. 2021a. Time-optimal Loosely-stabilizing Leader Election in Population Protocols. In 35nd International Symposium on Distributed Computing (DISC 2021). 40:1–40:17.
  • Sudo et al. (2016) Yuichi Sudo, Toshimitsu Masuzawa, Ajoy K Datta, and Lawrence L Larmore. 2016. The Same Speed Timer in Population Protocols. In the 36th IEEE International Conference on Distributed Computing Systems. 252–261.
  • Sudo et al. (2012) Yuichi Sudo, Junya Nakamura, Yukiko Yamauchi, Fukuhito Ooshita, Hirotsugu. Kakugawa, and Toshimitsu Masuzawa. 2012. Loosely-stabilizing leader election in a population protocol model. Theoretical Computer Science 444 (2012), 100–112.
  • Sudo et al. (2014) Yuichi Sudo, Fukuhito Ooshita, Hirotsugu Kakugawa, and Toshimitsu Masuzawa. 2014. Loosely-Stabilizing Leader Election on Arbitrary Graphs in Population Protocols. In International Conference on Principles of Distributed Systems. 339–354.
  • Sudo et al. (2020a) Yuichi Sudo, Fukuhito Ooshita, Hirotsugu Kakugawa, and Toshimitsu Masuzawa. 2020a. Loosely Stabilizing Leader Election on Arbitrary Graphs in Population Protocols without Identifiers or Random Numbers. IEICE Transactions on Information and Systems 103, 3 (2020), 489–499.
  • Sudo et al. (2018) Yuichi Sudo, Fukuhito Ooshita, Hirotsugu Kakugawa, Toshimitsu Masuzawa, Ajoy K Datta, and Lawrence L Larmore. 2018. Loosely-stabilizing leader election for arbitrary graphs in population protocol model. IEEE Transactions on Parallel and Distributed Systems 30, 6 (2018), 1359–1373.
  • Sudo et al. (2020b) Yuichi Sudo, Fukuhito Ooshita, Hirotsugu Kakugawa, Toshimitsu Masuzawa, Ajoy K Datta, and Lawrence L Larmore. 2020b. Loosely-stabilizing leader election with polylogarithmic convergence time. Theoretical Computer Science 806 (2020), 617–631.
  • Sudo et al. (2021b) Yuichi Sudo, Masahiro Shibata, Junya Nakamura, Yonghwan Kim, and Toshimitsu Masuzawa. 2021b. Self-stabilizing population protocols with global knowledge. IEEE Transactions on Parallel and Distributed Systems 32, 12 (2021), 3011–3023.
  • Thue (1912) Axel Thue. 1912. Uber die gegenseitige Lage gleicher Teile gewisser Zeichenreihen. Kra. Vidensk. Selsk. Skrifer, I. Mat. Nat. Kl. (1912), 1–67.
  • Yokota et al. (2021) Daisuke Yokota, Yuichi Sudo, and Toshimitsu Masuzawa. 2021. Time-optimal self-stabilizing leader election on rings in population protocols. IEICE Transactions on Fundamentals of Electronics, Communications and Computer Sciences 104, 12 (2021), 1675–1684.

Appendix A Chernoff Bounds

Lemma A.1 ((Mitzenmacher and Upfal, 2005), Theorems 4.4, 4.5).

Let X1,,XsX_{1},\dots,X_{s} be independent Poisson trials, and let X=i=1sXiX=\sum_{i=1}^{s}X_{i}. Then

(3) δ,0δ1:Pr(X(1+δ)𝐄[X])\displaystyle\forall\delta,~{}0\leq\delta\leq 1:~{}\Pr(X\geq(1+\delta)\mathbf{E}[X]) eδ2𝐄[X]/3,\displaystyle\leq e^{-\delta^{2}\mathbf{E}[X]/3},
(4) δ,0<δ<1:Pr(X(1δ)𝐄[X])\displaystyle\forall\delta,~{}0<\delta<1:~{}\Pr(X\leq(1-\delta)\mathbf{E}[X]) eδ2𝐄[X]/2.\displaystyle\leq e^{-\delta^{2}\mathbf{E}[X]/2}.