Data Structures & AlgorithmsVery hardProduct-company placement
Keys 56, 62, 60, 92, 46, 65, 74, 38, 72 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. 3
- B. 4
- C. 5
- D. 6
Correct answer: C. 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
- A binary tree has preorder traversal [7, 75, 8, 32, 9, 18, 91, 86] and inorder traversal [7, 8, 9, 18, 32, 75, 86, 91]. Reconstructing the…
- Keys 43, 53, 63 are inserted in this order into an empty AVL tree. After AVL rebalancing (a single rotation resolves the imbalance here)…
- A disjoint-set (union-find with union by rank and path compression) over 8 elements (0 to 7), each initially its own component, runs this…
- Undirected graph edges: D–C, B–C, A–C, A–B, A–D, B–D. Using a BFS 2-colouring, is this graph bipartite?
- Keys 64, 54, 44 are inserted in this order into an empty AVL tree. After AVL rebalancing (a single rotation resolves the imbalance here)…
- A binary tree has preorder traversal [23, 2, 94, 67, 57, 46, 81] and inorder traversal [2, 23, 46, 57, 67, 81, 94]. Reconstructing the…