Question
4. We are using stack to evaluate a postfix expression. If we feed the following values what final values will be stored at the stack?
4. We are using stack to evaluate a postfix expression.
If we feed the following values what final values will be stored at the stack? (hint: Use the logic in the book)
2 4 -1 *
Select one:
a. 2 4 -1 *
b. 6
c. 2 -4
d. -8
5. Stacks operate as _______
Select one.
a. First In, First out
b. arrays
c. Last in, First Out
d. Last out, First In
6. What is missing in the following code?
Public T pop() throws EmptyCollectionException
{
If(isEmpty())
Throw new EmptyCollectionException(Stack);
T result = stack[top];
Stack[top] = null;
Return result;
}
Select one;
a. Top++;
b. Top--;
c. Nothing
d. Expand
7. We are using stack to evaluate a postfix expression.
If we feed the following values what final values will be stored at the stack? ( hint: use the logic in the book)
2 4 -1 * +
Select one;
a. -2
b. 2 -4
c. 2 4 -1 * +
d. -8
Given the following sequence: push(8), pop(), push(9)
Assume we have an initial size of 5 for the array implementation. What would the top pointer show?
Select one;
a. 8
b. 0
c. 7
d. 9
9. Pop operation has O(1) time complexity.
Select one;
a. True
b. False
10. What would the following program print?
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));
System.out.print(Y);
Select one:
a. 2
b. 3
c. 7
d. 9
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started