Click here to Skip to main content
15,347,625 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 17-May-22 2:55am
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.
   
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[^]
   
An array is used to implement a heap -- The main reason that we can use an array to represent the heap-ordered tree in a binary heap is because the tree is a binary tree and it is complete. See algs4/notes.txt at master · hackprime/algs4 · GitHub[^]
   
The answer is array. Heaps are generally implemented with an array and every element is array represents a node of the heat.
   
Comments
Richard Deeming 17-May-22 9:51am
   
As already explained in solution 1.

And reposted in solutions 3 and 4.

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