Data Structures & AlgorithmsHardGATE CS · Product-company placement
A binary search tree holds exactly the keys 13, 19, 20, 36, 71, 73, 94, 99. Which ONE of the following sequences can be its PREORDER traversal?
- A. 73, 19, 36, 20, 13, 71, 99, 94
- B. 73, 20, 36, 71, 13, 19, 99, 94
- C. 73, 71, 36, 20, 13, 19, 99, 94
- D. 73, 71, 99, 20, 13, 19, 36, 94
Correct answer: C. 73, 71, 36, 20, 13, 19, 99, 94
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. 73, 71, 36, 20, 13, 19, 99, 94 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
- A BST holds integer keys between 1 and 100. Which sequence CANNOT be the sequence of keys examined while searching for 44?
- A rooted tree has these parent→child edges: 56→8, 64→56, 64→24, 64→45, 24→59, 45→41, 8→2. A depth-first search starts at the root and, at…
- A rooted tree has these parent→child edges: 74→13, 74→24, 84→62, 13→75, 13→66, 24→84. A depth-first search starts at the root and, at…
- A rooted tree has these parent→child edges: 72→45, 31→27, 98→31, 27→38, 31→72, 98→71. A depth-first search starts at the root and, at…
- A rooted tree has these parent→child edges: 74→62, 21→36, 65→79, 62→71, 36→78, 65→76, 71→99, 74→65, 74→21. A depth-first search starts at…
- A rooted tree has these parent→child edges: 78→14, 78→24, 61→26, 96→10, 78→61, 52→78, 14→9, 78→16, 26→96. A depth-first search starts at…