Binary Search Tree Costs
As with all data structures, there are costs to binary search trees. The BST's most significant cost is the lack of control over order of insertion. For example, the following traversal sequences have the same keys, but generate two different trees:
Notice that has a height of while has a height of Two different heights for the same set of keys! This shows that a BST's height depends on the order of key insertion.
Can we control the order of insertion? With what we have so far, no. Ultimately, how the keys are inserted is up to the user. If the user inserts the keys according to 's traversal sequence, then they'll get the tree But if they insert the keys according to then they'll get the tree
Because of this problem, we need a way to control the height of a binary search tree. Fortunately, there's a solution — AVL trees.