A scheme for storing binary trees in an array X is as follows. Indexing of X starts at 1 instead of 0. the root is stored at X[1]. For a node stored at X[i], the left child, if any, is stored in X[2i] and the right child, if any, in X[2i+1]. To be able to store any binary tree on n vertices the minimum size of X should be. (GATE CS 2006)
(A) log2n
(B) n
(C) 2n + 1
(D) 2^n — 1
Answer: (D)
Explanation: For a right skewed binary tree, number of nodes will be 2^n – 1. For example, in below binary tree, node ‘A’ will be stored at index 1, ‘B’ at index 3, ‘C’ at index 7 and ‘D’ at index 15.
A
\
\
B
\
\
C
\
\
D
Recommended Posts:
- Introduction to Data Structures | 10 most commonly used Data Structures
- Data Structures | Binary Trees | Question 1
- Data Structures | Binary Trees | Question 15
- Data Structures | Binary Trees | Question 3
- Data Structures | Binary Trees | Question 15
- Data Structures | Binary Trees | Question 6
- Data Structures | Binary Search Trees | Question 1
- Data Structures | Binary Search Trees | Question 2
- Data Structures | Balanced Binary Search Trees | Question 2
- Data Structures | Binary Search Trees | Question 3
- Data Structures | Binary Search Trees | Question 4
- Data Structures | Binary Search Trees | Question 5
- Data Structures | Balanced Binary Search Trees | Question 2
- Data Structures | Binary Trees | Question 8
- Data Structures | Binary Trees | Question 9
- Data Structures | Binary Trees | Question 10
- Data Structures | Binary Trees | Question 11
- Data Structures | Binary Search Trees | Question 6
- Data Structures | Binary Trees | Question 13
- Data Structures | Binary Search Trees | Question 7

