Problem:
Question 1- Determine the growth function and order of the following code fragment: for (int count = 0; count < n; count ++) { for (int count2 = 0; count2 < n; count2 = count2 + 2) { System.out.println(count, count2); } }
Question 2- Determine the growth function and order of the following code fragment: for (int count = 0; count < n; count ++) { for (int count2 = 0; count2 < n; count2 = count2 * 2) { System.out.println(count, count2); } }
Question 3- Hand trace a stack X through the following operations: X.push(new Integer(4)); X.push(new Integer(3)); Integer Y = X.pop(); X.push(new Integer(7)); X.push(new Integer(2)); X.push(new Integer(5)); X.push(new Integer(9)); Integer Y = X.pop(); X.push(new Integer(3)); X.push(new Integer(9));
question 4- Given the resulting stack X from the previous exercise, what would be the result of each of the following? A) Y = X.peek(); B) Y = X.pop(); Z = X.peek(); C) Y = X.pop(); Z = X.peek();
Question 2- What should be the time complexity of the isEmpty(), size(), and toString() methods?
Any help would be greatly appreciated!