StudyG Logo
Study G
Concept Breakdowns

Binary Search Tree Insertion and Deletion

These flashcards cover BST insertion and deletion — operations tested in CS data structures courses and coding interviews. A BST maintains sorted order through the invariant that left children are smaller and right children are larger. Deletion is the trickiest operation, requiring handling of three distinct cases based on node structure.

Interactive Deck

5 Cards
1
Front

What is the BST property?

Click to reveal
1
Back

For every node N:

  • Left subtree: all values < N
  • Right subtree: all values > N This holds recursively for every node in the tree.
2
Front

How does BST insertion work?

Click to reveal
2
Back

Insert: Compare value to current node. Go left if smaller, right if larger. Repeat until reaching null — insert node there. Time: O(h), where h = tree height.

3
Front

BST deletion — node with two children

Click to reveal
3
Back

Replace node with its in-order successor (smallest in right subtree) or in-order predecessor (largest in left subtree), then delete the successor/predecessor from its original position.

4
Locked

BST deletion — three cases

5
Locked

What is a degenerate BST?

Master this topic effortlessly.

Study G helps you master any topic effortlessly using proven learning algorithms and smart review timing

Download Study G

Frequently Asked Questions

What is the time complexity of BST operations?

For a balanced BST: O(log n) for search, insert, and delete. For a degenerate BST (sorted insertions): O(n) worst case. Self-balancing trees (AVL, Red-Black) guarantee O(log n) always.

Why is deletion harder than insertion in a BST?

Insertion always adds a leaf node — straightforward. Deletion must maintain BST property while restructuring the tree, requiring three different strategies depending on whether the deleted node has zero, one, or two children.

What is an in-order traversal of a BST?

In-order traversal (left → root → right) of a BST produces nodes in sorted ascending order. This property is used in deletion to find the in-order successor and is tested frequently in interviews.