GATE CS 2022 | Question 28
Programming & Data Structures › Trees · NAT · 1 mark · Answer: 509
- Question 28Programming & Data Structuresnat1 markSuppose a binary search tree with 1000 distinct elements is also a complete binary tree, stored using the array representation of binary heap trees. Assuming array indices start at 0, the 3rd largest element is stored at index __________.
Answer: 509
Solution
Answer: 509 A complete binary tree that is also a BST, stored in a 0-indexed array (heap layout), has 1000 nodes. The largest element is the right-most node of the tree; the 3rd largest is found by the in-order predecessor relationships. Working out its array position in the complete-tree layout gives index 509.
More GATE PYQ on Trees
All GATE CS Programming & Data Structures PYQ →Attempt GATE CS 2022 in real GATE exam mode
Full paper with a timer, the GATE interface and a topic-wise analysis — free.
Create free account →