# HW5_sol - Fall Semester 2008 CS300 Algorithms Solution#5...

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

Fall Semester 2008 CS300 Algorithms Solution #5 1. (a) 9 comparisons needed for MAX heap. (b) Every internal node performs FixHeap operation to construct a heap. Because it’s already sorted in the decreasing order, there is no key movement. When a node has two children nodes, you need two comparisons, and similarly when a node has one child, you need just one comparison. If n is even, the number of internal nodes is n/ 2 and the last internal node has one child node, so the number of comparison is 2 × ( n/ 2 - 1) + 1 = n - 1. If n is odd, the number of internal nodes is ( n - 1) / 2 and all internal nodes have two children nodes, so the number of comparisons is 2 × ( n - 1) / 2 = n - 1. (c) The best case. In the case of decreasing order, you do not need move a key during FixHeap operations, which minimizes the number of comparisons. 2. (a) Let us denote the list by L . Then the worst case is when L is sorted in the decreasing order like L = 111 ··· 1100 ··· 000. Let us assume that

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 2

HW5_sol - Fall Semester 2008 CS300 Algorithms Solution#5...

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

View Full Document
Ask a homework question - tutors are online