Data Structures & AlgorithmsHardAmazon/Microsoft SDE pattern
Keys 75, 53, 77, 17, 31, 29, 21, 5, 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. 3
- C. 6
- D. 4
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 9 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
- Directed edges: A→B (4), A→C (5), C→B (-4), B→D (1). Dijkstra's algorithm, which finalises each vertex once when it is removed from the…
- Keys 43, 46, 99, 82, 78, 23, 40, 44, 60, 34 are inserted via separate chaining (h(k) = k mod 5, new keys appended to the end of the chain)…
- A binary tree has preorder traversal [21, 13, 54, 28, 40, 34] and inorder traversal [13, 21, 28, 34, 40, 54]. Reconstructing the tree…
- What are the time complexities of P and Q? c int P(int n) { if (n <= 1) return 1; return P(n/2) + P(n/2); } int Q(int n) { if (n <= 1)…
- Keys 30, 11, 59, 70, 43, 35 are inserted via separate chaining (h(k) = k mod 8, new keys appended to the end of the chain) into a table of…
- Undirected graph edges: A–C, A–D, D–C, C–B. Using a BFS 2-colouring, is this graph bipartite?