Data Structures & AlgorithmsHardGATE CS · ICPC regional · Product Company SDE
Keys 40, 26, 84, 95, 87, 62, 49, 79 are inserted one by one into an empty binary search tree. What is the in-order traversal?
- A. [26, 40, 49, 62, 79, 84, 87, 95]
- B. [26, 49, 79, 62, 87, 95, 84, 40]
- C. [40, 26, 84, 62, 95, 49, 79, 87]
- D. [40, 26, 84, 62, 49, 79, 95, 87]
Correct answer: A. [26, 40, 49, 62, 79, 84, 87, 95]
Build the BST by inserting in order (root 40). in-order gives [26, 40, 49, 62, 79, 84, 87, 95]. In-order of a BST is always sorted.
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
- Keys 72, 27, 56, 96, 23, 39, 71, 12, 36 are inserted in this order into an empty BST. How many nodes lie in the left subtree of the root 72?
- Keys 36, 91, 14, 43, 11, 56, 93 are inserted one at a time into an initially empty max-heap (array representation, sift-up). What is the…
- In the undirected graph with edges A–B:9, B–C:8, B–D:9, B–E:3, B–F:9, A–F:5, D–F:12, E–D:11, what is the shortest-path distance from A to F?
- An undirected graph has adjacency lists A:BCE B:AD C:ADE D:BC E:AC. Neighbours are always explored in alphabetical order. Which is the DFS…
- Keys 97, 30, 61, 33, 46, 40, 51, 36, 31 are inserted one by one into an empty binary search tree. What is the level-order traversal?
- Keys 68, 35, 20, 76, 29, 93, 85, 49, 58 are inserted in this order into an empty BST. How many leaf nodes does the tree have?