Delete nodes greater than or equal to k in a BST
Given a BST and a value x, write a function to delete the nodes having values greater than or equal to x. The function will return the modified root.
Input BST 8 / \ 4 10 / \ / \ 3 5 9 11 Input X: 10 After deletion: 8 / \ 4 9 / \ 3 5
Basic properties of BST:
Thus it's clear whenever a root has a value greater than or equal to the input value X, the entire right subtree and root need to be deleted, but not the left one.
The above function actually builds the tree deleting the nodes having greater and equal value than X.
Example with Explanation: