This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do you initialise a heap data structure using pseudocode

 
ethio roln
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Can I someone show me how you would initialise a max-heap data structure, in pseudocode?

 
Stuart A. Burkett
Ranch Hand
Posts: 679
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 5590
55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure!
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15216
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
fred rosenberger
lowercase baba
Bartender
Pie
Posts: 12098
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
ethio roln
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 12098
30
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic