AVL and BinarySearhTree

as per the video we need avl for the random inputs by user but instead of doing so much work to convert it into a BST at each step we can simply take a input in an array and then sort it and then can use that array for making a bst .so, why we need avl then.

Hi Kriti,

We use AVL trees because of its properties and complexities, Yes there can be other approaches also but their complexity will not be better than the AVL tree.

For eg.
In AVL trees we can insert a node in O(log N) time complexity in the worst case,
but in the approach that you have suggested for inserting a node, you have to sort the array first
and to sort an array time complexity will be O(NlogN) which is obviously greater than the time complexity of AVL tree to insert a node.

So, that’s why we need AVL trees.

Hope this helps you to understand the concept :slight_smile:

1 Like