Modelcore
Decision tree model
Also called decision tree, decision tree complexity.
Algorithms as trees of queries whose cost is the depth; gives lower bounds such as the sorting bound.
The decision tree model describes an algorithm as a rooted tree. Each inner node asks one query about the input, each branch is one answer, and each leaf gives the output. The cost of the algorithm on an input is the number of queries on the path that the input follows, and the cost of the algorithm is the height of the tree, the largest number of queries on any path. Only queries cost: all other work is free, so a lower bound in this model holds for every algorithm that learns about its input through these queries, however fast its other steps are.
The machine
Fix a set of inputs, a set of outputs and a function to compute. Fix a set of allowed queries. A query is a function where is a finite set of answers. In a binary tree, .
A decision tree over is a rooted tree with these parts.
- Each inner node has a query and, for each answer , at most one child .
- Each leaf has a label in .
The tree runs on an input as follows. It starts at the root. At an inner node it computes and moves to the child . At a leaf it outputs the label of the leaf. The tree computes when, for each , the run on reaches a child that exists and ends with the output .
The tree is a fixed object, not a program with a loop. It is built for one problem size. So the model is non-uniform: an algorithm for all sizes is a family of trees, one for each size.
Three common choices of :
- Comparison trees. The input is a sequence of keys, and a query is "?" with two answers, or a three-way comparison of and with answers less, equal and greater. This is the comparison model.
- Boolean decision trees. The input is a bit string , and a query reads one bit .
- Algebraic trees. A query asks for the sign of a polynomial of the inputs. See algebraic decision trees, linear decision trees and algebraic computation trees.
What it counts
The depth of a leaf is the number of edges from the root to the leaf. The height of a tree is the largest depth of a leaf. Let be the least height of a decision tree over that computes . This is the worst-case cost of in the model: some input needs queries, and no algorithm of the model does better on its worst input.
For a probability distribution on , the average cost of a tree is . A randomized algorithm is a probability distribution over trees. Its expected cost on an input is the average over this distribution. The randomized cost of the algorithm is the largest expected cost over all inputs . See the Yao minimax principle.
The model does not count the size of the tree, the memory, or any work between queries.
Relation to other models
- The comparison model is the decision tree model with equal to the comparisons of two input keys. A deterministic comparison-based algorithm, such as merge sort, gives one tree for each input size (a randomized one gives a distribution over such trees), and the number of comparisons that it makes on an input is the length of the path of that input.
- A branching program is a decision tree in which different paths can meet again, so it is a directed acyclic graph. A decision tree is a branching program of which the graph is a tree. The graph form can be much smaller.
- The cell-probe model and the bit-probe model are decision trees in which a query reads one cell or one bit of a data structure.
- The model gives only lower bounds that hold for algorithms that use the queries of . An algorithm with other operations, such as the arithmetic of counting sort or radix sort, is not a tree over comparisons and can be faster.
Known results in the model
The counting lemma
Lemma 1. A tree in which each inner node has at most children and every leaf has depth at most has at most leaves.
Proof. By induction on . If , the tree is a single leaf, and . Let and suppose the claim holds for . The root is an inner node or a leaf. If it is a leaf, the tree has 1 leaf, and when . Otherwise the root has at most subtrees, and each is a tree of which every leaf has depth at most in the subtree. By the induction hypothesis each subtree has at most leaves. So the tree has at most leaves. ∎
Corollary 2 (counting bound). This is the information-theoretic bound, a counting argument on the leaves, and it is the base of the decision tree method for lower bounds. Let a decision tree with at most answers for each query compute . Let be its height. Then , so
Proof. For each there is an input with . The run on ends at a leaf with label . So the labels of the leaves cover , and the tree has at least leaves. By Lemma 1 the tree has at most leaves. So . Take on both sides. The height is an integer, so . ∎
Sorting
The sorting problem asks for the keys in order. Take the inputs to be the sequences of distinct keys, written as permutations of . The output is the permutation that sorts the input, so the outputs of two different inputs are different. Comparisons of distinct keys have two answers, "less" and "greater", so .
Theorem 3. Each comparison tree that sorts distinct keys has height at least . Also , so the height is .
Proof. The function maps each input to its sorting permutation, so . Corollary 2 with gives . For the second claim, , because the term is one term of a sum of positive terms. So , and with . For this is at least , because gives . ∎
A three-way comparison tree has three children for each node, and the "equal" child is never reached on distinct keys. So removing it leaves a tree with two children, and the same bound holds.
The table shows the bound for small . The last column is the least worst-case number of comparisons of any comparison sort, as Knuth tabulates it in Section 5.3.1.
| least worst case | ||||
|---|---|---|---|---|
| 3 | 6 | 2.585 | 3 | 3 |
| 4 | 24 | 4.585 | 5 | 5 |
| 5 | 120 | 6.907 | 7 | 7 |
| 6 | 720 | 9.492 | 10 | 10 |
| 10 | 3628800 | 21.791 | 22 | 22 |
| 12 | 479001600 | 28.835 | 29 | 30 |
The bound is tight for , and it is not tight for : the count argument only counts leaves and does not say that a tree with leaves of nearly equal depth exists. The Ford and Johnson algorithm reaches the values of the last column. For large the bound is tight up to the linear term: merge sort uses at most comparisons, which is . See the comparison sort lower bound.
Example, . Call the keys . The tree below sorts them with at most 3 comparisons. Each line is a node. Indentation shows the depth.
a < b ?
yes: b < c ?
yes: output a b c
no: a < c ?
yes: output a c b
no: output c a b
no: b < c ?
yes: a < c ?
yes: output b a c
no: output b c a
no: output c b a
The tree has 6 leaves, two at depth 2 and four at depth 3. The height is 3, which is . No tree of height 2 exists, because a binary tree of height 2 has at most 4 leaves.
The average depth
Lemma 4. A binary tree in which each inner node has exactly two children and that has leaves has leaf depths that add up to at least .
Proof. By strong induction on . For the tree is one leaf of depth 0, and . Let . The root has two subtrees with and leaves, where and . Each leaf is one level deeper in the whole tree than in its subtree. Let be the sum of the leaf depths. Then . By the induction hypothesis . The function is convex for , because . So . Hence . ∎
Theorem 5. Let a comparison tree sort distinct keys. If the input is a uniformly random permutation, the expected number of comparisons is at least .
Proof. Each input reaches one leaf. Two different inputs have different sorted outputs, so they reach different leaves. So exactly leaves are reached, and each is reached by one input. The average depth is times the sum of the depths of these leaves. Delete all nodes that no input reaches. Some inner nodes now have one child. Remove each such node and join its parent to its child. This step does not increase the depth of a leaf. The result is a tree with leaves in which each inner node has two children. By Lemma 4 its leaf depths add up to at least . The depths in the original tree are at least as large. So the average is at least . ∎
Two consequences follow. First, the bound of Theorem 3 holds for the average case too: an average of at least gives a worst case of at least . Second, it holds for randomized algorithms. A randomized comparison sort is a distribution over trees, each of which sorts. By Theorem 5, on a uniformly random input each tree has an average of at least . So the average over the distribution is at least , and some input has expected cost at least .
Search in a sorted array
The array is known to be sorted. The order of the array is known, so a comparison of two array entries gives no information. A query compares with one entry , with the answers less, equal and greater. The algorithm must output an index with , or the word "absent".
Theorem 6. Each comparison tree that solves this problem on all inputs has height at least .
Proof. Use the array and consider the inputs . For each , the run on passes through a node that compares with . Suppose not, for some . The run on ends at a leaf. This leaf must say "found at ". Now take . Each comparison on the path is with some with , and and give the same answer: both are greater than for , and both are less than for . So the run on ends at the same leaf. But is not in the array, so the answer is wrong. This is a contradiction.
So there are at least nodes in the tree, one for each index, and they are different nodes. Let the node for be the first node on the run for that compares with . Every earlier answer on this run is "less" or "greater", because "equal" can occur only when is compared with . The nodes that are reached by "less" and "greater" answers only are at most at depth . The nodes are inner nodes, so their depths are in . Hence and . The height is an integer. ∎
Binary search makes at most probes. For both numbers are 3, and for both are 4. So the bound is tight for each . See sorted search lower bound and search in a sorted array.
A bound that counting does not give
Counting needs many outputs. The function has two outputs, so Corollary 2 gives only . For the parity function, a different argument gives a much better bound.
Theorem 7. Every Boolean decision tree that computes the parity has height at least , and some tree has height . So .
Proof. The tree that reads in order has height . Now take any tree of height less than . Take a leaf and an input that reaches it. The path has fewer than queries, so some index is not queried on it. Let be with bit changed. The run on gives the same answers to the same queries, so it reaches the same leaf. The two inputs have different parity but the same output. So the tree is wrong. ∎
This is an adversary argument: the adversary answers each query and keeps one free bit until the end.
References
- Cormen, Leiserson, Rivest and Stein, Introduction to Algorithms, fourth edition, Section 8.1
- Donald E. Knuth, The Art of Computer Programming, Volume 3, second edition, Section 5.3.1
- Robert Sedgewick and Kevin Wayne, Algorithms, fourth edition, Section 2.2, Proposition I
About this page
The build computes these levels from the evidence in the repository. Each row says what the next level needs. Read what the levels mean.
| Ladder | Level | What the next level needs |
|---|---|---|
| Human proof | H0 no proof |
|
| Lean | L0 no Lean part |
|
| Visual | V0 none |
|
| Writing | W4 complete |
|
Tag F3DC2S Edit this page History Report an error Markdown JSON