hw2 - CS161 - Homework 2 Due: Thursday July 9, 5pm 1. (24...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
CS161 - Homework 2 Due: Thursday July 9, 5pm 1. (24 points, 3 each) (CLRS 4-4, subproblems a-g,j (pg. 86). You only need to provide upper bounds (i.e. O ) for recurrences you don’t solve using the master method. 2. (5 points) CLRS 4.3-2 (pg. 75). Explain your answer. 3. (25 points) There are some situations where we are asked to sort data that is almost sorted. A k -sorted array contains no element that is more than k positions from it’s position in the properly sorted array. For the questions below, A is a k -sorted array with k << n : (a) (10 points) What are the runtimes of Insertion-Sort , Merge-Sort and Quicksort on A ? Explain your answers. (b) (5 points) What is the runtime of Bubble-Sort on A (see pseu- docode below)? Explain your answer. Bubble-Sort(A) 1 sorted false 2 while sorted = false 3 sorted true 4 for i 1 to length [ A ] - 1 5 if A [ i ] > A [ i + 1] 6 swap A [ i ] and A [ i + 1] 7 sorted false (c) (10 points) Write pseudocode and provide the runtime for an
Background image of page 1

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

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

This document was uploaded on 05/25/2011.

Page1 / 3

hw2 - CS161 - Homework 2 Due: Thursday July 9, 5pm 1. (24...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online