What is the smallest possible depth of a leaf in a decision tree?.Heapsort and merge sort are optimal comparison sorts.Therefore, any comparison-based sorting algorithm must make at least O(nlogn) comparisons to sort the input array.
![sherlock subree sherlock subree](https://sherlockblaze.com/resources/img/cs/trees/avl_situation2.png)
=> n! ≤ 2^h => h ≥ log(n!) From Stirling’s formula, n! > (n/e)^n => h ≥ log(n/e)^n => h ≥ n(log n - log e) => h ≥ nlogn - nloge => h > O(nlogn) Another side, we know that the binary tree of height h has no more than 2^h leaves. Since there are n! permutations of n elements, each permutation representing a distinct sorted order, the tree must have at least n! leaves. Proof: Consider a decision tree of height h that sorts n elements. Idea: Any decision tree that sorts n elements has a height always greater than nlogn.
![sherlock subree sherlock subree](https://sherlockblaze.com/resources/img/cs/trees/avl_situation3.png)
A lower bound on the heights of decision trees is therefore a lower bound on the running time of any comparison sort algorithm.
#SHERLOCK SUBREE FULL#
A decision tree is a full binary tree structure that represents the comparisons performed by a sorting algorithm when it operates on an input of a given size.
![sherlock subree sherlock subree](https://sherlockblaze.com/resources/img/cs/trees/avl_situation1&4_solution_example.png)
We can visualize comparison sorts in terms of decision trees.
![sherlock subree sherlock subree](https://studyalgorithms.com/wp-content/uploads/2014/10/sample_tree.png)
We call such sorting algorithms comparison sort, where we use only comparisons between elements to gain order information about an input sequence A, A. These algorithms determine the sorted order based only on the comparisons between the input elements. We have already discussed several sorting algorithms that can sort n numbers in both O(n²) and O(nlogn) time complexity in the worst case.