Question & Answer: With respect to runtime complexity (using big-Oh notation), order the following from the fastest to the slowest: log n, 1…..

With respect to runtime complexity (using big-Oh notation), order the following from the fastest to the slowest: (7.5 points) log n, 1000, n log n, n, 2n, n Write a printReverse method that prints all items on a stack (sent in as a parameter), from the bottom of the stack to the top. (Thus, the top item will be printed last.) (7.5 points)

Thanks!

With respect to runtime complexity (using big-Oh notation), order the following from the fastest to the slowest: log n, 1000, n log n, n^3, 2^n, n Write a printReverse method that prints all items on a stack (sent in as a parameter), from the bottom of the stack to the top. (Thus, the top item will be printed last.)

Expert Answer

 

import java.util.Stack;
public class TestStackCode {
static Stack<Character> objStack = new Stack<>();
static void insert_at_bottom_check(char x) {
if (objStack.isEmpty())
objStack.push(x);
else {
char ObjA = objStack.peek();
objStack.pop();
insert_at_bottom_check(x);
objStack.push(ObjA);
}
}
static void reverse_Order() {
if (objStack.size() > 0) {
char objX = objStack.peek();
objStack.pop();
reverse_Order();
insert_at_bottom_check(objX);
}
}
public static void main(String[] args) {
objStack.push(‘1’);
objStack.push(‘2’);
objStack.push(‘3’);
objStack.push(‘4’);
System.out.println(“Original Stack Check”);
System.out.println(objStack);
reverse_Order();
System.out.println(“Reversed Stack Check”);
System.out.println(objStack);
}
}

Output screenshot:

Order image:

Still stressed from student homework?
Get quality assistance from academic writers!