sola2F06

sola2F06 - CS340 Fall 2006 Solution of Assignment 2...

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

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.

Unformatted text preview: CS340 - Fall 2006 Solution of Assignment 2 Algorithm Analysis and Linear Data Structures 1. Exercise 2.1 page 62 (6pts) 2 /N, 37 , √ N,N,N log log N,N log 2 N,N log N, N log ( N 2 ) ,N 1 . 5 , N 2 ,N 2 log N,N 3 , 2 N/ 2 , 2 N . N log N and N log ( N 2 ) grow at the same level. 2 N/ 2 and 2 N belong to the same class (exponential). We can also consider that N log 2 N = N log log N 2. Exercise 2.6 page 62 (8pts) (a) 2 2 N (b) O (log log D ) 3. Exercise 2.7 (question a) page 62 (10pts) (I) O ( N ). (II) O ( N 2 ). (III) O ( N 3 ). (IV) O ( N 2 ). (V) j can be as large as i 2 , which could be as large as N 2 . k can be as large as j , which is N 2 . The running time is thus proportional to NN 2 N 2 , which is O ( N 5 ). (VI) The if statement is executed at most N 3 times, by previous arguments, but it is true only O ( N 2 ) times (because it is true exactly i times for each i ). Thus the innermost loop is only executed O ( N 2 ) times. Each time through, it takes O ( j 2 ) = O ( N 2 ) time, for a total of O ( N 4 ). This is an example where multiplying loop sizes can occasionally give an overestimate.loop sizes can occasionally give an overestimate....
View Full Document

This note was uploaded on 11/15/2010 for the course CS 375 taught by Professor Dr.butz during the Fall '10 term at University of Regina.

Page1 / 3

sola2F06 - CS340 Fall 2006 Solution of Assignment 2...

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

View Full Document
Ask a homework question - tutors are online