# hwk2 - the term Hint 2 Try some small examples(n=1,2,3,4...

This preview shows page 1. Sign up to view the full content.

Fall 2011 CMSC 351: Homework 2 Clyde Kruskal Due at the start of class Wednesday, September 21, 2011. The following algorithm for sorting is called slowsort : i 1 while i < n do if A[i] > A[i+1] then A[i] A[i+1] i 1 else i i + 1 end if end while Problem 1. (a) What is the worst case input for comparisons for slowsort. (No justification needed.) (b) Write a summation (actually nested summations) for how many comparisons slowsort uses in the worst case. Hint 1: The algorithm has a final pass to confirm that the list is sorted. Leave this pass out of your summation (but do not drop
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: the term). Hint 2: Try some small examples (n=1,2,3,4 etc.). (c) Simplify your summation. (d) What is the high order term? (e) Write the worst-case running time in order notation. Problem 2. (a) Write a summation (actually nested summations) for how many comparisons slowsort uses in the average case. (b) Simplify your summation. (c) What is the high order term? (d) Write the average-case running time in order notation....
View Full 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