## 8 Discussion  
Implementing the K-Nearest Neighbours algorithm in Wireless Sensor Network protocols has significantly improved energy efficiency and network lifetime. This study focused on the modification of four protocols: LEACH, SEP, TEEN, and DEC, using the KNN algorithm to optimise cluster head (CH) selection and clustering mechanisms. The results of the MATLAB simulations provide a comprehensive view of the benefits achieved by this approach. The modified protocols, LEACH-KNN, SEP-KNN, TEEN-KNN, and DEC-KNN, showed a significant reduction in energy consumption compared to their original versions, as follows: the LEACH-KNN reduction is 14.1%, the SEP-KNN reduction is 15.6%, the TEEN-KNN reduction is 18%, and the DEC-KNN reduction is 22.7%. This reduction is attributed to the optimised selection of cluster heads, which minimises the data transmission distance and balances the energy load across the network. The proposed approach optimises CHs, resulting in a more efficient clustering structure, with fewer cluster heads required to cover the network area. The number of cluster heads was reduced by 46.7% in LEACH-KNN, 56.3% in SEP-KNN, 64.3% in TEEN-KNN, and 64.7% in DEC-KNN. This reduction reduces the energy consumption associated with maintaining multiple cluster heads and reduces the likelihood of overlapping clusters, which can lead to data redundancy and increased energy consumption. The sum of the distance between the cluster heads and the base station in the four modified protocols was significantly reduced compared to the original protocols, improving the connectivity of the network and reducing the energy required for data transmission. The average distance between CHs and the base station was reduced by 49.1% in LEACH-KNN, 66.3% in SEP-KNN, 73.7% in TEEN-KNN, and 65.9% in DEC-KNN. The proposed approach significantly increased the stability and lifetime of the network, and the LSD metrics were improved in each modified protocol, representing more extended operation time in both the first and the last nodes when the energy is completely exhausted. With these improvements and modifications, the KNN-based approach effectively extends the operational lifetime of the network, allowing for more extended data collection and transmission. Although our work is mainly focused on static WSN configurations, integrating the KNN algorithm into WSN protocols (LEACH, SEP, TEEN, DEC) shows that the proposed approach could be effectively adapted to dynamic topologies and varying traffic loads by addressing key energy efficiency, clustering optimisation, and network lifetime challenges. For changing topologies, KNN ensures that CHs are selected based on proximity, energy levels, and distance to the base station, dynamically adapting to node failures or removing dead nodes, and that clustering recalibrates in each round. KNN also prioritises nodes with \begin{table}
\begin{tabular}{c c c c c c c} \hline \hline \multirow{2}{*}{**Protocol**} & \multirow{2}{*}{**FSD**} & \multirow{2}{*}{**PSA**} & \multirow{2}{*}{**LSD**} & \multicolumn{3}{c}{**Improvement of the**} \\  & & & & & **KNN Approach** \\ \cline{5-6}  & & & & **FSD** & **PSA** & **LSD** \\ \hline LEACH & 2230 & 2301 & 3219 & \multirow{2}{*}{12.69\%} & \multirow{2}{*}{8.36\%} & \multirow{2}{*}{9.25\%} \\ LEACH-KNN & 2554 & 2511 & 3547 & & & \\ \hline SEP & 2065 & 2107 & 3217 & \multirow{2}{*}{12.50\%} & \multirow{2}{*}{15.31\%} & \multirow{2}{*}{8.94\%} \\ SEP-KNN & 2360 & 2488 & 3533 & & & \\ \hline TEEN & 1761 & 1803 & 3049 & \multirow{2}{*}{21.35\%} & \multirow{2}{*}{23.80\%} & \multirow{2}{*}{5.34\%} \\ TEEN-KNN & 2239 & 2366 & 3221 & & & \\ \hline DEC & 2321 & 2471 & 3510 & \multirow{2}{*}{12.12\%} & \multirow{2}{*}{9.59\%} & \multirow{2}{*}{5.82\%} \\ DEC-KNN & 2641 & 2733 & 3727 & & & \\ \hline \hline \end{tabular}
\end{table} 
Table 5: Performance metrics of the networks’ stabilities and lifetimes.