Data Structures & AlgorithmsHardGATE CS
A binary search tree holds exactly the keys 10, 17, 35, 59, 61, 68, 84, 91. Which ONE of the following sequences can be its PREORDER traversal?
- A. 35, 84, 17, 91, 61, 59, 10, 68
- B. 35, 68, 17, 91, 61, 59, 84, 10
- C. 35, 10, 91, 17, 61, 59, 84, 68
- D. 35, 10, 17, 91, 61, 59, 84, 68
Correct answer: D. 35, 10, 17, 91, 61, 59, 84, 68
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. 35, 10, 17, 91, 61, 59, 84, 68 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
- DFS on the directed graph with adjacency lists A: BE; B: –; C: AD; D: AG; E: DF; F: D; G: E starts at A (scanning lists in the order…
- Keys 87, 36, 57, 23, 95, 88, 77 inserted in this order build a BST. How many of the 7! orderings of these same 7 keys, inserted into an…
- DFS runs on the directed graph with adjacency lists A: EF; B: A; C: A; D: AE; E: BCF; F: G; G: B, starting at A, scanning lists in the…
- A B-tree has minimum degree t = 4 (every non-root node has between 3 and 7 keys) and height 3 (a root-only tree has height 0). What are…
- In how many different ways can 'abcdabcd' be split into a sequence of words from the dictionary {a, ab, abc, bcd, cd, d, abcd} (every…
- Six sorted files have 14, 31, 34, 35, 36, 58 records. Merging two files of sizes a and b costs a + b. What is the minimum total cost to…