T/F
15 n + 100 n2 = O(n2)
T/F
6 n log n + 4 n = O(n)
T/F
log(n2) + 4 log(log n) = O(log n)
T/F
2 n1/2 + 34 = O(n2)
T/F
3n + 100 n2 + n200 = O(2n)
String [ ][ ] str = new String[n][n]; for(int k = 0; k < n; k++) foobar(str[k]);
public Stack crazyStackMethod(int[][] a) { Stack stack = new Stack(); for(int i = 0; i < a.length; i++) { for(int j = 0; j < a.length; j++) { Stack tempStack = new Stack(); stack.push(a[i][j]); while(!stack.isEmpty()) { tempStack.push(stack.pop()); } stack = tempStack; } } return stack; }
public class Stack { private Queue Q = new Queue(); public E pop() { int k = 1; while( k++ < Q.size() )Q.enqueue(Q.dequeue()); return Q.dequeue(); } public void push(E o) { Q.enqueue(o); } }
If Q.enqueue(o) and Q.dequeue() takes O(1) time what is the worst-case runtime complexities of push(o) and pop()?