Question presented to candidate: "You will be coding in Python. Before we start, tell me the time complexity of the basic operations โ access, search, insert and delete โ on an array, a hash map and a balanced binary search tree, and which Python types you would use for each."
What a strong answer should cover:
- Dynamic array: O(1) index access, O(1) amortized append, O(n) insert or delete at the front or middle (elements shift), O(n) search, O(log n) search if sorted.
- Hash map: O(1) average insert, lookup and delete; O(n) worst case under collisions; no ordering of keys.
- Balanced BST: O(log n) insert, delete and lookup because the height stays about log n; also min, max, floor, ceiling and ordered iteration; an unbalanced BST degrades to O(n).
- Choosing: hash map for pure lookups, tree for ordered or range queries, array for index access and fast iteration.
- Python mapping:
listis a dynamic array,dict/setare hash tables, and there is no built-in balanced tree (bisecton a sorted list has O(n) inserts).
Code / implementation expected: Optional โ use list, dict and bisect correctly and state the cost of each call.