Why is heap implemented using array representations than tree(linked list) representations though both tree representations and heaps have

Why is heap implemented using array representations than tree(linked list) representations though both tree representations and heaps have same complexities?
Code:
for binary heap
-insert: O(log n)
-delete min: O(log n)
for a tree
-insert: O(log n)
-delete: O(log n)
Then why go with array representation when both are having same values ?
A. arrays can store trees which are complete and heaps are not complete
B. lists representation takes more memory hence memory efficiency is less and go with arrays and arrays have better caching
C. lists have better caching
D. In lists insertion and deletion is difficult
 
Answer: B
Explanation: In memory the pointer address for next node may not be adjacent or nearer to each other and also array have wonderful caching power from os and manipulating pointers is a overhead. Heap data structure is always a complete binary tree.
 

Tìm kiếm

Back
Top