GATE Computer ScienceHardGATE CS (PYQ pattern)
A binary tree is stored in level order with null children written as _ : 1 2 3 4 _ 5 6 _ 7 _ _ 8 _ (a null child still consumes a slot only if its parent is present; children are assigned to non-null nodes in queue order, 2 per node). What is its postorder traversal?
- A. 1 2 4 7 3 5 6 8
- B. 1 3 6 8 5 2 4 7
- C. 1 2 3 4 5 6 7 8
- D. 7 4 2 5 8 6 3 1
Correct answer: D. 7 4 2 5 8 6 3 1
Children are assigned in queue order: 1 has (2, 3); 2 has (4, _); 3 has (5, 6); 4 has (_, 7); 5 has none; 6 has (8, _). The postorder is 7 4 2 5 8 6 3 1.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- Non-negative numbers are stored as singly linked lists of digits with the least significant digit first. A = 9 -> 9 -> 8 -> 5 (the number…
- A priority queue is a sorted singly linked list (ascending). Insert scans from the head, comparing the new key with each node, and stops…
- Keys 1..7 form a max-heap stored in a 0-indexed array (children of i are 2i+1, 2i+2). The key 5 is the third largest. In how many…
- A hash table starts with 7 slots, uses linear probing with h(k) = k mod size, and after each insertion, if the load factor exceeds 0.7, it…
- A grid (S start, T target, # blocked, . free) is searched by BFS with 4-directional moves: S.#..... .##.###. ....#... .##.#.#. ...#..#T…
- How many 10-bit unsigned values x (0 to 1023) have no two adjacent 1 bits, where bit 9 and bit 0 also count as adjacent (the bits are…