WeightBalanceTreeNode insert(int x, int wt, WeightBalanceTreeNode k) :
if (k == null)
k = new WeightBalanceTreeNode(x, wt, null, null)
else if (x < t.element) :
k.left = insert (x, wt, k.left)
if (k.left.weight < k.weight)
k = rotateWithRightChild (k)
else if (x > t.element) :
k.right = insert (x, wt, k.right)
if (k.right.weight < k.weight)
k = rotateWithLeftChild (k)
a) when x>t. element Rotate-with-left-child should take place and vice versa
b) the logic is incorrect
c) the condition for rotating children is wrong
d) insertion cannot be performed in weight balanced trees
Why the below pseudo code where x is a value, wt is weight factor and t is root node can’t insert?
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
Why the below pseudo code where x is a value, wt is weight factor and t is root node can’t insert?
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!