Bird
Raised Fist0
Data Structures Theoryknowledge~20 mins

Deletion in BST in Data Structures Theory - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
BST Deletion Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding Deletion Cases in BST

Which of the following correctly describes the case when deleting a node with two children in a Binary Search Tree (BST)?

ADelete the node and then reinsert all nodes from its right subtree.
BSimply remove the node and connect its left child directly to its parent.
CReplace the node with its left child only, ignoring the right subtree.
DReplace the node with its in-order predecessor or successor, then delete that predecessor or successor node.
Attempts:
2 left
💡 Hint

Think about how to maintain BST properties after deletion.

📋 Factual
intermediate
1:30remaining
Number of Children in BST Deletion

How many children can a node have in a BST when it is deleted using the simplest case?

AZero or one child
BExactly two children
CAt least one child
DAny number of children
Attempts:
2 left
💡 Hint

Consider the easiest deletion cases first.

🔍 Analysis
advanced
2:30remaining
Result of Deleting Root Node with Two Children

Given a BST where the root node has two children, what will be the root node's value after deleting the root?

Data Structures Theory
Initial BST root value: 15
Root has left child 10 and right child 20.
After deleting root, which value replaces it?
A10
BThe minimum value in the right subtree
C20
DThe maximum value in the left subtree
Attempts:
2 left
💡 Hint

Recall the in-order successor concept.

Comparison
advanced
2:30remaining
Comparing In-Order Predecessor and Successor in Deletion

Which statement correctly compares using the in-order predecessor versus the in-order successor when deleting a node with two children in a BST?

ABoth maintain BST properties, but predecessor is maximum in left subtree, successor is minimum in right subtree.
BPredecessor is always smaller than the node, successor is always larger, so only successor can be used.
CPredecessor and successor are the same node, so either can be used interchangeably without difference.
DUsing predecessor breaks BST properties, only successor maintains correct order.
Attempts:
2 left
💡 Hint

Think about where predecessor and successor come from in the BST.

Reasoning
expert
3:00remaining
Effect of Deleting a Leaf Node on BST Height

What is the effect on the height of a BST after deleting a leaf node?

AThe height increases because the tree becomes unbalanced.
BThe height remains the same because leaf nodes do not affect height.
CThe height decreases by one only if the leaf was on the longest path.
DThe height always decreases by one regardless of the leaf's position.
Attempts:
2 left
💡 Hint

Consider how height is defined in a tree.

Practice

(1/5)
1. Which of the following is NOT a case handled during deletion in a Binary Search Tree (BST)?
easy
A. Deleting a node with two children
B. Deleting a node with one child
C. Deleting a node with three children
D. Deleting a node with no children (leaf node)

Solution

  1. Step 1: Understand BST node children possibilities

    In a BST, each node can have zero, one, or two children. There is no case of three children because BST nodes have at most two children.
  2. Step 2: Identify valid deletion cases

    Deletion handles nodes with zero, one, or two children. Three children is impossible, so it is not a valid case.
  3. Final Answer:

    Deleting a node with three children -> Option C
  4. Quick Check:

    BST nodes have max two children = Deleting node with three children [OK]
Hint: Remember BST nodes have max two children only [OK]
Common Mistakes:
  • Thinking a node can have more than two children
  • Confusing deletion cases with other tree types
  • Ignoring the leaf node deletion case
2. Which of the following is the correct step to delete a node with two children in a BST?
easy
A. Replace the node with its parent node
B. Replace the node with its inorder predecessor (largest in left subtree)
C. Replace the node with any leaf node
D. Replace the node with its inorder successor (smallest in right subtree)

Solution

  1. Step 1: Identify deletion method for two children

    When deleting a node with two children, the standard method is to replace it with its inorder successor, which is the smallest node in its right subtree.
  2. Step 2: Confirm replacement correctness

    The inorder successor maintains BST properties after replacement, unlike arbitrary leaf or parent nodes.
  3. Final Answer:

    Replace the node with its inorder successor (smallest in right subtree) -> Option D
  4. Quick Check:

    Two children deletion uses inorder successor = Replace the node with its inorder successor (smallest in right subtree) [OK]
Hint: Use inorder successor for two-child node deletion [OK]
Common Mistakes:
  • Using inorder predecessor instead of successor
  • Replacing with any leaf node
  • Replacing with parent node
3. Consider the BST below:
      15
     /  \
    10  20
   /    / \
  8    17 25

If we delete node 20, what will be the new right child of 15?
medium
A. 17
B. 25
C. 20
D. 15

Solution

  1. Step 1: Identify node to delete and its children

    Node 20 has two children: 17 (left) and 25 (right).
  2. Step 2: Find inorder successor of node 20

    The inorder successor is the smallest node in the right subtree of 20, which is 25. But since 25 has no left child, 25 is the successor.
  3. Step 3: Replace node 20 with its inorder successor

    Replace 20 with 25. Then remove original 25 node (which is a leaf). The new right child of 15 becomes 25.
  4. Final Answer:

    25 -> Option B
  5. Quick Check:

    Inorder successor of 20 is 25 = 25 [OK]
Hint: Replace two-child node with inorder successor (smallest right) [OK]
Common Mistakes:
  • Choosing 17 as successor instead of 25
  • Not updating parent's child pointer
  • Confusing inorder predecessor with successor
4. What is the error in the following deletion logic for a BST node with one child?
if node.left is not None:
    return node.left
else:
    return node.right
medium
A. It incorrectly returns the child without updating parent links
B. It should delete both children instead
C. It only works for leaf nodes
D. It should replace node with inorder successor

Solution

  1. Step 1: Analyze deletion logic for one child

    The code returns the child node directly but does not update the parent's pointer to this child, which breaks the BST links.
  2. Step 2: Identify missing link update

    Proper deletion requires updating the parent's child pointer to the returned node to maintain tree structure.
  3. Final Answer:

    It incorrectly returns the child without updating parent links -> Option A
  4. Quick Check:

    Missing parent link update = It incorrectly returns the child without updating parent links [OK]
Hint: Always update parent links when deleting nodes [OK]
Common Mistakes:
  • Ignoring parent pointer updates
  • Deleting both children unnecessarily
  • Using inorder successor for one-child deletion
5. You have a BST where you want to delete the root node which has two children. The inorder successor is the immediate right child with no left child. After replacing the root with the inorder successor, what must you do next to maintain BST properties?
hard
A. Replace the inorder successor with its right child
B. Replace the inorder successor with its left child
C. Do nothing, the tree is already valid
D. Remove the inorder successor node from its original position

Solution

  1. Step 1: Replace root with inorder successor

    The root is replaced by its inorder successor, which is the immediate right child with no left child.
  2. Step 2: Adjust inorder successor's original position

    Since the inorder successor has no left child, replace it with its right child (which may be None) to maintain BST links.
  3. Final Answer:

    Replace the inorder successor with its right child -> Option A
  4. Quick Check:

    Inorder successor replaced by right child = Replace the inorder successor with its right child [OK]
Hint: Replace successor with its right child after root replacement [OK]
Common Mistakes:
  • Forgetting to remove successor from original spot
  • Replacing successor with left child (which doesn't exist)
  • Assuming no further action needed