Remember, "the answer" is only half of it! Also, make sure everyone in your group can explain why.

We will use this Gradescope Online Assignment as our worksheet for in-class work. These problems are coded as being worth points for our simplicity, but will not impact your grade in the course.

Question 2

  1. Not a valid Binary Heap because the node with 7 has a value smaller than it (2) as a child.

    https://s3-us-west-2.amazonaws.com/secure.notion-static.com/e40c3cfc-d64a-40ae-a7dc-28acc6d34027/Untitled.png

  2. This is a valid Binary Heap since it satisfied all the invariants. A common concern is the fact that there are duplicate values, which is not a problem in the heap invariants.

    https://s3-us-west-2.amazonaws.com/secure.notion-static.com/34bfe4f0-6c6c-4071-a000-d7c02cd07946/Untitled.png

  3. Not a valid Binary Heap because it is not a complete tree.

    https://s3-us-west-2.amazonaws.com/secure.notion-static.com/d1a61a1e-1478-45c4-8331-0bf8076913ae/Untitled.png

  4. Not a valid Binary Heap because it is not a complete tree. Notice the row at index 2 is not completely full but the tree already started a row at index 3.

    https://s3-us-west-2.amazonaws.com/secure.notion-static.com/8fcbc15f-7f54-497a-818d-a06c6a7c9411/Untitled.png

Question 3

Question 3.1

The value returned is 5, because the minimum value is always stored at the top of the heap.

Question 3.2

When doing removeMin, we do a percolateDown operation. Recall the process for removeMin is:

  1. Remove the value from the top of the tree (to return at the end)
  2. Grab the last node at the bottom-level of the tree and move it to the top
  3. percolateDown that node to restore the Heap invariant

Question 3.3

This one is a bit weird since we asked for this strange-looking format. The correct answer is [7,8,7,13,9,11,15] which corresponds to the following tree:

https://s3-us-west-2.amazonaws.com/secure.notion-static.com/eac6c670-dc73-4bef-922e-b0f72dd8c948/Untitled.png

To get this answer, we start by following the removeMin algorithm.