K-Means Clustering Worked Example: Assign Points and Recompute Centroids
Follow six points through three assignment passes, recompute both centroids exactly, and see why one point switches clusters before k-means converges.
KnowledgeGate Team
Exam prep & CS education

K-means repeats two operations: assign every point to its nearest centroid, then recompute each centroid from its assigned points. The arithmetic becomes error-prone when one table uses old centroids and the next uses new ones. Across three fixed-centroid passes, point C changes clusters before the assignments stabilise. Squared Euclidean distance keeps unnecessary square roots out of every comparison.
K-means clustering: the assignment-update loop
K-means takes a set of points x_i, a chosen number of clusters K, and one centroid for each cluster, written mu_1,...,mu_K. Here, K=2. During an assignment step, each point goes to the centroid with the smallest squared Euclidean distance:
|| x-mu_k||^2=(x_1-mu_k1)^2+(x_2-mu_k2)^2.
During the update step, each centroid is replaced by the coordinate-wise arithmetic mean of all points assigned to its cluster. With centroids fixed, assignment chooses the smallest contribution to the squared-error objective for every point. With assignments fixed, the mean minimises the within-cluster squared error.
A precise stopping rule completes a fresh assignment pass with one fixed pair of centroids. If no point changes cluster, recomputing the means returns the same centroids, so the run has converged. Unsupervised Learning and Clustering Explained: K-Means Worked Example and Exam Traps owns feature representation, scaling, distance choices and comparisons among clustering algorithms. This calculation instead follows three complete K-means passes, the point that switches clusters and the final inertia.
K-means worked dataset and initial centroids
The point labels are:
Point | Coordinates |
|---|---|
A | (1,1) |
B | (2,1) |
C | (3,2) |
D | (8,8) |
E | (9,8) |
F | (10,9) |
Start with mu_1^(0)=A=(1,1) and mu_2^(0)=C=(3,2). Seeding both centroids on the left makes the reassignment visible, but it is not a recommended initialisation rule.
Each point and centroid is a two-component vector. Linear Algebra for GATE CS refreshes the vector, coordinate and distance foundations used here.

First assignment and centroid recomputation
Calculate both squared distances before assigning any point. Comparing squared distances gives the same nearest centroid as comparing their square roots because square root is an increasing function.
Point | d_1^2 to mu_1^(0) | d_2^2 to mu_2^(0) | Assignment |
|---|---|---|---|
A | 0 | 5 | Cluster 1 |
B | 1 | 2 | Cluster 1 |
C | 5 | 0 | Cluster 2 |
D | 98 | 61 | Cluster 2 |
E | 113 | 72 | Cluster 2 |
F | 145 | 98 | Cluster 2 |
The first sets are C_1^(0)={A,B} and C_2^(0)={C,D,E,F}. Now average each coordinate within its complete set:
mu_1^(1)=((1+2)/2,(1+1)/2)=(1.5,1),
mu_2^(1)=((3+8+9+10)/4,(2+8+8+9)/4)=(7.5,6.75).
The sum of squared errors, or SSE, checks what this update achieved. At the initial centroids, with the first assignments, it is
0+1+0+61+72+98=232.
Hold those assignments fixed but use the new means. The six contributions become 0.25, 0.25, 42.8125, 1.8125, 3.8125, 11.3125, giving
0.25+0.25+42.8125+1.8125+3.8125+11.3125=60.25.
This comparison does not yet reassign any point. It shows why the mean is the correct update for fixed clusters.
Second assignment, final centroids, and convergence
Use only mu_1^(1)=(1.5,1) and mu_2^(1)=(7.5,6.75) for the full second pass:
Point | d_1^2 | d_2^2 | Assignment |
|---|---|---|---|
A | 0.25 | 75.3125 | Cluster 1 |
B | 0.25 | 63.3125 | Cluster 1 |
C | 3.25 | 42.8125 | Cluster 1 |
D | 91.25 | 1.8125 | Cluster 2 |
E | 105.25 | 3.8125 | Cluster 2 |
F | 136.25 | 11.3125 | Cluster 2 |
Only C switches, moving from cluster 2 to cluster 1 because 3.25<42.8125. The new sets are C_1^(1)={A,B,C} and C_2^(1)={D,E,F}. Their means are
mu_1^(2)=((1+2+3)/3,(1+1+2)/3)=(2,4/3) approx (2,1.33),
mu_2^(2)=((8+9+10)/3,(8+8+9)/3)=(9,25/3) approx (9,8.33).
One more complete assignment pass is necessary. Keeping the fractions exact gives:
Point | d_1^2 to mu_1^(2) | d_2^2 to mu_2^(2) | Assignment |
|---|---|---|---|
A | 10/9 | 1060/9 | Cluster 1 |
B | 1/9 | 925/9 | Cluster 1 |
C | 13/9 | 685/9 | Cluster 1 |
D | 724/9 | 10/9 | Cluster 2 |
E | 841/9 | 1/9 | Cluster 2 |
F | 1105/9 | 13/9 | Cluster 2 |
The sets remain {A,B,C} and {D,E,F}. Their coordinate means therefore remain unchanged, and the run stops.

K-means inertia after convergence
Inertia is the within-cluster SSE, the sum of every point's squared distance from its assigned centroid. For final cluster 1, it is
10/9+1/9+13/9=8/3.
Final cluster 2 has the same contribution, 10/9+1/9+13/9=8/3. The final inertia is therefore 16/3, approximately 5.33.
The checkpoints are 232 at the chosen initial centroids and first assignments, 60.25 after the first mean update with those assignments fixed, and 16/3 after C switches and both clusters are updated. The objective improves monotonically in this run, but that does not prove a global optimum. Different seeds can reach different local solutions. Multiple starts and k-means++ reduce poor-seed risk, while choosing K, perhaps with elbow or silhouette analysis, remains a separate modelling decision.
K-means calculation traps
Most hand-calculation errors come from mixing states or updating too soon.
Trap | Reliable fix |
|---|---|
Mixing centroids from different passes | Write an iteration superscript on every centroid. |
Updating before all points are assigned | Complete each assignment pass synchronously. |
Averaging old centroids | Sum the assigned points and divide each coordinate by their count. |
Rounding 4/3 too early | Retain fractions or full precision until the end. |
Silently changing the distance measure | Use squared Euclidean distance unless the question or model specifies another measure. |
Incomparable feature scales | Standardise features before fitting when scale would otherwise dominate distance. |
Equal distances | State and apply one deterministic tie rule. |
An empty cluster | Handle it explicitly instead of dividing by zero. |
Do not replace squared Euclidean distance with Manhattan distance midway. Also keep centroid and medoid separate: a centroid is the coordinate-wise mean and need not be an observed point, while a medoid is an observed representative. K-means uses a mean, not a median or medoid.
How k-means assignment and update are tested
A common numerical task supplies the points, K, initial centroids, and a distance measure, then asks for the clusters or new centroids after one or two iterations. Use this scratch order: iteration label, distance table, assignment sets, coordinate sums, new means, then the next-pass change check.
Be ready to explain the reasoning too:
Squaring preserves the nearest-centroid choice because square root is increasing on non-negative values.
Recomputing the mean cannot increase SSE while cluster membership is fixed.
This run ends because a complete third assignment leaves every point in the same cluster.
Convergence does not guarantee the best result across every possible initialisation.
Mini-check: which point changes cluster in the second pass, and why? It is C, because its squared distances are 3.25 to mu_1^(1) and 42.8125 to mu_2^(1), so 3.25<42.8125.
K-means clustering: the short version and next step
The repeatable sequence is simple when each pass stays separate: assign every point using one fixed set of centroids, recompute each mean from its complete assigned set, and repeat until a full assignment pass is unchanged. This run finishes with clusters {A,B,C} and {D,E,F}, centroids (2,4/3) and (9,25/3), and inertia 16/3.
Use Coding & Skill Development Courses to explore the broader catalogue. If you want structured AI and machine-learning preparation beyond this hand calculation, AI & ML for Placements is the focused next step.
Keep learning
Unsupervised Learning and Clustering Explained: K-Means Worked Example and Exam Traps
Build intuition for unlabelled data, then follow k-means from assignment to updated centroids and SSE. Compare medoids, hierarchical clustering, DBSCAN and neural representations.
Means–Ends Analysis in AI: Subgoals, a 3-Disk Worked Example and Exam Traps
Learn the exact Means–Ends Analysis operator cycle, follow all seven moves of a 3-disk Tower of Hanoi solution, and avoid common reasoning traps.
Graphical Method in Linear Programming: Feasible Region, Corner Points and Optimality with a Worked Example
Learn the two-variable graphical method in the right order, then solve and audit a complete maximisation model without trusting the sketch alone.
Mathematical Representation of Points and Lines in Computer Graphics: From Equations to Pixels
Follow one segment from Cartesian coordinates to line equations, a point projection, a homogeneous intersection and seven selected pixels.





