is there a way to fix this tree? (self-balancing-binary-search python)

28 Views Asked by At

When trying to print a tree the root takes the value of 20 instead of 80 I guess the problem is inside the library near line 297 bur can't figure out how



from self_balancing_binary_search_tree import SBBST

ST = SBBST()

nums = [80,3,20,95,70] # random numbers

ST = SBBST(nums)

print(ST)
1

There are 1 best solutions below

0
Aditya Gupta On

As far as I know,

  • 80 is created as root
  • then 3 is inserted to the left of root
  • then 20 is inserted to the right of 3.
  • We will apply LR rotation
  • 20 becomes the root, 3 is left, 80 is right.
  • then inserting 95 at the right of 80 and 70 at left of 80.

hence 20 is root.

Hope this solves any confusion here.
:D