## 4 Design of a Capacity-Constrained Weighted Clustering Algorithm
### CH and BCH Node Selection
Assuming that the node transmission power is the same and the maximum communication distance is the same, the average distance factor of the node can be normalized and expressed [34] as follows:  
\[f_{E_{i}}=\frac{E_{ir}}{E_{i}} \tag{3}\]3  
where \((x_{i},y_{i},z_{i})\) and \((x_{j},y_{j},z_{j})\) represent the three-dimensional position information of nodes \(i\) and \(j\), respectively, and \(D_{\max}\) is the maximum distance between nodes within the partition. In summary, after calculating the five cluster head selection factors, the clustering weight values of the candidate cluster head nodes are obtained through a weighting method. The node with the smallest weight value is selected as the cluster head node, and the node with the second smallest weight value is selected as the backup cluster head node. In case of equal weight values, the node connectivity is compared. The weight value calculation method is expressed as follows:  
\[f_{E_{i}}=\frac{E_{ir}}{E_{i}} \tag{3}\]4  
where, \(W_{i}\) represents the weight value of node \(i\) in the cluster head selection process, and \(\varepsilon_{1}\), \(\varepsilon_{2}\), \(\varepsilon_{3}\), \(\varepsilon_{4}\) and \(\varepsilon_{5}\) are the weight coefficients of the five cluster head selection factors, which must satisfy \(\varepsilon_{1}+\varepsilon_{2}+\varepsilon_{3}+\varepsilon_{4}+\varepsilon_ {5}=1\). These coefficients can be dynamically selected based on the network environment. The pseudocode of the cluster head and backup cluster head selection algorithm is listed in Algorithm 2. ```
Input: Partition set \(P=\{partition_{1},\,partition_{2},\ldots,\,partition_{numClusters}\}\), node information nodes, number of partitions numClusters Output: CHs and BCHs for each cluster \(S_{CH}\)= \(\{CH_{1},\,CH_{2},\,\ldots,\,CH_{numClusters}\}\), \(S_{BCH}\) = \(\{BCH_{1},\,BCH_{2},\,\ldots,\,BCH_{numClusters}\}\) //Calculate node weights 1 for\(k\)= \(1\) to numClustersdo 2 for\(i\in partition_{k}\)do 3 Calculate the cluster head selection factors by nodes Calculate the weight \(W_{i}\) endfor //Select CHs and BCHs based on weights for\(k\)= \(1\) to numClustersdo 8 Nodes within the partition are sorted in descending order of weight \(CH_{k}\) = number of the node with the minimum weight \(BCH_{k}\) = number of the node with the second smallest weight \(11\) if there are nodes with the same weight do 12 Compare connectivity and select those with high connectivity \(13\) end if 14 endfor return\(S_{CH}\) = \(\{CH_{1},\,CH_{2},\,\ldots,\,CH_{numClusters}\}\), \(S_{BCH}\) = \(\{BCH_{1},\,BCH_{2},\ldots,\,BCH_{numClusters}\}\)
```  
**Algorithm 2** Anti-interference weighted selection algorithm for CHs and BCHs  
In Algorithm 2, the analysis of time and space complexity is mainly divided into two stages: the node weights calculation stage and the CHs/BCHs selection stage. In the node weights calculation stage, it is necessary to calculate the weight of each node in each cluster, with a total of \(k\) clusters and \(n\) nodes. The time complexity is \(O(n)\). In terms of space, it is necessary to maintain a weight array, so the space complexity is \(O(n)\). In the CHs/BCHs selection stage, it is necessary to sort the nodes within each cluster by weight. When the number of nodes in each cluster is approximately \(\frac{n}{k}\), the time complexity can be expressed as \(O(n\log(\frac{n}{k}))\). In terms of space, it is necessary to maintain sorting index arrays, cluster center arrays, and backup cluster center arrays. Therefore, the spatial complexity of this stage can be expressed as \(O(n)+O(k)+O(k)=O(n+k)\). Overall, for the anti-interference weighted selection algorithm for CHs and BCHs, the time complexity is \(O(n)+O(n\log(\frac{n}{k}))=O(n\log(\frac{n}{k}))\), and the space complexity is \(O(n)+O(n+k)=O(n+k)\).