## 3 Proposed Method
### Algorithms for Sensor Nodes
```
1:if node role = cluster head then
2: determine probabilities \(p_{i}\) based on event counter
3: determine \(TCH_{i}\) using method presented in Section 3.2
4:if duty time >= \(TCH_{i}\)then
5: CH address = next address in sequence
6: node role = cluster member
7:endif
8: broadcast sync frame
9: put communication module to sleep (sleep time)
10:else
11: listen to sync frame (wait time)
12:if sync frame received then
13:if CH address = own address then
14: node role = cluster head
15: duty time = 0
16:endif
17: put communication module to sleep (sleep time)
18:else
19: begin node initialization procedure
20:endif
21:endif
22:step = 0
```  
**Algorithm 3** Cluster-head selection  
The algorithm of sensor node initialization (Algorithm 4) is executed every time a sensor node starts to operate as well as when CH node is no longer present, e.g., due to malfunction or battery depletion. The initialized sensor node waits for sync frame. If the sync frame is received, the sensor node joins the WSN cluster as cluster member. In opposite situation, when sync frame is not received, the node takes the CH role. It should be noted that the sync frame includes information about current step of cluster operation. The CH node broadcasts the sync frame periodically, as shown in Algorithm 2 (line 4). Thus, a sensor node can join the cluster at any time, e.g., after its recovery. During initialization, the wait time, i.e., time when sensor node waits for the sync frame, is different for each node. The wait time (sync wait time) depends on address of the node (see line 2 in Algorithm 4). This prevents the situation when many neighboring sensor nodes take the CH role at the same time. An example of WSN cluster initialization is presented in Figure 2. In this example sensor nodes 1 and 2 are initialized at the same time and want to join the WSN cluster. Initially, the CH node is not present, thus node 1 does not receive sync frame during its wait time, and becomes the CH. As node 1 takes the CH role, it starts broadcasting sync frames. One of such frames is received by node 2, which then join the cluster as cluster member. Similarly, the 3 rd sensor node, which starts its operation later than the other nodes, acts as cluster member after receiving the sync frame. The most computationally complex operation in the proposed approach is to solve the system of linear equations in Algorithm 3 (line 3). In this work, this operation was performed by using the exact algorithm presented in [31], with complexity of \(\mathcal{O}(N^{3})\), where \(N\) is number of cluster members. As explained above, the computational complexity can be reduced by implementing heuristic or approximate algorithms to solve the equation system. Moreover, this computationally demanding operation can be effectively performed by the base station (sink) for larger clusters. The remaining operations of the proposed algorithms have linear complexity (\(\mathcal{O}(N)\)). ```
1:wake communication module up
2:sync wait time = delay * address
3: listen to sync frame (sync wait time)
4:if sync frame received then
5: role = cluster member
6: step = step determined in sync frame
7:else
8: role = cluster head
9: step = 0
10: duty time = 0
11:endif
12: put communication module to sleep (sleepTime)
```  
**Algorithm 4** Initialization of sensor node