GATE Computer ScienceHardGATE CS (PYQ pattern)
Keys 50, 30, 80, 20, 40, 70, 90, 10, 25, 35, 45, 5, 12, 22, 27 are inserted in this order into an empty BST. Its level-order traversal uses a queue: dequeue a node, then enqueue its non-null children. What is the maximum number of nodes simultaneously in the queue?
- A. 6
- B. 5
- C. 7
- D. 8
Correct answer: A. 6
The queue holds parts of two adjacent levels. Right after 40 is dequeued it contains 70, 90, 10, 25, 35, 45 (6 nodes), and later 35, 45, 5, 12, 22, 27 is again 6; it never exceeds 6.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- Which one of the following sequences can NOT be the postorder traversal of a binary search tree with distinct keys?
- Keys 1 to 6 are inserted into an empty BST in each of the 720 possible orders. For how many orders is the height of the resulting tree…
- All 120 insertion orders of keys 1..5 into an empty BST are equally likely. What is the probability that the resulting tree has height…
- Keys 40, 20, 10, 25, 30, 22, 50, 5, 3, 35, 45, 60 are inserted in this order into an initially empty AVL tree (a double rotation counts as…
- Keys 1, 2, 3, ..., 20 are inserted in increasing order into an initially empty AVL tree. What is the key at the root, and how many…
- An AVL tree of height 6 (a single node has height 0) has the minimum possible number of nodes, and its keys are 1, 2, ..., n for that…