1. Candidate CH broadcasts a competition message |

COMPETE_CH(, ., ); |

2. On receiving a COMPETE_CH from ; |

3. **if** () **then** |

4. ; |

5. generates test sequence number and the test task |

6. broadcasts a TEST_REQ(); |

7. On receiving a TEST_REQ() from ; |

8. generates the test result () for task ; |

9. broadcasts the Test_RES() to ; |

10. On receiving a TEST_RES from initiated by |

11. **if** () **then** |

12. * ***if** (() = ()) **then** |

13. *← *; |

14. *← *; |

15. **else if** () **then** |

16. **if** (() = ()) **then** |

17. *← *; |

18. ; |

19. ) |

20. **if** ( has received a TEST_RES from |

and () = ()) **then** |

21. *← *; |

22. **else if** ( received a TEST_RES from |

* * and () *≠ *() and ) **then** |

23. *← *; |

24. **else** store the test response; |

25. **if** () **then **.state *←finalCH*; |

26. **while** (.state = ) |

27. **if** ( and ) **then** |

28. broadcast FINAL_CH(); |

29. *←finalCH*; |

30. On receiving a FINAL_CH from ; |

31. **if** () **then** |

32. broadcast QUIT_ELECT(); |

33. .*←RegularNode*; |

34. On receiving a QUIT_ELECT from |

35. **if** () **then** |

36. remove from .; |

37. **end while** |