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.
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.
 Spring '08
 BAGCHI
 Selection Sort

Click to edit the document details