#C11189. AVL Tree Operations
AVL Tree Operations
AVL Tree Operations
This problem requires you to implement an AVL tree that supports insertion, deletion, and inorder traversal. An AVL tree is a self-balancing binary search tree. For any node in the tree, the height difference between its left and right subtrees, given by \( |\text{height}(left) - \text{height}(right)| \), is at most 1.
You are given a series of operations. Each operation is either an insertion or deletion. After processing all operations, print the keys of the AVL tree in non-decreasing order (i.e., the result of an inorder traversal).
Implement the following operations:
- Insert Operation: Insert a key into the AVL tree.
- Delete Operation: Delete a key from the AVL tree. If the key does not exist, no operation is performed.
The balancing of the AVL tree must be maintained after every insertion or deletion using appropriate rotations.
inputFormat
The first line contains an integer \( Q \) which denotes the total number of operations.
Each of the following \( Q \) lines contains an operation in one of the following formats:
I x
wherex
is an integer to be inserted into the AVL tree.D x
wherex
is an integer to be deleted from the AVL tree.
Note: If a delete operation is requested for a key that does not exist in the tree, simply ignore it.
outputFormat
Output a single line containing the keys of the AVL tree in non-decreasing order (obtained by an inorder traversal), separated by a single space.
## sample6
I 10
I 20
I 30
I 40
I 50
I 25
10 20 25 30 40 50