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

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

View Full Document Right Arrow Icon
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 justi±cation needed.) (b) Write a summation (actually nested summations) for how many comparisons slowsort uses in the worst case. Hint 1: The algorithm has a ±nal pass to con±rm that the list is sorted. Leave this pass out of your summation (but do not drop
Background image of page 1
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

This note was uploaded on 01/13/2012 for the course CMSC 351 taught by Professor Staff during the Fall '11 term at University of Louisville.

Ask a homework question - tutors are online