Data Structures & AlgorithmsModerateInfosys · Accenture pattern
Keys 15, 10, 20, 8, 12, 25, 6, 11, 13, 9 are inserted into an empty BST. What is the height of the tree (edges on the longest root-to-leaf path)?
- A. 4
- B. 2
- C. 9
- D. 3
Correct answer: D. 3
15 → 10 → 8 → 6 or 9, and 15 → 10 → 12 → 11 or 13: the longest paths have 3 edges (e.g. 15–10–8–9). 9 is a leaf at depth 3 (right child of 8). Counting nodes instead of edges gives 4.
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 10, 20, 30, 25, 28 are inserted into an empty AVL tree. Which rotations are performed, in order (named by imbalance case)?
- Floyd–Warshall on vertices 0–3 starts from the weight matrix below (∞ = no edge). After the iteration with k = 0 (paths allowed to go…
- How many distinct spanning trees does the graph with vertices A, B, C, D and edges A–B, B–C, C–D, D–A, A–C (a 4-cycle plus one diagonal)…
- A recursive segment tree is built over an array of n = 6 elements (each internal node splits its range into two halves; leaves are single…
- In a Fenwick (binary indexed) tree of size 16 (1-based), the update at index 5 adds the value to i = 5 and then repeatedly does i += i &…
- Union–find with NO union by rank/size and NO path compression: union(a, b) sets parent[find(a)] = find(b). Starting with singletons 0–5…