Showing:
Handle Score
@Ibrahim Nash 5761
@akhayrutdinov 5111
@mb1973 4989
@Quandray 4944
@saiujwal13083 4506
@sanjay05 3762
@marius_valentin_dragoi 3516
@sushant_a 3459
@verma_ji 3341
@KshamaGupta 3318
AVL Tree Insertion
Hard Accuracy: 34.92% Submissions: 7643 Points: 8

Given a AVL tree and N values to be inserted in the tree. Write a function to insert a given value into the tree.

Example 1:

â€‹N = 3
Values to be inserted = {5,1,4}

Input:
Value to be inserted = 5
Output:
5

Input :
Value to be inserted = 1
Output:
5
/
1

â€‹Input :
Value to be inserted = 4
Output:
4
/ \
1   5

You dont need to read input or print anything. Complete the function insertToAVL() which takes the root of the tree and the value of the node to be inserted as input parameters and returns the root of the modified tree.

Note:
The tree will be checked after each insertion.
If it violates the properties of balanced BST, an error message will be printed followed by the inorder traversal of the tree at that moment.
If instead all insertions are successful, inorder traversal of tree will be printed.

Expected Time Complexity: O(log N)
Expected Auxiliary Space: O(height of tree)

Constraints:
1 ≤ N ≤ 500