This preview shows pages 1–2. Sign up to view the full content.
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 nelement (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?
n1 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 nelement list.
C(1)=0
(no comparisons are required since a 1element list is always sorted)
C(n)= (n1)+C(n1)
(n1 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^(n1)(0) + \sum(i=2 to n)(1)^(ni)(i1) = (n1)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
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
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.
 Spring '08
 BAGCHI
 Selection Sort

Click to edit the document details