Click here to Skip to main content
15,844,903 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
I am really confused about which is the mostly used data structure for a Heap ?
Most of answers I got were Arrays and Linkedlist , but other than that too what other options do we have ?

What I have tried:

Tried google but didnt got the required answer for my query .
Posted
Updated 29-Jun-22 1:43am
Comments
Richard MacCutchan 3-Sep-20 7:37am    
As the other Richard already suggested, get a book on programming. Your confusion arises because you have not learned the basics. And until you do, no amount of questions here is going to help you.

If you are talking about implementing a Heap, then pretty much all you will need is arrays and linked lists - normally the just latter to describe the free and allocated blocks as an array is limited by its initial size and that's unlikely to be helpful in a "real world" app.

If you are talking about "what goes on the heap in Java?" then that's a different question, and the answer is "everything, pretty much". The only things that don't are local variables such as primitives (integers for example) and references to heap based objects - all of these stack based objects are transitory as they will be deallocated automatically when the method they are local to exits.
 
Share this answer
 
Quote:
Tried google but didnt got the required answer for my query .

and we are supposed to guess what is you required answer?
Quote:
Which data structure is used to implement heap ?

May be a heap is a data structure by itself: Heap (data structure) - Wikipedia[^]
 
Share this answer
 
Heaps are usually implemented with an array. Each element in the array represents a node of the heap, and. The parent / child relationship is defined implicitly by the elements' indices in the array.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900