a3solutions

a3solutions - CS 234 Fall 2010 Assignment 3 Written...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: CS 234 Fall 2010 Assignment 3 Written Component Solutions This assignment is meant to give you further insight into heaps and sorting. 1. Carefully explain why remove_max from a heap is Θ(1) in the best-case. Be sure to consider arbitrarily large heaps. [3 marks] The time needed to access the last node and move it to the root is Θ(1) . Each bubble down operation is Θ(1) . We show that it is possible for there to be exactly one bubble down operation. (Note there must be at least one bubble down operation because the child of the root in the same subtree as the last node will be out of heap-order with the last node after it moves to the root.) Here is a situation in which there is exactly one bubble-down operation: • the last node is in the left subtree • the item with the second highest priority is in the right child of the root • all priorities of items in the left subtree are larger than priorities in the proper descen- dants of the right child of the root In this case, the heap-order property will be satisfied after the last node is moved to the root and swapped with its right child. The case where the last node is in the right subtree is similar. 2. (a) If a heap is of size n , exactly how many indices in the array (Python list) might contain the item with the second largest priority? Explain briefly. [2 marks] The item of second largest priority must be stored in one of the root’s children. The item in the root must be of higher priority and all items in proper descendants must be...
View Full Document

This note was uploaded on 01/27/2011 for the course CS 234 taught by Professor Baranoski during the Fall '09 term at Waterloo.

Page1 / 3

a3solutions - CS 234 Fall 2010 Assignment 3 Written...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online