Leader Election in a Ring

CS6100: Topics in Design and
Analysis of Algorithms
Leader Election in a Ring
John Augustine
CS6100 (Even 2012): Leader Election in a Ring
Leader Election in a Ring
Problem Definition: Given n nodes connected to
form a single cycle, we must execute an algorithm
to ensure that a single node should decide to be the
leader.
• Can also expect others to know who the leader is.
• Ring can be uni or bi directional.
• n may or may not be known.
• Processors typically have unique id.
Theorem 1. In an n node ring formed by identical
nodes, there is no algorithm that solves leader
election.
CS6100 (Even 2012): Leader Election in a Ring
1
Le Lann, Chang, and Roberts (LCR)
Each node sends its
(unidirectional) ring1.
unique
id
around
the
When a node receives an id, it passes it along if its
own id is less than the id it received.
When a node receives its own id, it set itself to be the
leader.
Theorem 2. LCR algorithm solves leader election
correctly in n rounds and O(n2) messages.
How can we improve the message complexity?
1
If the ring is bidirectional, then we fix a direction and use only that fixed
direction.
CS6100 (Even 2012): Leader Election in a Ring
2
Hirschberg and Sinclair (HS) Algorithm
This algorithm works in phases 0, 1, 2, . . . , O(log n) in
a bidirectional ring.
Let ui be the id of node i.
In phase `, each node i sends its id in a token out to
a distance 2` that then returns to node i.
If node i does not receive both its tokens back in phase
`, it does not send out its id any more.
In phase `, if a node j receives node i’s token and
ui < uj , node j discards the token and does not pass
it along any more.
If ui = uj , then node j elects itself leader and sends a
final round of messages informing every other node of
its leader status.
CS6100 (Even 2012): Leader Election in a Ring
3
Message Complexity of HS Algorithm
Consider any winner w that survives to phase `. At
least 2`−1 + 1 nodes on, say, its counterclockwise side
do not survive to phase ` and can be accounted against
w.
Therefore, the number of winners in phase ` is at most
n
2`−1 + 1
.
Each winner’s tokens account for 4 · 2` messages.
Therefore, total number of messages in phase ` is
4 · 2` ·
n
2`−1
+1
≤ 8n.
Since the total number of phases is O(log n), the
message complexity is O(n log n).
CS6100 (Even 2012): Leader Election in a Ring
4
Time Complexity
Each phase ` requires 2 · 2` = 2`+1 rounds.
The last but one phase requires 2O(log n) = O(n)
rounds and the last round requires n rounds.
Therefore, total number of rounds is
2 + 4 + 8 + · · · + O(n) + n = O(n).
CS6100 (Even 2012): Leader Election in a Ring
5
The TimeSlice Algorithm
Each phase ` has n rounds.
Starting from phase 1, in each phase `, a node sends
out a token (in one direction) if its own id is `.
If it receives its own token, then it elects itself leader
and sends out another token informing every other
node of its leader status.
The node with smallest id is eventually elected leader.
Message complexity is O(n), but time can be quite
large if unique ids are chosen (say uniformly) from a
large range.
CS6100 (Even 2012): Leader Election in a Ring
6
The VariableSpeeds Algorithm
Each node with uid v sends out its token that travels
at the rate of 1 hop for every 2v rounds. If the token
encounters a node with a smaller id, it stops. If a token
returns to its sender, the sender elects itself leader.
Again, the node with minimum id is elected leader. Its
token travels n hops.
The next smallest makes at most n/2 hops.
The kth smallest makes n/2k−1 hops.
Therefore, total message complexity is at most 2n.
The time complexity is n · 2umin .
CS6100 (Even 2012): Leader Election in a Ring
7
Sketch of Lower Bound for
Comparison-Based Algorithms
Every node has the same start state except for its
unique uid.
Nodes can (i) copy, (ii)send/receive, and (iii) compare
kids. Nothing else.
Two (non-repeating) sequences U = (u1, u2, . . . , uk )
and V = (v1, v2, . . . , vk ) are order equivalent if, ∀i, j,
ui ≤ uj iff vi ≤ vj . I.e., their corresponding sequences
of relative ranks are identical.
Two states s and t are said to correspond with each
other if the id’s the contain are order equivalent.
The k-neighbourhood of node is the 2k + 1 nodes
nearest to it (including itself).
Lemma 3. If the uid’s in the k-neighbourhoods of
two nodes i and j are order equivalent, then, after k
(active) rounds, the states of i and j correspond.
CS6100 (Even 2012): Leader Election in a Ring
8
We want to show that rings can have a large amount
of symmetry that are difficult to break.
Let c be a constant in [0, 1] and R be a ring
√ of size n.
R is said to be c-symmetric if for every `, n ≤ ` ≤ n,
and every
cn segment S of length ` in R, there are at
least ` segments in R that are order equivalent to
S (counting S as well).
For n = 2k , it is easy to construct a 1/2 − symmetric
ring. Number nodes in order from 0 to n − 1 and then
use the reverse order of bits as kids. But we need
something more general.
Theorem 4. ∃ c such that for all n, there is a csymmetric ring of size n.
Theorem 5. For any comparison based leader
election algorithm A, there is an execution that
requires Ω(n log n) messages to be sent before the
leader is elected.
CS6100 (Even 2012): Leader Election in a Ring
9