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 1 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 (1<= n <=100). The available modification moves are
Aint (Character A followed by an int value between 1 and 100): A3 means insert value 3 into the AVL tree. If 3 is already in the tree, do nothing.
Dint (Character D followed by an int value between 1 and 100): D3 means delete value 3 into the AVL tree. If 3 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 pre-order. 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 1: A1 A2 A3 IN
Sample output 1: 123
Sample input 2: A1 A2 A3 PRE
Sample output 2: 213
Sample input 3: A1 D1 POST
Sample output 3: EMPTY
Important:
Test Case 13
Input: A69 D16 A31 A98 A45 A17 A50 D17 D44 A87 D100 D73 D95 D53 D75 A30 D6 A30 A46 A42 D33 D26 D78 D56 D79 D69 A87 D75 A74 D89 D89 A43 D23 A58 D82 D74 A90 A87 D98 A75 D60 D95 D35 A38 A63 D99 A3 A12 A81 D63 A83 D61 D57 D17 A65 D84 A43 D82 A92 A23 A74 D28 A11 D66 D83 D47 A88 D10 D56 D100 A100 A53 A93 A82 D52 A25 D34 A90 A43 A21 D94 D73 A29 D23 A93 A92 D92 D74 D19 D3 D56 A81 A43 D28 A72 A49 A20 D98 A97 A21 PRE
Expected Output: 503021121120252942313845434649816558537572908782889793100
Test Case 14
Input: A60 D39 A27 A5 A44 A17 A75 A69 A63 A50 D79 A92 D59 D72 D6 D17 D57 D58 D67 A67 A13 A61 D7 D21 D64 D69 A91 D26 D18 D81 A89 D20 D17 D6 A88 D2 D84 D26 D93 A96 A69 D89 D30 D12 D24 A60 A26 A17 D54 D52 A70 A88 A47 D94 D9 D43 D73 D33 A10 A72 A77 A61 D90 D22 D27 D6 D31 A100 D24 A78 A54 D57 D64 A27 A55 A73 D84 D100 D76 D13 D52 D43 A32 D12 D29 D78 D79 A31 D25 D25 A94 D100 A70 A6 A21 D52 D33 D12 A95 D76 PRE
Expected Output: 6032261056172127314744545055706763616988757273779291959496
Test Case 20
Input: D29 D7 A43 D28 D90 A82 A68 D56 D46 A58 D26 D34 A46 A56 A84 A55 D34 D98 D33 D45 D35 A52 A31 D73 D62 D61 D92 A43 A100 A81 A83 D10 D82 D58 A91 D20 D7 D90 A28 A93 D2 A50 A7 A9 D91 A5 D51 A66 A56 A40 A74 D66 A57 D35 D64 A95 D73 A24 D23 A13 D98 D1 D74 A22 D69 A24 A33 A71 A58 A9 A77 A29 A98 A64 D50 D47 D33 A72 D21 D93 A4 A79 A61 D61 A34 D82 D71 D65 D8 A96 A25 A62 A31 A87 D20 A13 D80 A36 A56 D51 PRE
Expected Output: 5631954724132228252946403436435255816858576462777279958483879896100
Test Case 26
Input: A63 A1 A40 A82 A67 D71 A49 A14 D31 A3 D87 A91 A52 A27 A39 A25 A97 A4 A65 A23 D13 D85 A40 A59 D44 D51 A25 D61 A16 A31 A92 A24 D14 A4 D54 A1 A29 D44 D99 A57 D52 D82 A6 A80 D30 A13 D27 A46 D5 A36 A53 D11 A60 D31 A86 D69 A37 D15 D27 D41 D79 A85 A8 D90 D59 A62 D32 A81 A56 D29 D78 D14 D99 D34 A17 A8 A94 D53 D55 D9 A68 D79 D43 D88 A94 D93 A60 A92 A5 A79 D92 A63 D45 A85 A87 D9 A53 D66 A5 D41 POST
Expected Output: 135861716134243639372523465356496260576579

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 Programming Questions!