I have been drawing some binary comparison trees, which correspond to compares made to sort an array, and I was wondering if there is any formula to determine the height of a comparison tree for an array of N values, in Sedgewick's algorithms 4th ed. book for N = 3, the height of a comparison tree is 3.
He draws his comparison trees in such a way that all the internal nodes and the root represent the comparisons, for example (i:j) means compare a[i] to a[j], if a[i] < a[j] then the left subtree represents all the rest of the comparisons that we need to make, to finish the sort, and the leaves represent the permutations that we get after the sort. For example the left path for N = 4 is : (0:1), (1:2), (2:3), (0,1,2,3).
After I drew a tree for N = 4, the height was not 4, more specifically, an example would be the following path : (0:1),(1:2),(2:3), here a > a (3:1),(3:0),(3,0,1,2). So is there a formula?
In the example above we first find out that a < a < a and then we find out that a > a, so we need to compare a to a and a, so far the path length is 4, but then we add the leaf (3,0,1,2) and now the path length is 5.