sample-exam1-solns

sample-exam1-solns - Illinois Institute of Technology...

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

View Full Document Right Arrow Icon
Illinois Institute of Technology Department of Computer Science Solutions to First Examination CS 430 Introduction to Algorithms Fall, 2007 10am–11:15am, Wednesday, September 26, 2007 121 Life Sciences 1. (a) n 2 (2 n ) 2 = 4 n 2 so the algorithm takes 4 times as long (b) n 3 (2 n ) 3 = 8 n 3 so the algorithm takes 8 times as long (c) 100 n 100 · (2 n ) = 200 n so the algorithm takes 2 times as long (d) n lg n (2 n ) lg(2 n ) = 2 n lg n + 2 n so the algorithm takes a bit more than 2 times as long AS n - > (e) 2 n 2 2 n = 4 n = 2 n · 2 n so the algorithm takes 2 n times as long (or, the time is SQUARED). For an increase by 1: (a) n 2 ( n + 1) 2 = n 2 + 2 n + 1 so the algorithm takes an extra (2 n + 1) units of time (b) n 3 ( n + 1) 3 = n 3 + 3 n 2 + 3 n + 1 so the algorithm takes an extra (3 n 2 + 3 n + 1) units of time (c) 100 n 100( n + 1) = 100 n + 100 so the algorithm takes 100 units of time (d) n lg n ( n + 1) lg( n + 1) n lg n + lg n so the algorithm takes about an extra lg n units of time (e) 2 n 2 n +1 = 2 · 2 n so the algorithm takes 2 times as long 2. We modify merge sort to count the number of inversions(pair ( i, j ) is called inversion if and only if i < j and A [ i ] > A [ j ], the number of inversions is the same as the number of comparisons in insertion sort) in Θ( n lg n ) time. To start, let us de±ne a merge-inversion as a situation within the execution of merge sort in which the MERGE procedure, after copying A [ p..q ] to L and A [ q + 1 ..r ] to R , has values x in L and y in R such that x > y . Consider an inversion (
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 note was uploaded on 04/07/2009 for the course CS 430 taught by Professor Kapoor during the Spring '08 term at Illinois Tech.

Page1 / 3

sample-exam1-solns - Illinois Institute of Technology...

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