| Algorithm 3. Pseudo-code of the Swap Phase |
| 1. repeat |
| 2. for i := 1 → N do /* Perform Clustering */ |
| 3. for j := 1 → K do |
| 4. Find Euclidean distance b/w Xi and Mj |
| 5. Tag Xi with j for which this distance is minimum |
| 6. endfor |
| 7. endfor |
| 8. for j := 1 → K do /* Find Minimum Sum (For Each Cluster)*/ |
| 9. for each data point Xa ϵ cluster j do |
| 10. for each data point Xi ϵ cluster j do |
| 11. Find sum of Euclidean distances b/w Xa and Xi |
| 12. endfor |
| 13. Find minimum sum |
| 14. endfor |
| 15. Update Xa as jth Medoid for which the sum is minimum /* Update Medoid*/ |
| 16. endfor |
| 17. until no update in any of ‘K’ Medoids |