GATE CS 2022 Set 1 — Question 28
Go beyond PYQs with Success TrackerAI-powered personalised practice and doubt support. Unlimited practice on eligible plans; AI usage limits apply.NAT+1 / -0MediumBinary Search TreesTreesProgramming & Data StructuresBinary Tree Properties
Programming & Data Structures → Trees → Binary Search Trees
Last updated
Question
Suppose a binary search tree with 1000 distinct elements is also a complete binary tree. The tree is stored using the array representation of binary heap trees. Assuming that the array indices start with 0, the largest element of the tree is stored at index_____________.
Correct answer
509 to 509
Solution
To find the -th largest element in a Binary Search Tree (BST), we perform a reverse in-order traversal (Right, Root, Left). Since the tree is also a Complete Binary Tree (CBT) stored in an array, the structure is fixed.Array Indexing Properties:
For a node at index :
The largest element in a BST is the rightmost node. We start at the root () and keep moving to the right child as long as the index is within bounds ().
Since node is a leaf (no left child), the next largest element is its parent (since was a right child).
After visiting , we must explore its left subtree to find the next largest values. The largest value in the left subtree is the rightmost node of that subtree.
The 3rd largest element is stored at index 509.
For a node at index :
- Left Child:
- Right Child:
- Parent:
- Total nodes (indices to ).
The largest element in a BST is the rightmost node. We start at the root () and keep moving to the right child as long as the index is within bounds ().
- Next right child: . Node has no right child.
- Does node have a left child? . No.
- Thus, index 510 is the largest element.
Since node is a leaf (no left child), the next largest element is its parent (since was a right child).
- Parent of : .
- Thus, index 254 is the 2nd largest element.
After visiting , we must explore its left subtree to find the next largest values. The largest value in the left subtree is the rightmost node of that subtree.
- Left child of : .
- Does node have a right child? . No.
- Since node has no right child, it is the largest element in the left subtree of .
- Thus, index 509 is the 3rd largest element.
The 3rd largest element is stored at index 509.
Continue learning with Success Tracker
A step still unclear? Work through it with support
Use Success Tracker to ask about the reasoning, then try another GATE CS question to check your understanding.
AI-powered practice· Unlimited practice on eligible plans
- PYQs with solutions
- Attempt available previous-year questions, then compare your reasoning with the worked solution. Coverage varies by stream.
- Practice that adapts
- Choose a topic, work on weaker areas and bookmark questions to revisit. Your attempts feed your progress tracking.
- AI doubt support
- Ask follow-up questions about a step or concept while practising, instead of stopping at the final answer.
Unlimited practice is available on eligible plans. Free practice and AI usage have limits; check the current plan allowances before choosing.
This page stays readable without an account. AI responses can be wrong; check them against the solution and source material.
More questions on Trees
2026 Set 2 Q12The set T represents various traversals over binary tree. The set S represents the order of…2026 Set 2 Q19Consider the following three ANSI-C programs, P1, P2, and P3. P1 [code] P2 [code] **P3**…2026 Set 1 Q23Let be an odd number greater than 100. Consider a binary minheap with elements stored in an…2026 Set 1 Q24Consider a hash table that is initially empty. The hash table is maintained…2026 Set 1 Q27Consider the following C statements: Which of the following options is/are correct? [figure]