This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: 15121 FALL 2009 [CORTINA]HOMEWORK 9  due Friday, November 20 by 11:59PMELECTRONIC HANDIN AVAILABLE BY MONDAY 5PMPROGRAMMING PROBLEM REVISEDPROBLEMS (10 pts)1. (1.5 pts) Consider the minheap below: 18/ \34 26/ \ / \60 46 52 89/ \ 75 91a. Using the minheap above, add the value 21 and restore the heap using the algorithm discussed in lecture. For your answer, show how the resulting heap would be stored in an array. b. Using the originalminheap above, remove the minimum value and restore the heap using the algorithm discussed in lecture. For your answer, show how the resulting heap would be stored in an array. c. Why are binary search trees not usually stored using arrays? Explain. 2. (1.5 pts) a. You are given the following array of integers in the order shown: 45 28 58 30 12 75 64 89 41Trace the algorithm for building a maxheap out of an array of elements, showing the contents of the array after each value is "inserted" into the maxheap. Use a vertical line to separate the elements in the array that are part of maxheap with those that are not. The first four steps are shown below for you along with the corresponding maxheaps. You do not have to draw the maxheaps in your answer. 45  28 58 30 89 64 75 12 41 4545 28  58 30 89 64 75 12 41 45/2858 28 45  30 89 64 75 12 41 58/ \28 4558 30 45 28  89 64 75 12 41 58/ \30 45/28b. Using your heap from part (a), trace the Heap Sort algorithm to transform the array to a sorted array in increasing order. Show the contents of the array after the element in index 0 (the root of the heap) is moved to its correct position and the remaining heap is fixed. Use a vertical bar to separate the elements that still belong to the heap from those that don't belong to the heap (i.e. the sorted part of the array). 3. (2 pts) 16 values are being sorted using the following sorting algorithms: Insertion Sort, Selection Sort, Quick Sort and Merge Sort. For each sort, two snapshots are given below. Each snapshot shows the order of the elements at that given point in the algorithm. The first snapshot is taken before the second snapshot. Identify which sort is being used for each algorithm and explain how you determined your answer....
View
Full
Document
This note was uploaded on 12/19/2009 for the course CS 121 taught by Professor Reidmiller during the Spring '09 term at Carnegie Mellon.
 Spring '09
 ReidMiller

Click to edit the document details