Data Structures & AlgorithmsHardGATE CS · TCS NQT · Product Company SDE
Keys 82, 68, 95, 70, 94, 13, 69, 23, 56 are inserted in this order into an empty BST. How many leaf nodes does the resulting tree have?
- A. 4
- B. 3
- C. 5
- D. 2
Correct answer: B. 3
Insert in order (root 82) and count nodes with no children: 3 leaves.
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
- An undirected graph has adjacency lists A:BCF B:ADF C:AE D:B E:CF F:ABE. Neighbours are always explored in alphabetical order. Which is…
- In the undirected graph with edges A–B:12, B–C:8, B–D:12, A–E:9, D–F:10, B–F:14, A–C:12, what is the shortest-path distance from A to E?
- Keys 81, 18, 92, 48, 71, 55, 44, 41 are inserted in this order into an empty BST. What is the postorder traversal?
- A max-heap is built by inserting 55, 85, 57, 63, 32, 19, 91, 12 one by one (sift-up on each insert). After one extract-max (move the last…
- A max-heap is built by inserting 73, 97, 96, 27, 78, 89, 18 one by one (sift-up on each insert). After one extract-max (move the last…
- A DAG has edges A→B, A→C, B→D, C→E, A→D, B→C. Using Kahn's algorithm (always picking the smallest-labelled vertex among those currently…