Take a positive integer (say K) as an input from the user. Generate all the K! BST from numbers {1,2,…,K}. For each generated BST, calculate the number of comparisons between the numbers required to generate that particular BST.
Enter a positive integer K = 3
Total number of generated BST = 6
Number of comparisons required to generate BST from permutations <1,2,3> = 3
Number of comparisons required to generate BST from permutations <1,3,2> = 3
Number of comparisons required to generate BST from permutations <2,1,3> = 2
Number of comparisons required to generate BST from permutations <2,3,1> = 2
Number of comparisons required to generate BST from permutations <3,1,2> = 3
Number of comparisons required to generate BST from permutations <3,2,1> = 3