Bottom-up merging: building the tree
Hierarchical agglomerative clustering starts with each point as its own cluster. Iteratively, the two closest clusters merge. As they merge, a dendrogram (tree diagram) records the merge and the distance at which it occurred. Keep merging until all points form a single cluster at the root. The dendrogram visually shows the merging history.
Unlike K-means, you do not need to specify the number of clusters up front. Instead, you 'cut' the dendrogram at any height (distance threshold) to retrieve clusters. Cut high, get few large clusters. Cut low, get many small clusters. This flexibility is powerful when cluster count is unknown.
Linkage: how distance is measured between clusters
The choice of linkage (how to compute distance between two clusters) changes the tree structure. Single linkage uses the distance between the two closest points in the clusters (can create long 'chains'). Complete linkage uses the farthest points (tends to form compact clusters). Average linkage uses the mean distance between all pairs of points. Ward linkage merges clusters to minimize the variance within resulting clusters, favoring balanced trees.
Single linkage is fast but prone to chaining (elongated clusters). Complete and Ward linkage produce more balanced dendrograms and tend to match human-perceived clusters better. Hierarchical clustering is slower than K-means on large datasets (quadratic or cubic time complexity), but the dendrogram provides richer information than a flat cluster assignment, making it popular in exploratory analysis and biology (e.g., gene sequencing).