Skip to content
GATEiit

GATE DA · Machine Learning

Hierarchical clustering: top-down and bottom-up; single-linkage and multiple-linkage

Building a hierarchy of clusters bottom-up (agglomerative) or top-down (divisive), the single, complete, average and centroid linkage rules, reading a dendrogram, and tracing merges from a distance matrix.

Before you start

Concept notes

1. Hierarchical clustering and the dendrogram

Hierarchical clustering builds a nested sequence of clusterings instead of one flat partition. There are two directions:

  • Agglomerative (bottom-up): start with n singleton clusters and repeatedly merge the two closest clusters until one cluster remains. Exactly n−1 merges happen.
  • Divisive (top-down): start with all n points in one cluster and repeatedly split a cluster into two until every point is alone (or a stopping rule fires).

The result is drawn as a dendrogram: a tree whose leaves are the points and whose internal nodes are merges, drawn at a height equal to the linkage distance at which the merge happened.

Cutting the dendrogram with a horizontal line at height h gives a flat clustering: the number of clusters equals the number of vertical lines the cut crosses. So the number of clusters need not be fixed in advance, unlike k-means. Cutting just below the last merge always gives 2 clusters.

012345heightcut at 4:2 clustersA (0)B (1)C (4)D (9)E (11)single-linkage merges at heights 1, 2, 3, 5
Single-linkage dendrogram for the 1-D points A=0, B=1, C=4, D=9, E=11. A cut at height 4 gives {A, B, C} and {D, E}.

2. Linkage: distance between two clusters

Agglomerative clustering needs a rule for the distance D(P,Q) between clusters P and Q, built from point distances d(x,y).

Linkage D(P,Q) Behaviour
Single (nearest neighbour) min⁡d(x,y) Finds long, thin or curved clusters; suffers chaining
Complete (farthest neighbour) max⁡d(x,y) Compact clusters of similar diameter; sensitive to outliers
Average (UPGMA) mean of all ∣P∣ ∣Q∣ pairs Compromise between the two
Centroid d(μP,μQ) Distance between cluster means
Ward rise in total within-cluster squared error Similar to k-means

In each min, max or mean, x ranges over P and y over Q. The syllabus term "multiple linkage" covers the rules other than single linkage, which look at more than one pair of points.

Chaining: with single linkage, two dense groups joined by a thin trail of points merge early, because one close pair is enough.

Single, complete, average and Ward give monotone dendrograms (merge heights never decrease). Centroid linkage can give an inversion: a later merge at a smaller height.

3. Running agglomerative clustering by hand

Work on the distance matrix:

  1. Find the smallest off-diagonal entry; merge that pair. Record the merge height.
  2. Replace the two rows and columns by one row for the new cluster.
  3. Fill the new row with the linkage rule. For a merged cluster P∪Q and any other cluster R:
    • single: D(P∪Q,R)=min⁡(D(P,R),D(Q,R))
    • complete: D(P∪Q,R)=max⁡(D(P,R),D(Q,R))
    • average: D(P∪Q,R)=∣P∣D(P,R)+∣Q∣D(Q,R)∣P∣+∣Q∣ (size-weighted)
  4. Repeat until one cluster is left.

The first merge is the same for every linkage (the closest pair of points). The rules differ from the second or third merge onwards, so GATE questions usually ask for the clusters at a later stage or the height of the last merge.

Single linkage and MSTs: single-linkage merges are exactly the edges Kruskal's algorithm adds to a minimum spanning tree, in the same order. Cutting the dendrogram into k clusters equals deleting the k−1 heaviest MST edges.

Cost: the naive method is O(n3) time and needs the O(n2) distance matrix.

4. Divisive (top-down) clustering

Divisive clustering starts with one cluster and splits. Trying every split is hopeless: a cluster of n points has 2n−1−1 ways to split into two non-empty parts. So practical methods use a heuristic.

  • Bisecting k-means: split the chosen cluster with 2-means; repeat on the cluster with the largest spread.
  • DIANA (divisive analysis): in the chosen cluster, the point with the largest average distance to the others starts a "splinter" group. Then any point whose average distance to the splinter group is smaller than to the rest moves across. Repeat until no point moves.
Agglomerative Divisive
Starts with n singletons one cluster
Step merge closest pair split one cluster
Good at fine, local structure large, global structure
Mistakes a merge is never undone a split is never undone

Both are greedy: a decision taken at one level is final at every later level.

Formulas to remember

Single linkage
Dmin⁡(P,Q)=min⁡x∈P, y∈Qd(x,y)
Complete linkage
Dmax⁡(P,Q)=max⁡x∈P, y∈Qd(x,y)
Average linkage
Davg(P,Q)=1∣P∣ ∣Q∣∑x∈P∑y∈Qd(x,y)
Centroid linkageμP is the mean of the points in P
Dcen(P,Q)=∥μP−μQ∥
Merges in agglomerative clusteringStarting from n singletons
n−1
Two-way splits of an $n$-point clusterWhy exhaustive divisive clustering is impractical
2 n−1−1

Common mistakes

  • Updating a merged cluster's distance with min when the question asks for complete linkage (or max for single). Read the linkage first.
  • Using the plain average of the two old entries for average linkage when the clusters have different sizes; the update must be weighted by cluster size.
  • Assuming all linkages give the same final clusters because they share the first merge; they usually differ from the second or third merge.
  • Counting clusters after a dendrogram cut by counting merges above the cut instead of the vertical lines the cut crosses.
  • Saying hierarchical clustering needs k in advance; only the cut level needs choosing, after the tree is built.

Worked examples

Try each step yourself, then reveal the working.

Example 1: Single, complete and average linkage on five points

numerical

One-dimensional points: A = 0, B = 1, C = 4, D = 9, E = 11. Run agglomerative clustering with single, complete and average linkage. Give the merge heights for each.

  1. Step 1: Find the first two merges. Do they depend on the linkage?

    Try it on paper first.

Example 2: Single and complete linkage can give different clusters

numerical

Four objects have the distance matrix below (rows and columns in the order P, Q, R, S):

Find the two clusters obtained by single linkage and by complete linkage.

  1. Step 1: Make the first merge.

    Try it on paper first.

Example 3: One divisive (DIANA) split

numerical

Split the 1-D points 2, 3, 5, 12, 14 into two groups with the DIANA rule (absolute difference as distance).

  1. Step 1: Find each point's average distance to the other four.

    Try it on paper first.

Example 4: Choosing a linkage

conceptual

Two dense, round groups of points are joined by a thin line of points spaced closely. Which linkage is likely to merge the two groups early, and which keeps them apart longer?

  1. Step 1: How does single linkage see the bridge?

    Try it on paper first.

Previous year questions

3 official GATE DA questions on this topic, newest first.

Practise these 3 PYQs →

Topic test

10 questions: up to 3 official PYQs and original practice questions, with GATE marking (MCQ wrong answers lose marks). Score 60% or more to pass. A new set is drawn each time.

Mark as mastered

Loading your progress…

My revision notes

Notes written by the GATEiit team against the official GATE DA syllabus; being checked by a reviewer. Updated 2026-11-21. Spotted a mistake? Use Report an issue on any question, or contact us.