0

I am. Not getting the correct values... Pls check the problem

Avl tree Datastructure https://code.sololearn.com/ca9A14a8a0a1/?ref=app

25th Jan 2021, 8:17 PM
Aditya Salabh
Aditya Salabh - avatar
5 Antworten
+ 1
Aditya Salabh did you see what is happening? When the top node rotates, it is no longer the root. But the program continues to add nodes as if the original root were in place. The tree ends up unbalanced, and printing the tree from the old root fails to show the whole left side (6 and 9) because the old root is now a child node.
29th Jan 2021, 10:06 PM
Brian
Brian - avatar
+ 1
Got it... Finally
30th Jan 2021, 4:11 AM
Aditya Salabh
Aditya Salabh - avatar
0
The reason that it fails to print nodes 6 and 9 is due to the root pointing to the wrong node. When the rotate methods get called, check whether the root should get updated.
28th Jan 2021, 10:12 AM
Brian
Brian - avatar
0
Brian not able to find it
28th Jan 2021, 4:12 PM
Aditya Salabh
Aditya Salabh - avatar
0
Try this to see what I mean. Insert this code at line 46: global root if cur_node == root: print ("The top node rotated right.")
28th Jan 2021, 5:49 PM
Brian
Brian - avatar