hw1sol - Advanced Analysis of Algorithms - Homework I...

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

View Full Document Right Arrow Icon
Advanced Analysis of Algorithms - Homework I (Solutions) K. Subramani LCSEE, West Virginia University, Morgantown, WV { ksmani@csee.wvu.edu } 1 Problems 1. Solve the following recurrences: (a) T ( n ) = T ( n ) + 1 . (b) T ( n ) = 4 T ( n 2 ) + n 2 · log n . Solution: (a) Substitute n = 2 k . The recurrence then becomes: T (2 k ) = T (2 k 2 ) + 1 . Use G ( k ) to denote T (2 k ) . Accordingly, the recurrence can be written as: G ( k ) = G ( k 2 ) + 1 . Using any of the methods discussed in class or [CLRS01], it can be shown that G ( k ) = log k . Thus, T (2 k ) = log k , from which it follows that T ( n ) = log log n . (b) We can directly use the Master Theorem. In this case, a = 4 , b = 2 and f ( n ) = n 2 log n . Thus, f ( n ) Θ( n log b a · log 1 n ) , from which it follows that T ( n ) = Θ( n 2 log 2 n ) . 2 2. Professor Krustowski claims to have discovered a new sorting algorithm. Given an array A of n numbers, his algorithm breaks the array into 3 equal parts of size n 3 , viz., the first third, the middle third and the bottom third. It then recursively sorts the first two-thirds of the array, the bottom two-thirds of the array and finally the first two-thirds of the array again. Using mathematical induction, prove that the Professor has indeed discovered a correct sorting algorithm. You may assume the following: The input size n is always some multiple of 3 ; additionally, the algorithm sorts by brute-force, when n is exactly 3 . Solution: As per the specifications, the algorithm works correctly, when n 3 . Assume that the algorithm works correctly, as long as 1 n k , where k > 3 . Now consider the case where the array
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.

Page1 / 3

hw1sol - Advanced Analysis of Algorithms - Homework I...

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