Assignment 2

Some jpg's of the solutions - not gorgeous, but legible for example purposes

one example and the rest

Remember heaps say top is biggest (or smallest for min heap) and also that the tree is complete. So a sort

  1. takes the top one out,
  2. then takes the last one in the tree and puts it on top,
  3. then "heapifies" by letting it "fall" into place.

My 4 cases were the mathematician in me being explicit since the problem stated, "Give counter examples to show that heapsort is not stable regardless of whether an inequality or a strict inequality is used to switch elements around."
Since it said to show "regardless", I showed all 4 possibilities of where the inequality could be.

  1. > and <
  2. > and <
  3. > and <
  4. > and <
These .gifs are also in this directory. I suggest looking at them with a viewer that allows you to enlarge. Enlarged the diagrams are clear.