homework9_001

homework9_001 - 15-121 FALL 2009[CORTINA]HOMEWORK 9 due...

Info iconThis preview shows pages 1–3. 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: 15-121 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 min-heap below: 18/ \34 26/ \ / \60 46 52 89/ \ 75 91a. Using the min-heap 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 originalmin-heap 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 max-heap out of an array of elements, showing the contents of the array after each value is "inserted" into the max-heap. Use a vertical line to separate the elements in the array that are part of max-heap with those that are not. The first four steps are shown below for you along with the corresponding max-heaps. You do not have to draw the max-heaps 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 Reid-miller during the Spring '09 term at Carnegie Mellon.

Page1 / 6

homework9_001 - 15-121 FALL 2009[CORTINA]HOMEWORK 9 due...

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

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