Answer the following questions, either in handwritten form or using some program that supports mathematical notation. In the following, assume that "log n" means "log2 n".
Order the following list of functions by their Big-Oh time complexity, such that if function f(n) is above or to the left of g(n), then f(n) = O(g(n)). (I.e., put them in order, fastest to slowest; more formally, order them by growth rate, from most slowly growing to most quickly growing.)
Algorithm A uses 10n log n operations, while algorithm B uses n 2 operations.
Determine the value n0 such that A is better than B for n >= n0.
Repeat the problem assuming B uses n sqrt(n) operations.
For each function f(n) and time t in the following table, determine the largest size n of a problem that can be solved in time t assuming that the algorithm to solve the problem takes f(n) microseconds. (Some entries have already been completed as examples.)
| 1 Second | 1 Hour | 1 Month | 1 Century | |
|---|---|---|---|---|
| log n | approx. 10300000 | |||
| sqrt(n) | ||||
| n | ||||
| n log n | ||||
| n2 | ||||
| n3 | ||||
| 2n | ||||
| n ! | 12 |
Prove or disprove:
12 is O( 1 ).
7n + 3n2 - 2 is O( n3 ).
max( n3, 10n2 ) is O(n2).
3n log n is Big-Omega( n ).
| f(n) = | n2 | for even n >= 0 | is O( n2 ). |
| n3 | for odd n >= 1 |
2n + 1 is O( 2n ).
If d(n) is O(f(n)) and e(n) is O(g(n)), then the product d(n)e(n) is O(f(n)g(n)).
Characterize the following summations (exactly) in terms of n:
| 5 | + | 5 | + | 5 | + | 5 | + | . . . | + | 5 |
| -- | -- | -- | --- | --- | ||||||
| 2 | 4 | 8 | 16 | 2n |
Sigma 1 <= i <= n ( 3i + 4 ) [where Sigma is the summation symbol].
Give a Big-Oh characterization, in terms of n, of the running time of each of the following Java methods.
public void ExA( int n ) {
int a;
for ( int i = 0; i < n; i += 2 )
a = i;
}
public void ExB( int n ) {
int a;
for ( int i = 0; i < n * n; i++ )
a = i;
}
public void ExC( int n ) {
int a;
for ( int i = 0; i < n; i++ )
for ( int j = 0; j <= i; j++ )
a = i;
}
public void ExD( int n ) {
int a;
for ( int i = 0; i < n * n; i++ )
for ( int j = 0; j <= i; j++ )
a = i;
}
public void ExE( int n ) {
int a;
for ( int i = 0; i < n; i++ )
for ( int j = 0; j <= n - i; j++ )
a = i;
}
public void ExF( int n ) {
int a;
for ( int i = 1; i < n; i *= 2 )
a = i;
}
Give an example of a positive function f(n) such that f(n) is neither O(n) nor Big-Omega( n ).
Would the function be Big-Omega( n ) if Big-Omega were redefined as follows?
f(n) is Big-Omega of g(n) if there is a real constant c > 0 such that f(n) >= c g(n) for infinitely many values of n.
Provide a proof for your conclusion.
The following conversation was overheard between a programmer and a computer scientist:
Estimate how long it would take the Computer Scientist's algorithm to solve the problem for 20 BogoUnits.
Estimate how long it would take the Programmer's program to solve the problem for 20 BogoUnits.
What additional information do you need to decide which solution is in fact better for the actual problem?
Submit a hardcopy of your solutions in hard copy form to the instructor by the due date specified.