Hierarchical agglomerative clustering (HAC) builds a tree of nested clusters by merging the two closest clusters $N - 1$ times, so it needs no number of clusters in advance and, apart from ties, always gives the same tree. The linkage, the rule for the distance between two clusters, decides the tree: on six points on a line, single and complete linkage part ways at the fourth merge. On 30 samples of 600 Reuters stories cut into six clusters, single linkage left at least 590 stories in one cluster every time, and complete linkage's cut was decided by ties at similarity zero. Average linkage came close to k-means (median NMI 0.394 against 0.384). HAC computes $O(N^2)$ similarities, which limits it to small collections such as search results.
K-means split the Reuters stories into six flat clusters, because we asked for six. Many uses of clustering want a hierarchy instead: broad groups at the top for an overview, divided into narrower ones for a closer look. Browsing a collection works this way, and so do taxonomies of topics. The original Scatter/Gather system produced such levels on the fly, by reclustering the groups a user selected. Can a tree of clusters be built directly, without choosing $K$ at all, and how does it compare with k-means?
It can. Hierarchical clustering builds that structure directly, as a tree of nested clusters, and does not need the number of clusters in advance. How it compares with k-means depends on how the similarity of two clusters is measured. On 30 samples of 600 Reuters stories, one such measure came close to k-means and two others failed every time, as the comparison near the end shows.
Here is the route. First we state the bottom-up algorithm, its top-down counterpart, and the choice the bottom-up algorithm depends on, the similarity between clusters. Then we trace it by hand on six points under four such choices and read the results as dendrograms. Next come chaining and outliers, and a summary of the linkages' properties and of the cost, whose proofs are in Linkage properties of agglomerative clustering. Finally we compare the methods with k-means on samples of 600 Reuters stories and solve an exercise of the course text. The article follows Manning, Raghavan, and Schütze (2008, chapter 17).
Agglomerative clustering
The common approach is bottom-up, or hierarchical agglomerative clustering (HAC):
- Start with every document in a cluster of its own.
- Find the two most similar clusters and merge them.
- Repeat until a single cluster contains everything.
Each merge is recorded, so the result is a binary tree with documents at the leaves and the whole collection at the root. $N$ documents take exactly $N - 1$ merges. Unlike k-means, HAC has no random starting point. Given the same documents and similarity measure, it always produces the same tree, apart from ties.
Divisive clustering
The opposite, top-down approach is divisive clustering: start with one cluster and repeatedly split one in two. It needs a flat clustering algorithm to do the splitting, and the usual choice is k-means with $K = 2$. The result is bisecting k-means (Steinbach, Karypis, and Kumar, 2000):
- Start with all documents in one cluster.
- Pick a cluster to split.
- Split it in two with k-means. Do this several times from different seeds and keep the best split.
- Repeat steps 2 and 3 until the wanted number of clusters is reached, or until every document is alone, which gives a full tree.
Steinbach, Karypis, and Kumar judged a split by the average pairwise similarity within the clusters and split the largest remaining cluster each time. They report little difference between ways of picking the cluster. The trace below judges a split by its RSS and splits the cluster with the largest RSS, the residual sum of squares defined in the k-means article.
The six points of the worked example below sit on a line at $a = 0$, $b = 1$, $c = 2.5$, $d = 4.5$, $e = 5.7$ and $f = 9.5$. To keep the trace free of seeds, the script takes for each split the exact lowest-RSS division, found by trying every one. All six points in one cluster have RSS 60.53. Of the 31 ways to divide them in two, the three best are these:
| Split | RSS |
|---|---|
| {a, b, c} and {d, e, f} | 16.79 |
| {a, b, c, d} and {e, f} | 18.72 |
| {a, b, c, d, e} and {f} | 22.45 |
The whole trace follows. Each row splits the cluster whose RSS is largest; the last column is the RSS summed over all clusters after the split.
| Step | Cluster split (its RSS) | Into | Total RSS after |
|---|---|---|---|
| 1 | abcdef (60.53) | abc, def | 16.79 |
| 2 | def (13.63) | de, f | 3.89 |
| 3 | abc (3.17) | ab, c | 1.22 |
| 4 | de (0.72) | d, e | 0.5 |
| 5 | ab (0.5) | a, b | 0 |
At step 2 the other divisions of $\{d, e, f\}$ are $d$ against $\{e, f\}$, with RSS 7.22, and $\{d, f\}$ against $e$, with 12.5. At step 3 the other divisions of $\{a, b, c\}$ score 1.125 and 3.125 against 0.5.
Example (why step 3 repeats the split). Started from the seeds $a$ and $f$, k-means with $K = 2$ stops at $\{a, b, c, d\}$ and $\{e, f\}$, RSS 18.72, not at the best split. In the first iteration $d$ is 4.5 from $a$ and 5 from $f$, so it joins $a$, while $e$ is 5.7 from $a$ and 3.8 from $f$. The centroids move to 2 and 7.6, no point changes sides, and the run stops. Started from the seeds $a$ and $b$, the left cluster grows from $\{a\}$ to $\{a, b\}$ to $\{a, b, c\}$, and the run stops at the best split, 16.79. A single run can return a local minimum, as the k-means article showed, so bisecting k-means keeps the best of several.
Divisive clustering is less common than HAC. Still, Steinbach, Karypis, and Kumar (2000) found bisecting k-means competitive with the best agglomerative method on text. Its F-measure was higher than that of average linkage on seven of their eight document collections (on one of the seven, re0, by 0.0004; average linkage won on tr45). It is also faster when only the top levels of the tree are needed. Each split is a k-means run, linear in the number of documents, while HAC is at least quadratic (Manning, Raghavan, and Schütze, 2008, §17.6). The top-down tree of the six points has the same clusters as the complete-link tree found below. That is an observation about these six points, not a general fact. Semantic document identifiers in Generative Retrieval are built by a similar recursion of k-means, with $k$ groups at each split, so that a prefix of the identifier names a cluster.
Similarity between clusters
Step 2 hides the real decision. It needs the similarity of two clusters, not only of two documents. The choice, called the linkage, decides what the algorithm finds. With document similarity measured by cosine similarity:
- Single linkage uses the similarity of the most similar pair, one document from each cluster. Two clusters are close if any of their members are close.
- Complete linkage uses the similarity of the least similar pair. Two clusters are close only if all their members are close.
- Average linkage uses the average similarity over all pairs with one document in each cluster, the cross pairs. This article's examples and its Reuters comparison use this form. The textbook's group-average variant averages over all pairs of distinct documents in the merged cluster, including pairs within each original cluster; a document's similarity to itself is left out (Manning, Raghavan, and Schütze, 2008, §17.3, eq. 17.1).
- Centroid linkage uses the similarity of the two clusters' centroids. With dot-product similarity, the average over cross pairs equals the dot product of the two centroids (Manning, Raghavan, and Schütze, 2008, §17.4, eq. 17.6). So average linkage in the cross-pair form and centroid linkage coincide. When centroids are compared by a distance instead, centroid linkage behaves differently, as the section on inversions in Linkage properties of agglomerative clustering shows.
Why the cross-pair average is the centroid similarity. The dot product distributes over sums, so a sum of dot products is the dot product of the sums. Let cluster $\omega_i$ hold $n_i$ documents with vectors $\vec{x}_1, \dots, \vec{x}_{n_i}$ and centroid $\vec{\mu}_i = \frac{1}{n_i} \sum_m \vec{x}_m$. Let $\omega_j$ hold $n_j$ documents $\vec{y}_1, \dots, \vec{y}_{n_j}$ with centroid $\vec{\mu}_j$. Then
$$\vec{\mu}_i \cdot \vec{\mu}_j = \Big( \frac{1}{n_i} \sum_{m} \vec{x}_m \Big) \cdot \Big( \frac{1}{n_j} \sum_{\ell} \vec{y}_\ell \Big) = \frac{1}{n_i n_j} \sum_{m} \sum_{\ell} \vec{x}_m \cdot \vec{y}_\ell .$$
The right side is the mean of the $n_i n_j$ cross-pair dot products. The identity uses nothing about the lengths of the vectors. When they have unit length, each dot product is a cosine similarity. The script confirms the identity on random vectors.
Everything here can be stated with distances instead of similarities, merging the two closest clusters. Single linkage then uses the smallest cross-pair distance, complete linkage the largest, average linkage the mean cross-pair distance, and centroid linkage the distance between centroids. The worked example uses distances, because points on a line make them easy to read.
A worked example
The linkage can change the tree. On six points on a line, three linkages agree on which clusters join in the first three merges and part ways at the fourth. The points sit at $a = 0$, $b = 1$, $c = 2.5$, $d = 4.5$, $e = 5.7$ and $f = 9.5$, with the distance between two points the difference of their positions. They form a loose chain from $a$ to $e$, with $f$ off on its own:
| a | b | c | d | e | f | |
|---|---|---|---|---|---|---|
| a | 0 | 1 | 2.5 | 4.5 | 5.7 | 9.5 |
| b | 1 | 0 | 1.5 | 3.5 | 4.7 | 8.5 |
| c | 2.5 | 1.5 | 0 | 2 | 3.2 | 7 |
| d | 4.5 | 3.5 | 2 | 0 | 1.2 | 5 |
| e | 5.7 | 4.7 | 3.2 | 1.2 | 0 | 3.8 |
| f | 9.5 | 8.5 | 7 | 5 | 3.8 | 0 |
The first two merges are the same for every linkage, because between single points all linkages agree: the smallest entry is $a$–$b$ at 1, then $d$–$e$ at 1.2.
The third merge joins $c$ to $\{a, b\}$ under every linkage, but at different heights, because the linkages measure the distance from $c$ to $\{a, b\}$ differently. The two cross distances are $c$–$b$ = 1.5 and $c$–$a$ = 2.5. Single linkage takes the smaller, 1.5; complete the larger, 2.5; average their mean, 2.0. In each case this is the smallest distance among the clusters left, $\{a, b\}$, $c$, $\{d, e\}$, $f$.
Example (the next merge under complete linkage). With the three clusters $\{a, b, c\}$, $\{d, e\}$ and $f$ remaining, complete linkage merges $\{d, e\}$ and $f$ next. Complete linkage scores $\{a, b, c\}$ against $\{d, e\}$ by their farthest pair, $a$–$e$ at 5.7. It scores $\{d, e\}$ against $f$ by $d$–$f$ at 5, which is smaller, so $f$ joins $\{d, e\}$. The third pair, $\{a, b, c\}$ and $f$, is 9.5 apart.
The fourth merge is where the linkages disagree. The candidate distances for the three clusters $\{a, b, c\}$, $\{d, e\}$ and $f$ are:
| Pair | Cross distances | Single | Complete | Average |
|---|---|---|---|---|
| {a, b, c} and {d, e} | 4.5, 5.7, 3.5, 4.7, 2, 3.2 | 2 | 5.7 | 3.93 |
| {d, e} and f | 5, 3.8 | 3.8 | 5 | 4.4 |
| {a, b, c} and f | 9.5, 8.5, 7 | 7 | 9.5 | 8.33 |
Single linkage sees the close pair $c$–$d$ at distance 2 and joins the chain. Complete linkage sees that $a$ and $e$ are 5.7 apart, which would make $\{a, \dots, e\}$ a wide cluster, and prefers $\{d, e, f\}$, whose widest pair is 5. Average linkage, at $23.6 / 6 \approx 3.93$ against 4.4, sides with single linkage this time. The full sequence of merges, with the distance at which each happened (rounded to two decimals):
| Merge | Single link | Complete link | Average link |
|---|---|---|---|
| 1 | a + b at 1 | a + b at 1 | a + b at 1 |
| 2 | d + e at 1.2 | d + e at 1.2 | d + e at 1.2 |
| 3 | ab + c at 1.5 | ab + c at 2.5 | ab + c at 2 |
| 4 | abc + de at 2 | de + f at 5 | abc + de at 3.93 |
| 5 | abcde + f at 3.8 | abc + def at 9.5 | abcde + f at 6.76 |
Centroid linkage gives the same tree as average linkage here, with the same heights. On a line, the distance between two centroids equals the average cross distance whenever one cluster lies entirely to one side of the other. The reason is that every cross distance is then a difference taken the same way round. If every point $x$ of one cluster lies to the left of every point $y$ of the other, each distance is $y - x$. The mean of the differences $y - x$ over all cross pairs is the mean of the $y$ minus the mean of the $x$, which is the distance between the centroids. That holds at every merge of this example, because the clusters compared are always runs of neighboring points. When the clusters interleave, the two differ: the clusters $\{0, 5\}$ and $\{2.5\}$ have the same centroid, distance 0, and average cross distance 2.5. In the plane the two differ as well, as the three points of the inversion example in Linkage properties of agglomerative clustering show.
Dendrograms
The tree is drawn as a dendrogram, with documents along the bottom. Each merge is a horizontal line joining two branches, at a height given by the distance (or similarity) of the clusters merged. Merges of very similar clusters sit near the bottom; the last, least similar merges sit near the top.
Notice also that in every tree each merge sits higher than the one before. Under single linkage the heights are 1, 1.2, 1.5, 2 and 3.8. Single, complete and average linkage always behave this way: merge heights never decrease. The textbook calls this property monotonicity (Manning, Raghavan, and Schütze, 2008, §17.1) and names centroid clustering as the only one of its four methods without it (§17.4). Its inversion example (Figure 17.12) measures similarity as negative Euclidean distance, although its definition of centroid similarity is the dot product of the centroids (eq. 17.5). With the dot product, centroid clustering is monotone. Linkage properties of agglomerative clustering proves monotonicity for single, complete and cross-pair average linkage from their distance-update rules, and its Problem 1 proves it for the textbook's group-average method. Milligan (1979) gives general conditions on update rules under which it holds. Monotonicity is what lets a dendrogram be read as "clusters merged later are less alike". The section on inversions of that article shows a linkage that lacks it.
A flat clustering can be taken from the tree by cutting it:
- at a fixed similarity, keeping only merges above a threshold;
- at the number of clusters wanted, undoing the last $K - 1$ merges;
- at the largest gap between successive merge heights, where the next merge would join clusters much less similar than any merged before.
In the example, all three trees have their largest gap before the last merge: from 2 to 3.8 for single link, 5 to 9.5 for complete, and 3.93 to 6.76 for average. So the gap rule gives two clusters in each case: $\{a, b, c, d, e\}$ and $\{f\}$ for single and average linkage, $\{a, b, c\}$ and $\{d, e, f\}$ for complete.
Example (three clusters from the complete-link tree). Cutting the complete-link tree into three clusters, by undoing its last two merges, gives $\{a, b, c\}$, $\{d, e\}$ and $\{f\}$. Undoing the last merge separates $\{a, b, c\}$ from $\{d, e, f\}$, and undoing the one before separates $f$ from $\{d, e\}$. The single-link and average-link trees give the same three clusters, although at two clusters they differ from the complete-link tree.
The tree holds every one of these clusterings at once, which is part of its appeal. A browsing interface can show the top levels and let users descend.
Chaining and outliers
Single linkage has a well-known weakness, chaining. Because one close pair is enough to merge two clusters, a sequence of documents each similar to the next can join documents at the two ends that have nothing in common.
The example shows it at small scale. Single linkage puts $a$ and $e$ in one cluster although they are 5.7 apart, farther than $e$ is from $f$, because each link along the chain is at most 2. Single-link clusters tend to be long and straggly. On text, single linkage can grow one giant cluster that absorbs documents one at a time. The textbook's 30-story example ends with eleven merges that each add a single document or a pair (Manning, Raghavan, and Schütze, 2008, Figure 17.1 and §17.2), and all 30 Reuters samples below end in one giant cluster. Single-link HAC is equivalent to building a minimum spanning tree of the documents and removing its longest edges; Linkage properties of agglomerative clustering proves it.
Complete linkage avoids chaining. It prefers compact clusters with small diameters, but it is sensitive to outliers. A single document far from the rest greatly increases the diameter of any cluster it could join, and can change the whole clustering. In the example, $f$ does this by pulling $d$ and $e$ away from $c$. Average linkage is a compromise between the two. Manning, Raghavan, and Schütze (2008, §17.5) recommend group-average clustering for documents, because it suffers from neither chaining, nor sensitivity to outliers, nor inversions. They name two exceptions. Documents that are not vectors cannot use it and should be clustered with complete linkage. Tasks that depend on local structure, such as detecting the first story about an event or finding duplicates, suit single linkage.
Properties of the linkages, and cost
The rest of this article uses four facts about the linkages, all proved in Linkage properties of agglomerative clustering. After a merge, each linkage finds the distance from the new cluster to every other from distances already known, and under single, complete and average linkage merge heights never decrease. Centroids compared by Euclidean distance can invert the tree. Single-link merges are the edges of a minimum spanning tree in order of weight. With priority queues HAC takes $O(N^2 \log N)$ time, and single linkage $O(N^2)$.
In practice the difference matters less than the notation suggests. All these algorithms compute $O(N^2)$ document similarities, and computing a similarity between two documents costs far more than a comparison inside a queue (Manning, Raghavan, and Schütze, 2008, §17.2.1). They also keep the $N \times N$ similarity matrix, so memory is quadratic as well.
That cost decides when HAC can be used. For the few hundred results of a query, it is fast: 600 documents have about 180,000 distinct pairs. A collection of a million documents is another matter. Its similarity matrix has $5 \times 10^{11}$ distinct pairs, about 2 terabytes at four bytes each, and k-means, linear in $N$, is the practical choice. A common hybrid clusters a sample with HAC, uses the resulting clusters as starting centroids, and runs k-means on the whole collection (Manning, Raghavan, and Schütze, 2008, §17.8). The Buckshot algorithm of Scatter/Gather works this way. It applies group-average clustering to a random sample of $\sqrt{KN}$ documents, takes the centers of the $K$ clusters found, and then assigns every document to its nearest center, in two rounds when the clustering is done interactively (Cutting, Karger, Pedersen, and Tukey, 1992).
Comparison on Reuters
Six points showed how the linkages differ, and the difference is larger on real text. The four methods were compared on a random sample of 600 stories from the six-category Reuters collection of K-means in practice, with the same TF-IDF vectors. About half of the sample is in the large earn category. Each dendrogram was cut into six clusters, and the lowest-RSS of ten k-means++ runs on the same sample was taken for comparison. The measures are defined in evaluating clusterings.
The first table reports one sample, drawn with a fixed seed, so that its clusters can be examined one by one. Differences of a few hundredths between its rows carry no weight. The second table, further down, repeats the comparison on 30 samples.
Example (what the chaining figure predicts). Judging from the chaining figure, single linkage should do worst when its tree is cut into six clusters, with one giant cluster and a few stragglers. The table confirms it. It also shows that complete linkage did nearly as badly, for a reason the six points could not reveal.
| Method | Purity | NMI | Rand index | Cluster sizes |
|---|---|---|---|---|
| Single linkage | 0.523 | 0.018 | 0.379 | 595, 1, 1, 1, 1, 1 |
| Complete linkage | 0.532 | 0.036 | 0.394 | 577, 9, 5, 4, 3, 2 |
| Average (centroid) linkage | 0.725 | 0.369 | 0.689 | 308, 261, 9, 9, 8, 5 |
| K-means | 0.753 | 0.409 | 0.691 |
Single linkage chained almost everything into one cluster and left five individual stories apart at the top of the tree. That is the behavior of the chaining figure, at scale. Its NMI of 0.018 says the clusters carry almost no information about the categories.
Complete linkage ran into a property of sparse text vectors. Many pairs of stories share no terms and have similarity exactly zero. Once clusters grow, nearly every pair of clusters contains such a pair. The last 27 merges before the six-cluster cut all took place at complete-link similarity zero. So which clusters merged, and the six-cluster cut, were decided by how ties were broken, not by the data.
The script's tie rule is this. It keeps the cluster similarities in a table with one row per cluster. A merged cluster stays in the row of its earliest story, in the order the sample was drawn. Among pairs tied for the highest similarity, it takes the first one met when the table is read row by row. That is the pair whose earlier cluster comes first in the sample order, and among those the one with the earliest partner. TF-IDF weights are not negative, so no similarity is below zero. Once the highest complete-link similarity is zero, every remaining pair is therefore tied at zero. The rule then merges the cluster holding the first story of the sample with the next cluster in sample order, again and again. The large complete-link cluster in the table is thus a product of the sample's random order. Another tie rule would give other clusters at this level.
In both cases the cut at six clusters does not reflect the categories, though the trees may hold sensible groups at lower levels.
Average linkage produced two large clusters and four small ones, with scores close to k-means. K-means was slightly better on all three measures in this sample. On this sample the choice of linkage mattered far more than the choice between average-link HAC and k-means.
Thirty samples. One sample cannot say which of these observations are stable. So the comparison was repeated on 30 samples of 600 stories, drawn with seeds 0 to 29, with the same procedure and the same tie rule. The sample above is seed 0. The table gives the median and the interquartile range of each measure, and of the size of the largest of the six clusters.
| Method | Purity | NMI | Rand index | Largest cluster |
|---|---|---|---|---|
| Single linkage | 0.525 (0.515 to 0.541) | 0.023 (0.017 to 0.025) | 0.379 (0.373 to 0.391) | 595 (594 to 595) |
| Complete linkage | 0.536 (0.525 to 0.551) | 0.051 (0.039 to 0.066) | 0.399 (0.392 to 0.409) | 581 (577 to 585) |
| Average (centroid) linkage | 0.738 (0.720 to 0.753) | 0.394 (0.368 to 0.442) | 0.720 (0.690 to 0.736) | 307 (297 to 316) |
| K-means | 0.729 (0.710 to 0.761) | 0.384 (0.358 to 0.447) | 0.672 (0.648 to 0.689) | 193 (182 to 221) |
The failures of single and complete linkage are stable. Single linkage left at least 590 of the 600 stories in one cluster in all 30 samples. Complete linkage made between 21 and 32 merges at similarity zero before the six-cluster cut in every sample, with a median of 28, so its cut was decided by the tie rule every time.
The ranking of average linkage against k-means in the single sample is not stable. Over the 30 samples the two have nearly the same median purity and NMI. Average linkage had the higher NMI in 16 samples and the higher Rand index in 22. It is also less dependable. In 3 of the 30 samples it put between 569 and 590 stories into one cluster, with NMI between 0.04 and 0.19, while k-means never did. What holds across the samples is the last sentence of the single-sample reading: the choice of linkage mattered far more than the choice between average-link HAC and k-means.
When to use which
- Hierarchical clustering suits small collections, such as a set of search results, and uses that need a hierarchy or an unknown number of clusters. It is deterministic, which makes results reproducible.
- K-means suits large collections and uses that need a fixed number of flat clusters. It is fast but depends on its starting point.
- Group-average linkage is the default the textbook recommends for documents (§17.5). On the 30 Reuters samples above, the cross-pair average was also the only linkage that came close to k-means. Single linkage is useful mainly for its connection to minimum spanning trees and for finding elongated structures, not for grouping documents by topic.
Worked problems
The problem is Exercise 17.9 of the course text (Manning, Raghavan, and Schütze, 2008), numbered as in the printed book and restated in our own words. The solution is ours, and the script checks every number in it. Exercises 17.11, 17.6 and 17.10 are solved in Linkage properties of agglomerative clustering.
Problem 1 (Exercise 17.9). A run of HAC finds that, among the clusterings in its tree, the one with $K = 7$ clusters scores highest on some chosen measure of quality. Is it the highest-scoring clustering among all clusterings with seven clusters?
Not in general. The tree contains exactly one clustering with seven clusters, the one left after $N - 7$ merges. Comparing it with the other levels of the same tree says nothing about the many other ways to form seven clusters. HAC is greedy: each merge is the best available at that moment and is never undone, so a clustering that requires separating two documents merged early is out of reach. There is one exception, proved next. Two small cases after it show a better clustering of the same size outside the tree when the exception does not apply.
The exception: single link judged by its own measure. The course text (§17.5) defines the combination similarity of a cluster for single link without reference to any merges. Divide the cluster into two parts in every possible way, take for each division the largest similarity between a document of one part and a document of the other, and take the smallest of those values. A singleton scores 1, and a clustering scores the smallest value among its clusters. In other words, a cluster scores above $t$ exactly when its documents are connected by pairs of similarity above $t$. If they are, every division is crossed by such a pair. If they are not, the division into one connected piece and the rest has no crossing pair above $t$.
Assume all pairwise similarities are distinct and below 1. Let $s$ be the similarity of the last merge that produces the single-link level with $K$ clusters. Single link merges pairs in decreasing order of similarity, skipping pairs already in one cluster, as the minimum spanning tree section of Linkage properties of agglomerative clustering shows. So the clusters of that level are the groups connected by pairs of similarity at least $s$, and the level scores at least $s$. It scores exactly $s$, because the two clusters joined at $s$ have no closer pair between them. Now take any clustering with at most $K$ clusters and suppose it scores above $s$. Then each of its clusters is connected by pairs of similarity above $s$. Those pairs connect the documents into the single-link level just before the merge at $s$, which has $K + 1$ groups. Each cluster lies inside one group, so there are at least $K + 1$ clusters, a contradiction. Hence no clustering with at most $K$ clusters scores above $s$, and the single-link level is the best of its size on this measure. The course text proves the same by induction on $K$ (Manning, Raghavan, and Schütze, 2008, §17.5). It adds that this is optimality for a criterion that rewards chains, which is often not the one wanted. For complete link and group average, judged by their own measures, the tree can miss the best clustering, as the text's four points show next.
Complete linkage and diameter. Complete linkage aims at clusters of small diameter, the largest distance between two members. Take four points on a line at 1, 4, 5 and 8, spaced like the four points of the textbook's example in §17.5. Complete linkage first merges 4 and 5, at distance 1. The next candidates are $\{4, 5\}$ with 1 and $\{4, 5\}$ with 8, both at distance 4, and 1 with 8 at distance 7. Whichever of the tied pairs is taken, the two-cluster level has a cluster of diameter 4. The clustering $\{1, 4\}$, $\{5, 8\}$ has diameters 3 and 3. It is better by complete linkage's own measure, and the tree cannot contain it, because 4 and 5 were joined at the first step.
The six points and RSS. Score a clustering by its RSS, lower being better. The two-cluster level of the single-link and average-link trees is $\{a, b, c, d, e\}$ and $\{f\}$. The first cluster has centroid $13.7 / 5 = 2.74$, and the RSS is 22.45. The clustering $\{a, b, c\}$, $\{d, e, f\}$ has RSS 16.79, the lowest of all 31 two-way divisions, as the divisive trace found. On these points the complete-link tree does contain it. So the same measure can favor one tree over another, and no tree is guaranteed to hold the best clustering of a given size.
What we have learned
Hierarchical agglomerative clustering merges the two closest clusters until one remains, and records the merges as a dendrogram that holds a flat clustering at every level. Divisive clustering builds a tree from the top by repeated splitting. The linkage decides the agglomerative tree. On the six points, single and complete linkage parted ways at the fourth merge. Single, complete and average linkage never lower the merge height, centroids compared by Euclidean distance can invert the tree, and single-link merges are the edges of a minimum spanning tree, which explains chaining. Those properties and the cost bounds are proved in Linkage properties of agglomerative clustering. The quadratic similarity matrix limits HAC to small collections. On 30 samples of 600 Reuters stories, single and complete linkage failed every time, for different reasons, and average linkage came close to k-means.
This closes the unit on clustering. Every collection in it, Cranfield and Reuters, was already in hand. On the web, a collection has to be gathered first: a program fetches every page, follows its links, and decides what to fetch next without overloading anyone's server. What a web crawler does begins the next unit, on web crawling, and describes how such a program works.
The worked example, the divisive trace, the centroid identity and the worked problem are recomputed by tools/experiments/clustering/hac_toy.py, the single-sample Reuters comparison by tools/experiments/clustering/reuters_kmeans.py, and the 30 samples by reuters_hac_samples.py, in the site repository.
References
- Cutting, D. R., Karger, D. R., Pedersen, J. O., and Tukey, J. W. (1992). Scatter/Gather: A cluster-based approach to browsing large document collections. In Proceedings of SIGIR 1992, 318–329. record · 3 pages
- Manning, C. D., Raghavan, P., and Schütze, H. (2008). Introduction to Information Retrieval, chapter 17. Cambridge University Press. record · 102 pages
- Milligan, G. W. (1979). Ultrametric hierarchical clustering algorithms. Psychometrika, 44(3), 343–346. record
- Steinbach, M., Karypis, G., and Kumar, V. (2000). A comparison of document clustering techniques. In KDD Workshop on Text Mining. record
Reviewed: verified, 16 Nov 2026 · checked against sources, 23 Nov 2026 · citations checked, 16 Nov 2026 · editorial review, 23 Nov 2026 · 13 revisions