Question: Create a Python program for AVL Tree that stores or deletes integers given by the user. Asks the user to enter a positive integer number,

Create a Python program for AVL Tree that stores or deletes integers given by the user. Asks the user to enter a positive integer number, add to AVL tree if the number does not exist in the tree else delete it the AVL tree, if a negative number is entered, then exit the program. After each insertion and deletion, the program prints the current tree using the printHelper method. Use Recursive implementations in the insertion and deletion functions: insert_node, delete_node. Print the tree using tree traversals depth-first Post order. The complexity of the insertion and deletion operations is O(log n). The entire program must run in logarithmic time. For searching a node exist or not, modify the `insert_node` method to return the updated node after insertion or deletion, and then use that node to check if the value exists in the tree. Create a main function to execute the program. In the main function, if the root is empty, insert in the root, otherwise, insert left or right, then Update the height, If unbalanced (tallest right - balanceFactor >1), rotate right. If unbalanced (tallest left - balanceFactor <-1), rotate left. If the node is the one to delete, pull right if left is empty, or pull left if right is empty, otherwise, pull the minimum data at right. Tree constructor is not needed.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!