Problem Set: Heaps


  1. For each of the following, tell whether it's a minheap, a maxheap, or not a valid heap. If it's not a heap, explain why.
  2. Build a minheap from the following values. Show the heap after inserting 5 values, 10 values, 15 values, and after inserting all values.
      64 25 81 36 16 144 9 100 75 12 225 269 121 196 49 94 135
    
  3. Build a maxheap from the following values. Show the heap after inserting 5 values, 10 values, 15 values, and after inserting all values.
      97 59 31 144 49 81 256 36 16 169 55 121 269 25 100 64 86
    
  4. Build a maxheap from the following values. Show the heap after inserting 5 values, 10 values, 15 values, and after inserting all values.
      100 50 300 150 75 125 25 400 250 200 350 175 65 225 425 115 275 375 185 90
    
  5. Build a minheap from the following values. Show the heap after inserting 5 values, 10 values, 15 values, and after inserting all values.
      150 50 300 100 225 75 400 275 200 25 125 350 250 175 90 425 375 115 185 65
    
  6. Remove 8 values from the following heap (remove the root each time). Show the heap after each value is removed.
  7. Consider the heap from the problem above. Show how it will be stored in an array. Use the heap as shown, not after you deleted from it.

  8. Remove 8 values from the following heap (remove the root each time). Show the heap after each value is removed.
  9. Consider the heap from the problem above. Show how it will be stored in an array. Use the heap as shown, not after you deleted from it.

  10. Given the following heap:
    360  305  275  242  290  260  150  99   175  230  140  180  250  120
    [0]  [1]  [2]  [3]  [4]  [5]  [6]  [7]  [8]  [9]  [10] [11] [12] [13]
    
    1. What is the left child of 242?
    2. What is the right child of 260?
    3. Does 150 have a left child? If so what is it?
    4. Does 150 have a right child? If so what is it?
    5. Draw the heap


  11. Show the array from problem 9 after one pass of heapsort (move one element to the end and then perform siftdown).

  12. Show the array from problem 9 after a second pass of heapsort (move one element to the end and then perform siftdown).

  13. Show the array from problem 9 after a third pass of heapsort (move one element to the end and then perform siftdown).

  14. Show the array from problem 9 after a fourth pass of heapsort (move one element to the end and then perform siftdown).

  15. Show the array from problem 9 after a fifth pass of heapsort (move one element to the end and then perform siftdown).

  16. Show the array from problem 9 after a sixth pass of heapsort (move one element to the end and then perform siftdown).



Email Me | Office Hours | My Home Page | Department Home | MCC Home Page

© Copyright Emmi Schatz 2009