## 4 Proposed Approach
### Cluster Head Election Phase  
The pseudo-code of the clustering process is presented in Algorithm 2. We assume that no potential failure occurs during the execution of the CHs election phase. First, to elect a cluster head, a node \(i\) browses the \(CRL_{i}\) list and compares its weight with the weight of its neighbors and with the weight of CHs that dominate its neighbors (rule \(R1\)). If \(W_{i}\) is the greatest weight, \(i\) updates \(Mych_{i}=1D_{i}\) (elect itself as a cluster head) and set \(Dist(i,Mych_{i})=0\) (execute \(R2\)), then broadcasts a \(CH\_Announcement\) beacon that contains the new CH information. Otherwise, \(i\) chooses the node with the highest weight value in \(CRL_{i}\) list as its new CH. In the case where two or more nodes have the same highest weight, the node identifier is used as a tie-breaker, i.e., the device that has the highest \(ID\) is elected as CH. Rule \(R1\) prevents the formation of poorly structured clusters, it allows network nodes to choose the most appropriate cluster head in their k-hop neighborhood. Otherwise, the node chooses the second weightiest node in \(CRL_{i}\) and so on until finding the weightiest CH with less than \(k\) hops of distance. If no \(CH\) meets these requirements, then the current node elects itself as a new CH to avoid isolated node scenario. Node \(i\) updates \(Mych_{i}\) with the identifier of the chosen node from (R1) and selects the path with the minimum number of hops toward the CH according to the information received from its one hop neighborhood (using rule (R3)). Consequently, nodes will be constrained to join the closest cluster that includes the weightiest CH, which prevents the formation of a height number of small clusters. The cluster heads election process is illustrated in Figure 5.  
```
Code for each node \(i\) Variables: \(ID_{i}\): identifier \(N(i)\): set of neighbors node of \(i\) \(W_{i}\): weight of the node \(i\) \(Max\_weight\): temporary variable used to find the node with the highest weight Output \(CRL_{i}\): clustering record list of \(i\) \(Mych_{i}\): the relative CH of \(i\) \(Dist(i,Mych_{i})\): the minimal distance between \(i\) and its relative CH (in term of hop) (R1): If \(Max\_weight\
eq Max(\{CRL[ID_{j}][W]\mid j\in(N(i)\lor Mych_{N(i)})\wedge Dist (j,Mych_{j})<k\}\bigcup\{W_{i}\})\)then \(Max\_weight=Max(\{CRL[ID_{j}][W]\mid j\in(N(i)\lor Mych_{N(i)})\wedge Dist (j,Mych_{j})<k\}\bigcup\{W_{i}\})\) \(Mych_{i}=ID_{j}\) Else If \(i\
eq j\wedge W_{i}=W_{i}\)then If \(ID_{i}\geq ID_{j}\) \(Mych_{i}=ID_{i}\) Else \(Mych_{i}=ID_{j}\) \(Mych_{i}=ID_{j}\) \(Mych_{i}=ID_{i}\) Else \(Mych_{i}=ID_{j}\) (R2): If \((Mych_{i}=ID_{i})\wedge CRL[Mych_{i}][Dist_{i}]\
eq 0\)then \(Dist(i,Mych_{i})=0\) \(CRL[Mych_{i}][Dist_{i}]=0\)  Broadcast \(CH\_Announcement\) beacon (R3): If \((Mych_{i}\
eq ID_{i})\wedge(Dist(i,Mych_{i})\
eq Min(Dist(j,Mych_{j})\mid j\in N (i)\wedge Mych_{i}=Mych_{j})+1)\)then \(Dist(i,Mych_{i})=Min(Dist(j,Mych_{i})\mid j\in N(i)\wedge Mych_{i}=Mych_{j})+1\) \(CRL[Mych_{i}][Dist_{i}]=Dist(i,Mych_{i})\)
```  
**Algorithm 2** Cluster Head election phase. Figure 6 shows an execution scenario of the clustering process with \(k=2\) in a small network (modeled by a graph). Green nodes represent the CHs and the white nodes represent the cluster members. Tables (b,d,f,h) in Figure 6 show the different nodes parameter. Figure 6a,g present, respectively, the initial network state and the final clustered network. Initially, network nodes have received the signal message from the BS and exchanged their clustering information. At each stage, the variables of each node used during the clustering are illustrated in the corresponding matrix. Notice in Figure 6a, the weight of nodes 1 and 11 are the highest among all the nodes in their \(CRL\) lists. During the following round (Figure 6c) these two nodes execute rule \(R1\) to update their \(Mych\) value (became CHs) and rule \(R2\) to update the distance \(Dist(i,Mych_{i})=0\). Next, nodes 1 and 11 send an announcement beacon to their neighbors.