Lecture-03. Leader Election
Lecture-03. Leader Election
Rajiv Misra
Dept. of Computer Science & Engineering
Indian Institute of Technology Patna
[email protected]
Preface
• Each processor has a set of elected (won) and not-elected (lost) states.
• Once an elected state is entered, processor is always in an elected state
(and similarly for not-elected): i.e., irreversible decision
• In every admissible execution:
• every processor eventually enters either an elected or a not-elected
state
• exactly one processor (the leader) enters an elected state
Uses of Leader Election
• A uniform algorithm does not use the ring size (same algorithm for each
size ring)
• Formally, every processor in every size ring is modeled with the same
state machine
• A non-uniform algorithm uses the ring size (different algorithm for each
size ring)
• Formally, for each value of n, every processor in a ring of size n is
modeled with the same state machine An .
• Note the lack of unique ids.
Leader Election in Anonymous Rings
Theorem: There is no leader election algorithm for anonymous rings, even if
algorithm knows the ring size (non-uniform) and synchronous model
Proof Sketch:
• Every processor begins in same state with same outgoing messages (since
anonymous)
• Every processor receives same messages, does same state transition, and
sends same messages in round 1
• Ditto for rounds 2, 3, …
• Eventually some processor is supposed to enter an elected state.
But then they all would.
Leader Election in Anonymous Rings
• Proof sketch shows that either safety (never elect more than one
leader) or liveness (eventually elect at least one leader) is violated.
• Since the theorem was proved for non-uniform and synchronous rings,
the same result holds for weaker (less well-behaved) models:
• uniform
• asynchronous
Rings with Identifiers
id = 37
id = 3
p4 p0
p1 id = 19
p3
id = 25 p2
id = 4
• Uniform algorithm: there is one state machine for every id, no matter
what size ring
• Non-uniform algorithm: there is one state machine for every id and
every different ring size
• These definitions are tailored for leader election in a ring.
O(n2) Messages LE Algorithm:
LeLann-Chang-Roberts (LCR) algorithm
• The correctness of the algorithm follows in the same manner as in the simple
algorithm, because they have the same swallowing rules.
• It is clear that the probes of the processor with the maximal identifier are
never swallowed; therefore, this processor will terminate the algorithm as a
leader. On the other hand, it is also clear that no other <probe> can traverse
the whole ring without being swallowed. Therefore, the processor with the
maximal identifier is the only leader elected by the algorithm.
O(n log n) Leader Election Algorithm
pi
probe probe
reply reply
Correctness:
• Similar to O(n2) algorithm.
Message Complexity:
• Each message belongs to a particular phase and is initiated by a
particular processor
• Probe distance in phase k is 2k
• Number of messages initiated by a processor in phase k is at most
4*2k (probes and replies in both directions)
Analysis of O(n log n) Leader Election Algorithm
2k-1 processors
… a phase
k-1 winner … a phase
k-1 winner
…
log(n–1)+1
phase 0 msgs
≤ 4n + n + 4•2k•n/(2k-1+1)
k=1
termination
msgs < 8n(log n + 2) + 5n
msgs for
phases 1 to
= O(n log n) log(n–1)+1
Can We Do Better?
• The O(n log n) algorithm is more complicated than the O(n2) algorithm
but uses fewer messages in worst case.
• Works in both synchronous and asynchronous case.
• Can we reduce the number of messages even more?
• Not in the asynchronous model…
Lower bound for LE algorithm
But, can we do better than O(n log n)?
Theorem: Any leader election algorithm for asynchronous rings
whose size is not known a priori has ῼ(n log n) message
complexity (holds also for unidirectional rings).
• Both LCR and HS are comparison-based algorithms, i.e. they
use the identifiers only for comparisons (<; >;=).
• In synchronous networks, O(n) message complexity can be
achieved if general arithmetic operations are permitted (non-
comparison based) and if time complexity is unbounded.
Overview of LE in Rings with Ids
• synchronous ring:
• (n) messages under certain conditions
• otherwise (n log n) messages