Search code examples
arraystreelinked-listcomplexity-theorybinary-heap

Complexity of binary heaps using linked lists


I am trying to compare the implementing a binary heap using an array and linked lists. I think arrays are better in every way because all operations can be done faster than or equal to the operations using a linked list. It also needs less memory.

But are there any reasons why using linked lists are better than arrays for binary heaps?


Solution

  • Binary heaps are rarely represented as explicit trees. They use more memory than the array version, have poor locality of reference, and (as you noted in your earlier question) are harder to implement.

    The marin reason for studying binary heaps as trees is to build up an intuition for the data structure. It is quite difficult to reason about the properties and correctness of binary heaps given just the array representation, but by connecting them back to the binary tree representation it becomes a lot easier to design and prove correctness of algorithms on binary heaps.

    Hope this helps!