{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

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.
Background image of page 1

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

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

{[ snackBarMessage ]}