Data Structures & AlgorithmsVery hardGATE CS · TCS NQT · Product Company SDE
Keys 77, 23, 72, 58, 94, 42, 92 are inserted in this order into an empty BST. What is the postorder traversal?
- A. [23, 42, 58, 72, 77, 92, 94]
- B. [42, 58, 72, 23, 94, 92, 77]
- C. [42, 58, 72, 23, 92, 94, 77]
- D. [77, 23, 72, 58, 42, 94, 92]
Correct answer: C. [42, 58, 72, 23, 92, 94, 77]
Insert in order to build the BST (root 77); postorder visits left, right, root, giving [42, 58, 72, 23, 92, 94, 77].
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 the undirected graph with edges A–B:14, A–C:4, B–D:8, C–E:11, D–F:12, C–F:9, what is the shortest-path distance from A to C?
- An undirected graph has edges (u–v: weight) A–B:8, B–C:11, C–D:6, C–E:3, A–C:6. What is the weight of its minimum spanning tree?
- A DAG has edges A→B, A→C, A→D, A→E, D→E. Using Kahn's algorithm (always picking the smallest-labelled vertex among those currently…
- Keys 75, 52, 51, 68, 44, 20, 77, 85 are inserted in this order into an empty BST. How many nodes lie in the left subtree of the root (75)?
- A max-heap is built by inserting 50, 84, 44, 25, 79, 86 one by one (sift-up on each insert). After one extract-max (move the last element…
- A min-heap is built by inserting 60, 47, 76, 55, 61, 80, 34 one by one (sift-up on each insert). After one extract-min (move the last…