LOGBOOK

HELP

Quiz Entry - updated: 2026.11.27

How can every comparison sort be drawn as a decision tree, and what do its paths and its height mean?

For a fixed input size $n$, each inner node is one comparison "$x_i < x_j$?", its two branches are the two answers, and each leaf is the order the algorithm outputs. A run on one input follows one root-to-leaf path, so the path length is that run's number of comparisons, and the height of the tree is the worst case.

Decision tree for sorting three elements a, b, c: five comparison nodes, six leaves, height 3

* The tree insertion-sort follows for three elements. The run on a = 2, b = 9, c = 4 asks three questions and outputs a c b, that is 2 4 9. *

Why such a tree exists at all: a deterministic comparison sort chooses its next comparison based only on the answers it has received so far. Two inputs that produce the same answers are therefore handled identically, step for step. So all possible runs for a given $n$ fit into one binary tree: start at the first comparison, branch on the answer, continue with whatever the algorithm asks next, and stop at a leaf when it knows enough to output the elements in a fixed order.

The algorithm never builds this tree. It is a way to picture all its possible runs at once. Every comparison sort has such a tree for every $n$, and different algorithms have differently shaped trees. That is what makes the model useful: a statement about all binary trees with enough leaves is a statement about all comparison sorts.

In the tree for three elements, two leaves sit at depth 2 (inputs where two answers already settle the order, such as a < b followed by b < c) and four at depth 3. The height, 3, is the number of comparisons for the unluckiest inputs.

Go deeper:

From Quiz: ADS / Sorting Lower Bound, Bucket-Sort and Radix-Sort | Updated: Nov 27, 2026