Binary Search Tree: Insert, Search, Delete

medium
Unit 17 · Greedy & Trees0/3 to milestone

Implement a BST class (no balancing) storing unique integer keys:

  • insert(key) (ignore duplicates), contains(key)
  • delete(key): handle a leaf, a node with one child, and a node with two children (replace it with its in-order successor); no error if missing
  • inorder(): keys in sorted order
  • height(): number of nodes on the longest root-to-leaf path (0 for empty)
Pro problem

Unlock this and every premium problem across all tracks — plus hidden-test grading, advanced AI engineering modules and new content every week.

Start 7-day free trial
solution.py · Python 3.13
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Binary Search Tree: Insert, Search, Delete · TechGradify