Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and beginning April 20th, 2021 (Eastern Time) the Yahoo Answers website will be in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.

Heap versus Tree (Java)?

I am having trouble defining the difference between a heap and a tree. I know that a heap IS a complete binary tree...so how do I differentiate? When would I use each?

Thanks.

1 Answer

Relevance
  • Person
    Lv 7
    9 years ago
    Favorite Answer

    Heaps tend to be sorted by default, ie, a maxheap or minheap, and they tend to provide methods for popping and pushing items to the heap, where the heap will be sorted according to the elements added and the comparator you passed to it. They're largely used for sorting items or keeping them ordered, ie, a heap is the parent of the priority queue. Trees are much more general.

Still have questions? Get your answers by asking now.