2dbi
Home/Blinkit/Explain how to remove a node from a BST
BBlinkit·DSAL2DSA Phone Screen

Explain how to remove a node from a BST

Deleting a node from a Binary Search Tree (BST) while preserving the BST property. Three cases to handle:

  • Node is a leaf: simply remove it.
  • Node has one child: replace the node with its child.
  • Node has two children: find the in-order successor (leftmost node of right subtree) or in-order predecessor (rightmost node of left subtree), copy its value to the target node, then delete that successor/predecessor node recursively.

Time complexity is O(h) where h is tree height — O(log n) for balanced trees, O(n) worst case for skewed trees. Candidates are expected to independently identify the two-children case without hints; knowing both the successor and predecessor approaches is a plus.

added …
排行榜薪资
语言
账号