| Overview | Schedule | Resources | Assignments | Home |
| 16 | 8 | 11 | 4 | 5 | 2 | 9 | 13 |
Consider the following code fragment:
for ( int i = 0; i < n - 1; i++ ) {
for ( int j = 0; j < n - 1; j++ ) {
System.out.println( "Hello!" );
}
}
How many "Hello!"s are printed? Give an exact answer (in terms of n) as well as an answer in O( ) notation.
You have a problem for which you are considering two different algorithms, named A and B. It is known that the running time of A is O(n2), while the running time of B is O(n3). Running the two algorithms on some test data, where n is 100, reveals that both take about the same amount of time. If the real data size is more like 100,000 items, which algorithm will be the better choice, and by how much?
Consider the following function.
public 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 for each of the following method calls:
Questions, short answer and otherwise, could also be asked about the following topics:
The exam will be closed-book, closed-notes. It will be designed to be completed in 1 hour. It will be held Wednesday, September 27, in class.
| Overview | Schedule | Resources | Assignments | Home |
![]()
DePauw University,
Computer Science Department,
Fall 2006
Maintained by Brian Howard
(bhoward@depauw.edu).
Last updated