Data Structures & AlgorithmsVery hardAmazon/Microsoft SDE pattern
Keys 45, 92, 18, 65, 91, 86, 78, 95 are inserted in this order into an empty BST (no rebalancing). What is the height of the tree (edges on the longest root-to-leaf path)?
- A. 5
- B. 6
- C. 4
- D. 3
Correct answer: A. 5
Inserting keys in this order without rebalancing produces a tree whose deepest leaf is 5 edges below the root. 3 would be the height of a *balanced* tree with 8 nodes, which insertion order alone does not guarantee.
Practise more Trees, Graphs, Recursion and Dynamic Programming questionsTrees, Graphs, Recursion and Dynamic Programming: notes and key points
More Trees, Graphs, Recursion and Dynamic Programming questions
- Keys 55, 50, 19, 76, 39, 98, 34, 63, 58, 69 are inserted via separate chaining (h(k) = k mod 8, new keys appended to the end of the chain)…
- A trie is built from the words {cat, card, den, cats, dog, do, cap}. Using the trie (walk the prefix's characters, then count all words in…
- Build a binary min-heap in place from the array [2, 63, 36, 74, 23, 20, 15, 22] using bottom-up heapify (sift-down from the last internal…
- Build a binary min-heap in place from the array [47, 72, 84, 82, 36, 61, 51, 7, 2] using bottom-up heapify (sift-down from the last…
- Undirected graph edges: E–C, C–A, B–E, B–C, A–B, A–E, C–D. Using a BFS 2-colouring, is this graph bipartite?
- A trie is built from the words {cat, card, dot, den, deed, dog}. Using the trie (walk the prefix's characters, then count all words in the…