Homework_1-solution

Homework_1-solution - Homework 1 CSC122, Spring 2008 Due on...

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

View Full Document Right Arrow Icon

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

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

Unformatted text preview: Homework 1 CSC122, Spring 2008 Due on Tuesday Feb 19 th at midnight. answers are in blue 1. Consider the following code fragment: for ( int i = 0; i < n - 1; i++ ) { for ( int j = 0; j < n - 1; j++ ) { cout << “Hello!” << endl; } } How many “Hello!”s are printed? Give an exact answer (in terms of n ) as well as an answer in O( ) notation. a) n 2 – 2n + 1 times, or (n-1) 2 times b) O(n 2 ) 2. What is the O( ) of the following expressions? Explain your answers. (a) 1000 100 10 2 3 + + + n n n O(n 3 ) because O() is only a close estimation and you only keep the fastest growing term, which is n 3 . (b) 10 lg 2 + + n n n O(n 2 ) because O() is only a close estimation and you only keep the fastest growing term, which is n 2 . Consider the following function. void mystery( int n, int m ) { if ( m > n ) { System.out.print( m + “ “); mystery( m – 1, n ); } else if ( m < n ) { System.out.print( n + “ “); mystery( m + 1, n ); } else System.out.println( “Done” ); } What is the output of the following function call? mystery( 3, 3 )What is the output of the following function call?...
View Full Document

This note was uploaded on 04/17/2008 for the course COMPUTER S 221 taught by Professor Kadija during the Spring '08 term at DePauw.

Page1 / 5

Homework_1-solution - Homework 1 CSC122, Spring 2008 Due on...

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

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