Data Structures & AlgorithmsHardProduct company OA
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 elements). How many nodes does it have?
- A. 12
- B. 16
- C. 7
- D. 11
Correct answer: D. 11
Every internal node has exactly two children, so it is a full binary tree with n = 6 leaves and n − 1 = 5 internal nodes: 2n − 1 = 11. The ARRAY used to store it is usually sized 4n (or 2·next power of two = 16), but most of those slots are unused.
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
- 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…
- A connected undirected graph has vertex degrees A: 3, B: 4, C: 2, D: 3, E: 2. Does it have an Euler path (using every edge exactly once)…
- Houses in a row hold [3, 2, 7, 10, 1, 9]. No two ADJACENT houses may both be chosen. What is the maximum total? (dp[i] = max(dp[i − 1]…
- The set [3, 9, 7, 3, 11] is split into two subsets so that the absolute difference of their sums is as small as possible (subset-sum DP…
- Digits map to letters A = 1 … Z = 26. In how many ways can the string '2263' be decoded? (dp over prefixes; a pair counts only if it is…