## 5 Proposed Dynamic Cluster Head Election Algorithm
### Proposed Optimum Cluster Head Election Method  
There is a set of well-known techniques used to select the appropriate cluster head (CH) of each cluster. To explain how the proposed algorithm works it will focus on a single cluster and then generalize the idea to multiple clusters. The pseudo-code presented in Algorithm 1 explains how the proposed method is working in a single cluster. After the network architecture is designed and its configuration is completed according to the assumptions (Section 4.3), the proposed protocol is implemented in the sink node gateway to select an optimum cluster head dynamically. The basic idea in the proposed method is to distribute the energy approximately equally among the cluster nodes in each round/cycle, along with the complexity of tracking the CHs by the attackers. At the beginning of each round/cycle, the corresponding SN elects the CH candidate randomly (just to determine the CH candidate priority; the election is not finished yet), then the CH candidate power is checked. If the CH candidate > zero, that meaning the CH is alive, the SN elects it as a current CH and informs the other nodes. Otherwise means the CH candidate is dead, therefore the CH candidate is skipped and the next node is checked periodically until the end round is reached, re-organizing the cluster after deleting dead nodes from the topology list as illustrated in Section 5.2. Accordingly, the regular nodes transmit their data/service to the current CH and, in turn, the current CH transmits the collected data/service to the corresponding SN. After the CH is elected, the SN makes another check to ensure whether the current CH is the last node in this round/cycle or not; that happens when the next node (during the periodic checking) is itself the CH candidate that was elected randomly at beginning of the first round. If the current CH is not the last one in the round, the next CH candidate is checked periodically. Otherwise, it means the first round is finished, and the SN elects the CH candidate for the next round randomly, etc. Figure 5 shows the proposed Optimum Cluster Head Election method's data flow diagram, which illustrates all the idea mentioned above, and how this method works. Testing the residual energy of the CH candidate with a specific threshold is one of the common solutions. However, the process of testing these near-death nodes is a waste of time and energy, due to the additional control messages in repetitive testing in each round/cycle for useless nodes if they are not deleted from the topology list, which opens the door for further research to address these challenges effectively. Therefore, this issue is considered as a future work, as mentioned in Section 7. Note that the proposed Optimum Cluster Head Election Method lifts from the regular nodes the processes of selecting the next CH node, and the process of notifying the rest of the cluster nodes about the elected CH. Instead, all previous functions were assigned to the rechargeable SN nodes. Contrary to most of the previous studies where the cluster nodes participate in selecting the next CH node and then notify the rest of the cluster nodes to fulfill these roles in these models, cluster nodes keep all the information of the topology list, which leads to a significant and effective drain on cluster nodes' energy. In short, the main new ideas of the proposed method can be summarized as follows:  
(i) Introduce a new random method to elect a CH candidate; the new method checks the remaining energy for the CH candidate (not the CH itself) which is elected randomly (at the beginning of each round/cycle) to overcome the problems of the black holes. This is contrary to the common random method, which elects the CH randomly and blindly. (ii) Furthermore, the idea behind using the random election method at the beginning of each round is to strengthen the security side and complexity of tracking the CHs by the attackers.