Why the below pseudo code where x is a value, wt is weight factor and t is root node can't insert?
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)
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
Answer: Option A
A. O(1)
B. O(log n)
C. O(n)
D. O(n log n)
Which traversal method of a BST will produce a sorted sequence of node values?
A. Inorder
B. Preorder
C. Postorder
D. Level-order
What is the maximum number of children a node in a Binary Search Tree (BST) can have?
A. 1
B. 2
C. 3
D. Any number
How can you determine if a Binary Tree is a Binary Search Tree (BST)?
A. Verify if all nodes in the left subtree are less than the root and all nodes in the right subtree are greater than the root.
B. Check if the tree is balanced.
C. Ensure all nodes have exactly two children.
D. Verify the height of the tree.

Join The Discussion