GATE Computer ScienceHardGATE CS (PYQ pattern)
A heap with 2000 elements is stored in an array (complete binary tree, last level filled left to right). How many elements are in the left subtree of the root, and how many in the right subtree?
- A. 999 and 1000
- B. 1023 and 976
- C. 1022 and 977
- D. 976 and 1023
Correct answer: B. 1023 and 976
Levels 0 to 9 hold 1023 elements and the last level (depth 10) holds 977. The left subtree has 511 elements on depths 1 to 9 plus the first 512 slots of the last level = 1023; the right subtree has 511 plus the remaining 977 - 512 = 465 = 976.
Practise more Programming and Data Structures (GATE) questionsProgramming and Data Structures (GATE): notes and key points
More Programming and Data Structures (GATE) questions
- How many structurally distinct AVL trees (left and right distinguished, shape only) have exactly 9 nodes?
- A binary tree is serialised in preorder with # for a null child: A B D # # E G # # # C # F # #. What is its inorder traversal and its…
- An undirected simple graph on 100 vertices is stored by keeping only the upper triangle (without the diagonal) of its adjacency matrix as…
- The 4 largest elements of the stream 14, 7, 22, 3, 18, 9, 30, 11, 25, 5, 17, 28, 2, 21 are found with a min-heap of size 4 holding the…
- A sorted array was rotated: [15, 18, 22, 25, 30, 2, 4, 7, 9, 11, 12, 14]. The standard rotated binary search (compare a[lo] <= a[mid] to…
- Two singly linked lists merge into a common tail: list X has 7 nodes before the merge point, list Y has 11 nodes before it, and the shared…