aspose file tools*
The moose likes General Computing and the fly likes How do you initialise a heap data structure using pseudocode Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » General Computing
Bookmark "How do you initialise a heap data structure using pseudocode" Watch "How do you initialise a heap data structure using pseudocode" New topic
Author

How do you initialise a heap data structure using pseudocode

ethio roln
Greenhorn

Joined: Jun 24, 2012
Posts: 2
Hi,
Can I someone show me how you would initialise a max-heap data structure, in pseudocode?

Stuart A. Burkett
Ranch Hand

Joined: May 30, 2012
Posts: 679
ethio roln wrote:Can I someone show me how you would initialise a max-heap data structure, in pseudocode?

Create instance of max-heap data structure
Initialise it


Expand those two instructions until you reach the necessary level of detail.
Stephan van Hulst
Bartender

Joined: Sep 20, 2010
Posts: 3647
    
  17

Sure!
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14269
    
  21

Welcome to the Ranch, ethio roln.

Please note that you've posted your question in the "Meaningless Drivel" forum - this is the forum on the website here where we make jokes and relax. If you post in here, expect to get non-serious answers. We have many other forums where your question will be taken more seriously.

I assume that you are looking for serious answers to your question, so I'll move it to a more appropriate forum. Please select an appropriate forum yourself, next time when you post a question.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11411
    
  16

Personally, I find the question rather vague..."pseudo-code" means "in English (or any other natural language)". And a "heap data structure" is an abstraction of a concept.

So you are asking us to tell you in English how to put together an abstract thing.

I guess the first question is "Do you know what a heap data structure is?", quickly followed by "do you know what a max heap data structure is"?

At the most basic level, the pseudo-code would be something like

1) create an empty heap
2) call 'insert' for each element you want to insert.

Did you have some other, more specific question? are you trying to write your own heap? are you trying to create the EXACT heap you show in your original post?or are you trying to do something else?


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
ethio roln
Greenhorn

Joined: Jun 24, 2012
Posts: 2
Jesper de Jong wrote:Welcome to the Ranch, ethio roln.

Please note that you've posted your question in the "Meaningless Drivel" forum - this is the forum on the website here where we make jokes and relax. If you post in here, expect to get non-serious answers. We have many other forums where your question will be taken more seriously.

I assume that you are looking for serious answers to your question, so I'll move it to a more appropriate forum. Please select an appropriate forum yourself, next time when you post a question.


Thank you for that.

fred rosenberger wrote:Personally, I find the question rather vague..."pseudo-code" means "in English (or any other natural language)". And a "heap data structure" is an abstraction of a concept.

So you are asking us to tell you in English how to put together an abstract thing.

I guess the first question is "Do you know what a heap data structure is?", quickly followed by "do you know what a max heap data structure is"?

At the most basic level, the pseudo-code would be something like

1) create an empty heap
2) call 'insert' for each element you want to insert.

Did you have some other, more specific question? are you trying to write your own heap? are you trying to create the EXACT heap you show in your original post?or are you trying to do something else?


I know what a heap is and how it works. This is for a course work I did and got no marks for this question.
"Describe in pseudo-code the Initialisation of the data structure as of figure (a).
Ignore node 95, which is about to be inserted."

This was my answer:

Create heap-array
With array size 11

fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 11411
    
  16

well...I don't think you need to specify the size. Heaps should grow as needed.

then you need to start inserting the values so that you get the structure in the diagram. I believe you'd insert 82 first, so that it becomes your root.

I'm not sure how you'd insert the rest of the elements. According to the wikipedia, new elements are generally inserted at the first open node. This often 'breaks' the heap properties, so it must then be 're-heapified'. I'm not sure how you'd force it to end up in the exact configuration specified since the implementation of the re-heapify is usually a mystery.

If this is course work, I'd suggest you talk to your professor/TA about what THEY think the correct answer is.
 
wood burning stoves
 
subject: How do you initialise a heap data structure using pseudocode