Академический Документы
Профессиональный Документы
Культура Документы
Big-O Notation
1) (10 points) Write the following Big-O bounds in order, from smallest to largest (hint – create a table
and see how the values grow as n increases):
O(n²), O(1.01n), O((log n)²), O(n √n), O(n log n), O(n0.0001), O(1)
Using big-O notation in terms of the parameter n, how much time do the following methods take? Give the
tightest and simplest bound possible, and justify your answer.
2) (5 points)
int n = 1000;
System.out.println("Hey - your input is: " + n);
ANS: O( )
3) (5 points)
for (int i = 0; i < n; i++) {
System.out.println("looking at: " + i);
}
ANS: O( )
4) (5 points)
for (int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
System.out.println("looking at: " + i + " and " + j);
}
}
ANS: O( )
5) (5 points)
for (int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
System.out.println("looking at: " + i + " and " + j);
}
}
for (int i = 1; i <= n; i++) {
for(int j = 1; j <= n; j++) {
System.out.println("looking at: " + i + " and " + j);
}
}
ANS: O( )
________________________________________________________________________________
This homework is intended for you to review and practice the material presented in class. Therefore, please work
independently on this assignment.
Data Structures
Assignment 3 (60 points)
6) (10 points)
public static int pow(int m, int n) {
int ret = 1;
for (int i = 0; i < n; i++) {
ret *= m;
}
return ret;
}
ANS: O( )
7) (10 points)
public static int mystery(int n) {
int count = 0;
int cur = 1;
while (cur < n) {
count++;
cur = cur * 2;
}
return cur;
}
ANS: O( )
ANS: ____
9) (5 points) What is the big-o notation to find the n-th item in an unsorted list?
a. O(n)
b. O(n!)
c. O(n2)
d. O(log n)
ANS: ____
________________________________________________________________________________
This homework is intended for you to review and practice the material presented in class. Therefore, please work
independently on this assignment.