Question: Please use Python to implement Binary Tree Traversal AVL Tree Insertion and Deletion Please follow this guideline! The solution should contain exactly 1 file: main.py
Please use Python to implement
Binary Tree Traversal
AVL Tree Insertion and Deletion
Please follow this guideline!
The solution should contain exactly file: main.py for Python
You should start your program by initializing an empty AVL tree.
Your program takes one line as input. The input line contains n modification moves separated by spaces n The available modification moves are
Aint Character A followed by an int value between and : A means insert value into the AVL tree. If is already in the tree, do nothing.
Dint Character D followed by an int value between and : D means delete value into the AVL tree. If is not in the tree, do nothing.
Your input is then followed by exactly one finishing move PRE or POST or IN: If the finishing move is PRE, then you should print out the tree in its current situation in preorder. If the tree is empty, print out EMPTY. Otherwise, print out the values separated by spaces. POST and IN are handled similarly. You dont need to worry about invalid inputs.
need pass all the test cases!
need pass all
Sample input : A A A IN
Sample output :
Sample input : A A A PRE
Sample output :
Sample input : A D POST
Sample output : EMPTY
Important:
Test Case
Input: A D A A A A A D D A D D D D D A D A A A D D D D D D A D A D D A D A D D A A D A D D D A A D A A A D A D D D A D A D A A A D A D D D A D D D A A A A D A D A A A D D A D A A D D D D D A A D A A A D A A PRE
Expected Output:
Test Case
Input: A D A A A A A A A A D A D D D D D D D A A A D D D D A D D D A D D D A D D D D A A D D D D A A A D D A A A D D D D D A A A A D D D D D A D A A D D A A A D D D D D D A D D D D A D D A D A A A D D D A D PRE
Expected Output:
Test Case
Input: D D A D D A A D D A D D A A A A D D D D D A A D D D D A A A A D D D A D D D A A D A A A D A D A A A A D A D D A D A D A D D D A D A A A A A A A A A D D D A D D A A A D A D D D D A A A A A D A D A A D PRE
Expected Output:
Test Case
Input: A A A A A D A A D A D A A A A A A A A A D D A A D D A D A A A A D A D A A D D A D D A A D A D A D A A D A D A D A D D D D A A D D A D A A D D D D D A A A D D D A D D D A D A A A A D A D A A D A D A D POST
Expected Output:
