Question presented to candidate: "Explain what a binary search tree is. Then, in Python, show me how search, insert and delete work, and tell me what their running time depends on."
What a strong answer should cover:
- The BST property: every key in a node's left subtree is smaller, every key in its right subtree is larger โ for the whole subtree, not just the children.
- Search, insert and delete each walk one root-to-leaf path, so they cost O(h), where h is the height.
- The three delete cases (leaf, one child, two children) and the in-order successor.
- In-order traversal visits the keys in sorted order.
- Height is the whole story: about log2(n) when balanced, n โ 1 when keys arrive sorted; self-balancing trees (AVL, red-black) keep it O(log n).
- Python specifics: there is no BST in the standard library (
dictis a hash table,bisectworks on a sorted list), and a recursive insert on sorted keys hits the default recursion limit of 1000.
Code / implementation expected: Optional โ a small Node class with insert, search and delete in Python 3.