Consider a heap containing n elements, where n > 100 and n is odd. Assuming 1-based indexing, which of the following cannot be the index of a leaf node in the heap?
Solution :
The correct answer is (n−1)/2.
To understand why this is correct, let us analyze the properties of a binary heap represented as an array with 1-based indexing. For any node at index in a heap containing elements:
- The left child of the node is located at index .
- The right child of the node is located at index .
- A node is a leaf node if it has no children, which means its left child index exceeds the total number of elements in the heap: .
- Conversely, a node is an internal (non-leaf) node if it has at least one child, which means:
Let us now test the index given in the correct option, which is:
To determine if this node can be a leaf, we calculate the index of its left child:Since we are given that , it is clear that:
This means the index of the left child, , is a valid position within the heap. In fact, since is odd, the node at index also has a right child at index . Because the node at index has children, it must be an internal node and cannot be a leaf node in the heap.Completely free for students. Educators & coaching institutes get 2 months free Pro trial to create tests.
Access unlimited practice questions, detailed step-by-step solutions, and exam study materials — completely free for students.
Create and conduct professional online assessments with AI question generation, tab proctoring, and comprehensive batch management.
Prepare for GATE 2026 Civil Engineering with the latest question papers, previous year papers, detailed solutions, syllabus, exam pattern, preparation tips, mock tests, and subject-wise study material. Download GATE 2026 CE question papers with solutions in PDF format and boost your preparation for top engineering institutes and PSU recruitment.
Prepare effectively for GATE 2026 Electronics & Communication Engineering (EC) with this comprehensive Question Paper with Solutions. This resource includes detailed explanations, concept-wise solutions, previous year paper analysis, and exam-oriented practice to help aspirants strengthen core subjects like Electronic Devices, Analog Circuits, Digital Circuits, Signals & Systems, Network Theory, Control Systems, Electromagnetics, Communications, and more. Perfect for revision, self-assessment, and boosting your GATE 2026 EC preparation strategy.
Copyright © 2026 Combe Labs Private Limited. All Rights Reserved.