Consider a situation of writing a binary tree into a file with memory storage efficiency in mind, is array representation of tree is good?

Pham Quỳnh

New member
Consider a situation of writing a binary tree into a file with memory storage efficiency in mind, is array representation of tree is good?
A. yes because we are overcoming the need of pointers and so space efficiency
B. yes because array values are indexable
C. No it is not efficient in case of sparse trees and remaning cases it is fine
D. No linked list representation of tree is only fine
 
Answer: C
Explanation: In case of sparse trees (where one node per level in worst cases), the array size (2$^{h}$)-1 where h is height but only h indexes will be filled and (2$^{h}$)-1-h nodes will be left unused leading to space wastage.
 

Tìm kiếm

Back
Top