Data Structures & AlgorithmsHardGATE CS
A binary search tree holds exactly the keys 28, 41, 46, 47, 55, 66, 96, 99. Which ONE of the following sequences can be its PREORDER traversal?
- A. 47, 28, 41, 99, 46, 66, 55, 96
- B. 47, 28, 41, 55, 99, 66, 46, 96
- C. 47, 55, 41, 46, 99, 66, 28, 96
- D. 47, 28, 41, 46, 99, 66, 55, 96
Correct answer: D. 47, 28, 41, 46, 99, 66, 55, 96
In a valid BST preorder, once a key larger than some node appears (we have moved into that node's right subtree), no later key may be smaller than that node. 47, 28, 41, 46, 99, 66, 55, 96 never breaks this; each other option does at some point.
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
- The weighted undirected graph A–B (3), A–C (5), A–E (22), B–D (18), B–F (16), C–D (8), C–F (2), E–F (26) has a unique MST. What is the…
- The connected undirected graph with edges A–C, A–F, B–C, B–D, B–G, B–H, C–D, C–F, D–E, D–G, F–H, G–H must be walked so that every edge is…
- DFS on the directed graph with adjacency lists A: CDG; B: –; C: –; D: BCF; E: –; F: CE; G: CE starts at A (scanning lists in the order…
- What is the length of the longest BITONIC subsequence (strictly increasing then strictly decreasing; either part may be empty) of [19, 10…
- Keys 32, 44, 47, 53, 93, 54, 12, 22, 68, 97 are inserted into an empty AVL tree (giving preorder 53, 44, 22, 12, 32, 47, 68, 54, 93, 97)…
- Using parts 3, 4, 5 (each any number of times), in how many ways can 10 be written as an ORDERED sum (so 1 + 2 and 2 + 1 count separately)?