Data Structures & AlgorithmsModerateTCS NQT · Infosys pattern
Keys 50, 30, 70, 20, 40, 60, 80, 35, 65, 10 are inserted into an empty BST. How many nodes have EXACTLY one child?
- A. 2
- B. 3
- C. 4
- D. 5
Correct answer: B. 3
20 has only left child 10; 40 has only left child 35; 60 has only right child 65. 50, 30 and 70 have two children; 10, 35, 65 and 80 are leaves. Total 3.
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 climber can take 1 or 3 steps at a time. In how many different ordered ways can a staircase of 7 steps be climbed? (ways(n) = ways(n −…
- Keys 50, 40, 30, 45, 47 are inserted in that order into an empty AVL tree. What is the preorder traversal of the final tree?
- Kruskal's algorithm runs on edges (weight): A–B 4, A–C 3, B–C 2, B–D 5, C–D 7, C–E 8, D–E 6, D–F 9, E–F 4. What is the total weight of the…
- Bellman–Ford from S relaxes the directed edges in this fixed order in every pass: C→D (1), B→C (2), A→B (3), S→A (4). How many passes are…
- A min-heap of size k = 3 tracks the 3 largest values of the stream 5, 1, 9, 3, 7, 8, 2 (push each value; if the size exceeds 3, pop the…
- An undirected graph has edges 1–2, 2–3, 3–1, 3–4, 4–5, 5–6, 6–4, 6–7, 7–8. How many BRIDGES (edges whose removal disconnects the graph)…