Skip to content
SEE Exam Prep

Question 9 of 15 · CIE-1 QB · 7 marks

Open in ChatGPT

What are Election Algorithms? Explain the Bully algorithm with a suitable example.


Introduction

An election algorithm picks a coordinator when the current one fails. The bully algorithm assumes every process has a unique priority (the highest numbered process wins) and that every process can reach every other, so no ring is needed.

Algorithm

  1. A process P notices the coordinator is not responding and starts an election by sending ELECTION to every process with a higher id.
  2. If no one answers within a timeout, P declares itself coordinator and sends COORDINATOR to all processes with lower ids.
  3. If a higher process answers, P waits: the higher process runs the election instead.
  4. A process that receives ELECTION sends ELECTION to all processes higher than itself, and returns OK to the sender.
  5. The highest id that receives no higher reply becomes coordinator and announces itself.

Diagram

ELECTIONELECTIONOKOKELECTION (no reply)COORDINATOR (5)COORDINATOR (5)coordinator 7 failstimeout, 5 is coordinatorP2P3P5P7P2P3P5P7

Example

  • Processes 2, 3, 5, 7 with coordinator 7. When 7 fails, 2 sends ELECTION to 3, 5 and 7.
  • 3 and 5 reply OK, so 2 stands down.
  • 5 sends ELECTION to 7 and gets no reply.
  • After its timeout, 5 declares itself coordinator and tells 2 and 3.

Complexity

  • Best case: n − 2 messages (the second-highest process wins immediately).
  • Worst case: O(n²) messages, when the lowest process starts the election.
  • Time: at most n timeouts.

Bully vs ring

Point Bully Ring
Topology needed Full connectivity Logical ring
Messages O(n²) worst case 2n always
Failure detection Timeout per candidate Ring traversal
Winner Highest id Highest id in the ring

Conclusion

The bully algorithm is fast when the second-highest process notices the failure first and quadratic when the lowest one does, which is why it suits small, fully connected clusters.