The K-Means algorithm does not run forever. It stops when any one of the following conditions is met:
✅ 1. Centroids Do Not Change
- If the centroids remain the same even after multiple iterations,
- It means the algorithm has converged.
✅ 2. Points Remain in the Same Cluster
- If no data point changes its cluster membership,
- The clusters are considered stable.
✅ 3. Maximum Number of Iterations Is Reached
- A maximum limit (e.g., 100 iterations) is set in advance.
- Once this limit is reached, the algorithm stops automatically.
