homework9_001

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

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

15-121 FALL 2009 [CORTINA] HOMEWORK 9 - due Friday, November 20 by 11:59PM ELECTRONIC HANDIN AVAILABLE BY MONDAY 5PM PROGRAMMING PROBLEM REVISED PROBLEMS (10 pts) 1. (1.5 pts) Consider the min-heap below: 18 / \ 34 26 / \ / \ 60 46 52 89 / \ 75 91 a. 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 original min-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 41 Trace 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 45 45 28 | 58 30 89 64 75 12 41 45 / 28 58 28 45 | 30 89 64 75 12 41 58 / \

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

View Full Document
28 45 58 30 45 28 | 89 64 75 12 41 58 / \ 30 45 / 28 b. 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.
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern