## Definition of a Balanced Tree

The constraint is generally applied recursively to every subtree. That is, the tree is only balanced if: The left and right subtrees’ heights differ by at most one, AND The left subtree is balanced, AND The right subtree is balanced According to this, the next tree is balanced: A / \ B C / / … Read more

## Tail recursive function to find depth of a tree in Ocaml

You can trivially do this by turning the function into CPS (Continuation Passing Style). The idea is that instead of calling depth left, and then computing things based on this result, you call depth left (fun dleft -> …), where the second argument is “what to compute once the result (dleft) is available”. let depth … Read more

## With ‘ N ‘ no of nodes, how many different Binary and Binary Search Trees possible?

Total no of Binary Trees are = Summing over i gives the total number of binary search trees with n nodes. The base case is t(0) = 1 and t(1) = 1, i.e. there is one empty BST and there is one BST with one node. So, In general you can compute total no of … Read more