943,881 Members | Top Members by Rank

Ad:
  • C Discussion Thread
  • Unsolved
  • Views: 4282
  • C RSS
Sep 30th, 2005
0

a question about heap data structure

Expand Post »
although this question is basically related to a data structure, still I think that a good progrmmer should be able to answer it. My question is that "is it possible to determine the order in which some ( numbers or characters etc ) are arrived for insertion into a min or max heap ( if we are given that heap )." I think that its answer is yes as there can be so many combinations that we can describe in this regard, but my tutor says that it is not possible, I will be very thank ful for any serious reply.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
md_salman is offline Offline
12 posts
since Sep 2005
Sep 30th, 2005
0

Re: a question about heap data structure

Quote originally posted by md_salman ...
although this question is basically related to a data structure, still I think that a good progrmmer should be able to answer it. My question is that "is it possible to determine the order in which some ( numbers or characters etc ) are arrived for insertion into a min or max heap ( if we are given that heap )." I think that its answer is yes as there can be so many combinations that we can describe in this regard, but my tutor says that it is not possible, I will be very thank ful for any serious reply.
If only insertion has happened, you are correct in that there are a non-zero number of combinations in this regard.

For example, suppose your min-heap has three elements, looking like
  1. X
  2. / \
  3. Y Z
where X < Y < Z. Suppose your insertion algorithm fills the bottom row from left-to-right. It's either that or right-to-left. First I'll assume that you made only three insertions with no deletions.

There are six possible orders of input: X Y Z, X Z Y, Y X Z, Y Z X, Z Y X, Z X Y. Whenever Z comes before Y, the following heap results.

  1. X
  2. / \
  3. Z Y

Therefore, if you have the heap
  1. X
  2. / \
  3. Y Z
and X < Y < Z, then you know that Y was inserted before Z was. Generally speaking, I think you can only derive the order of insertion when comparing two leaf nodes (and probably only with two adjacent leaf nodes), but I do not know for sure.

If the heap has undergone insertion along with removal of the minimum element, then you cannot know anything about the ordering in which two particular elements were inserted.
Team Colleague
Reputation Points: 1135
Solved Threads: 171
Super Senior Demiposter
Rashakil Fol is offline Offline
2,478 posts
since Jun 2005
Oct 3rd, 2005
0

Re: a question about heap data structure

AOA
here is a link if data structure notes. it will help you to solve your problem \\ Read AVL Tree // data structure.
http://vulms.vu.edu.pk/Links/CS301.htm
ALLAH HAFIZ
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ITgeneration is offline Offline
6 posts
since Sep 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C Forum Timeline: Multiline Story String
Next Thread in C Forum Timeline: Emulator Help!!!!!





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC