hw1-solns

# hw1-solns - Illinois Institute of Technology Department of...

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

Illinois Institute of Technology Department of Computer Science Solutions to Homework Assignment 1 CS 430 Introduction to Algorithms Spring Semester, 2009 1. Problem 2.3-3 on page 36 Solution: The base case is when n = 2, and we have n lg n = 2lg2 = 2 · 1 = 2. For the inductive step, our inductive hypothesis is that T ( n /2) = ( n /2)lg( n /2). Then T ( n ) = 2 T ( n /2) + n = 2( n /2)lg( n /2) + n = n (lg n - 1) + n = nlgn - n + n = n lg n , which completes the inductive proof for exact powers of 2. 2. Problem 2.3-4 on page 37 Solution: Since it take Θ( n ) time in the worst case to insert A[ n ] into the sorted array A[1. . n -1], we get the recurrence T ( n ) = ½ Θ(1) if n = 1 T ( n - 1) + Θ( n ) if n > 1 The solution to this recurrence is T ( n ) = Θ( n 2 ) 3. Problem 2-3(a) on page 39 Solution: cost times 1 y 0 c 1 1 2 i n c 2 1 3 while i 0 c 3 n +1 4 do y a i + x · y c 4 n +1 5 i i - 1 c 5 n +1 The running time of the algorithm is the sum of running times for each statement executed:

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.

{[ snackBarMessage ]}

### Page1 / 2

hw1-solns - Illinois Institute of Technology Department of...

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

View Full Document
Ask a homework question - tutors are online