hw6solutions - ECE 369 Homework #6 Solutions (Sixth...

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

View Full Document Right Arrow Icon
ECE 369 Homework #6 Solutions (Sixth Edition) Section 2.6 15) In Selection Sort, the index of the maximum item in a list must be found. This requires comparisons between list elements. In an n-element (unsorted) list how many such comparisons are needed in the worst case to find the maximum element.? How many are needed in the average case? n-1 compares are always needed --every element after the first must be considered a potential new maximum. 16) Define the basic operation as the comparison of list elements and ignoring the amount of work required to exchange list elements, write a recurrence relation for the amount of work done by selection sort on an n-element list. C(1)=0 (no comparisons are required since a 1-element list is always sorted) C(n)= (n-1)+C(n-1) (n-1 compares to find the maximum element + # of compares to sort the list minus the las$ for n>=2 17) Solve the recurrence of (16). This is a first order linear recurrence relation with constant coefficients. By equation (8) of section 2.4. the solution is C(n) = 1^(n-1)(0) + \sum(i=2 to n)(1)^(n-i)(i-1) = (n-1)n/2 18) MergeSort requires comparing elements from each of two sorted lists to see what goes next into the combined sorted list.Given the following pairs of lists perform a merge and count the number of comparisons to merge the two lists into one. a. 6,8,9 and 1,4,5 b. 1,5,8 and 2,3,4 c. 0,2,3,4,7,10 and 1,8,9 a. the merged list is 1,4,5,6,8,9 3 comparisons - 6 vs 1,6 vs 4,6 vs 5 b. the merged list is 1,2,3,4,5,8 4 comparisons - 1 vs 2, 5 vs 2, 5 vs 3, 5 vs 4
Background image of page 1

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

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

This note was uploaded on 09/24/2009 for the course ECE 369 taught by Professor Bagchi during the Spring '08 term at Purdue University.

Page1 / 5

hw6solutions - ECE 369 Homework #6 Solutions (Sixth...

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