---
title: "K-means on 1-D data, K=2 and K=3"
subject: "Data Mining"
chapter: 5
key: "semester_7/data_mining:kmeans-1d-k2-k3"
source: https://www.bctengineer.com/q/semester_7/data_mining/kmeans-1d-k2-k3
site: BCT Engineering
---

# K-means on 1-D data, K=2 and K=3

Data Mining · Chapter 5: Cluster Analysis

- Asked in: year not given
- Video: [Lec-13: K-mean Clustering with Numerical Example | Unsupervised Learning | Machine🖥️ Learning 🙇‍♂️🙇](https://www.youtube.com/watch?v=5FpsGnkbEpM) — Gate Smashers
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_7/data_mining/kmeans-1d-k2-k3
- Whole chapter: https://www.bctengineer.com/md/semester_7/data_mining/chapter-5

## Question

Identify the cluster of the following instances using K-Means clustering algorithm (Take K=2 and K=3).
X = {2, 24, 21, 5, 6, 41, 35, 36, 9, 26, 44, 7, 46, 26, 11, 1, 32, 43, 48, 13}

## Short answer

For K=2 with initial centroids 2 and 24: Cluster 1 = {1,2,5,6,7,9,11,13} centroid 6.75; Cluster 2 = {21,24,26,26,32,35,36,41,43,44,46,48} centroid 35.17. For K=3 with initial centroids 2,24,46: Cluster 1 = {1,2,5,6,7,9,11,13} centroid 6.75; Cluster 2 = {21,24,26,26,32,35} centroid 27.33; Cluster 3 = {36,41,43,44,46,48} centroid 43.0.

## Answer

**Data** (sorted): 1, 2, 5, 6, 7, 9, 11, 13, 21, 24, 26, 26, 32, 35, 36, 41, 43, 44, 46, 48 (n = 20). For one attribute the distance is d = |x − c|.

**Assumptions**: the initial centroids are chosen from the data: for K = 2: 2 and 24; for K = 3: 2, 24 and 46. A tie goes to the lower-numbered cluster.

#### K = 2
**Iteration 1** (C1 = 2, C2 = 24)
| Value | d to C1 | d to C2 | Cluster | Value | d to C1 | d to C2 | Cluster |
| --- | --- | --- | --- | --- | --- | --- | --- |
| 1 | 1 | 23 | C1 | 26 | 24 | 2 | C2 |
| 2 | 0 | 22 | C1 | 26 | 24 | 2 | C2 |
| 5 | 3 | 19 | C1 | 32 | 30 | 8 | C2 |
| 6 | 4 | 18 | C1 | 35 | 33 | 11 | C2 |
| 7 | 5 | 17 | C1 | 36 | 34 | 12 | C2 |
| 9 | 7 | 15 | C1 | 41 | 39 | 17 | C2 |
| 11 | 9 | 13 | C1 | 43 | 41 | 19 | C2 |
| 13 | 11 | 11 | C1 (tie) | 44 | 42 | 20 | C2 |
| 21 | 19 | 3 | C2 | 46 | 44 | 22 | C2 |
| 24 | 22 | 0 | C2 | 48 | 46 | 24 | C2 |

C1 = {1, 2, 5, 6, 7, 9, 11, 13}, new centroid = 54/8 = **6.75**.
C2 = {21, 24, 26, 26, 32, 35, 36, 41, 43, 44, 46, 48}, new centroid = 422/12 = **35.17**.

**Iteration 2** (C1 = 6.75, C2 = 35.17): the points 1 to 13 are nearer to 6.75 (e.g. 13: 6.25 vs 22.17); 21 is 14.25 from C1 and 14.17 from C2, so it stays in C2; all others are nearer to C2. No object changes cluster, so the algorithm stops.

**Answer (K = 2): Cluster 1 = {1, 2, 5, 6, 7, 9, 11, 13}, centroid 6.75; Cluster 2 = {21, 24, 26, 26, 32, 35, 36, 41, 43, 44, 46, 48}, centroid 35.17.**

#### K = 3
**Iteration 1** (C1 = 2, C2 = 24, C3 = 46): each value goes to the nearest centroid:
- C1 = {1, 2, 5, 6, 7, 9, 11, 13} (13 is 11 from both 2 and 24; tie to C1)
- C2 = {21, 24, 26, 26, 32, 35} (35 is 11 from 24 and 11 from 46; tie to C2)
- C3 = {36, 41, 43, 44, 46, 48}

New centroids: C1 = 54/8 = **6.75**, C2 = 164/6 = **27.33**, C3 = 258/6 = **43.0**.

**Iteration 2** (6.75, 27.33, 43.0)
| Border values | d to C1 | d to C2 | d to C3 | Cluster |
| --- | --- | --- | --- | --- |
| 13 | 6.25 | 14.33 | 30.0 | C1 |
| 21 | 14.25 | 6.33 | 22.0 | C2 |
| 35 | 28.25 | 7.67 | 8.0 | C2 |
| 36 | 29.25 | 8.67 | 7.0 | C3 |

No change in assignment, so the algorithm has converged.

**Answer (K = 3): Cluster 1 = {1, 2, 5, 6, 7, 9, 11, 13}, centroid 6.75; Cluster 2 = {21, 24, 26, 26, 32, 35}, centroid 27.33; Cluster 3 = {36, 41, 43, 44, 46, 48}, centroid 43.0.**

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. For one attribute, what is the distance used in K-means?
   A. d = |x - c|
   B. d = x + c
   C. d = (x - c)^3
   D. d = x/c
   Answer: A. With one dimension, Euclidean distance reduces to the absolute difference. (Key point: 1D distance)

2. For K = 2, cluster C1 = {1, 2, 5, 6, 7, 9, 11, 13} has what new centroid?
   A. 6.75
   B. 7.5
   C. 35.17
   D. 13
   Answer: A. The sum is 54, and 54/8 = 6.75. (Key point: K=2 centroid)

3. How is value 13 (equidistant 11 from centroids 2 and 24) handled?
   A. Discarded
   B. Placed in both
   C. Tie goes to the lower-numbered cluster, C1
   D. Made a new cluster
   Answer: C. The stated rule gives ties to the lower-numbered cluster. (Key point: Ties)

4. For K = 3, what are the final centroids?
   A. 6.75, 27.33, 43.0
   B. 6.75, 35.17, 43.0
   C. 2, 24, 46
   D. 10, 25, 40
   Answer: A. Clusters {1..13}, {21,24,26,26,32,35} and {36..48} have means 6.75, 164/6 = 27.33 and 258/6 = 43.0. (Key point: K=3 result)

## Close variants set in other exams

- [K-means on six 2-D instances (K=2)](https://www.bctengineer.com/question.md?key=semester_7%2Fdata_mining%3Akmeans-x-y-k2) — Data Mining, chapter 5

## Related in Data Mining

- [Need of clustering; hierarchical vs partitioning; K-means](https://www.bctengineer.com/question.md?key=semester_7%2Fdata_mining%3Acluster-need-hier-vs-partition-kmeans) — Data Mining, chapter 5
- [Cluster analysis; K-means on height/width](https://www.bctengineer.com/question.md?key=semester_7%2Fdata_mining%3Akmeans-height-width) — Data Mining, chapter 5
- [K-means on six 2-D instances (B65)](https://www.bctengineer.com/question.md?key=semester_7%2Fdata_mining%3Akmeans-b65) — Data Mining, chapter 5
- [Cluster analysis applications; K-means](https://www.bctengineer.com/question.md?key=semester_7%2Fdata_mining%3Acluster-application-kmeans) — Data Mining, chapter 5
- [Short note: K-means clustering](https://www.bctengineer.com/question.md?key=semester_7%2Fdata_mining%3Akmeans-note) — Data Mining, chapter 5
- [K-means on eight points into 3 clusters](https://www.bctengineer.com/question.md?key=semester_7%2Fdata_mining%3Akmeans-eight-points-k3) — Data Mining, chapter 5

## Related in other subjects

- [Two groups: best, consistent, SE of difference](https://www.bctengineer.com/question.md?key=semester_5%2Fprobability_and_statistics%3Atwo-groups-best-consistent-se) — Probability and Statistics, chapter 1
- [Gumbel design flood, 43 years data, 85% reliability](https://www.bctengineer.com/question.md?key=semester_5%2Fengineering_hydrology%3Agumbel-43yr-330-187-life50) — Engineering Hydrology, chapter 6, asked 2×
- [B-tree from 78, 21, 14, 11, 97, 85, 74, 63](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Abtree-build-78-21-14) — Data Structure and Algorithm, chapter 6, asked 2×
- [22 pairs: means, consistency, correlation](https://www.bctengineer.com/question.md?key=semester_5%2Fprobability_and_statistics%3Asample-22-pairs-xy-correlation) — Probability and Statistics, chapter 5
