DATA STRUCTURES STACK EXAM
WITH CORRECT ANSWERS
T/F In the Java API class java.util.Stack<E> implements a stack; there is no Stack
interface - Correct Answers -True
T/F an array can be used for storage of a stack instead of using a Java ArrayList class -
Correct Answers -True
T/F the statement Stack<String> myStack = new Stack<String>(); defines a stack that
holds String objects - Correct Answers -True
T/F there is only one stack interface in Java - Correct Answers -False
A(n) _ is a data structure in which objects are inserted into and removed from the same
end - Correct Answers -Stack
A(n) _ is a string that reads the same in either direction: left to right or right to left -
Correct Answers -Palindrome
In terms of efficiency all stack operations using an array structure are - Correct Answers
-O(1)
The value of the following postfix expression is 12+4*3+ - Correct Answers -15
Rewrite the following statement as an infix expression 56* 10- - Correct Answers -5*6-
10
A(n) _ is a data structure with the property that only the top element is accessible -
Correct Answers –Stack
Consider the implementation of the stack using an array. What goes wrong if we try to
store the top of the stack at location [0] and the bottom of the stack at the last used
position if the array - Correct Answers -Both push and pop would require linear time
In the linked list implementation of the stack class where does the push method place
the new entry on the linked list - Correct Answers -At the head
In the array version of the stack class, which operations require linear time for their
worst case (is empty, peek, pop) - Correct Answers -None
WITH CORRECT ANSWERS
T/F In the Java API class java.util.Stack<E> implements a stack; there is no Stack
interface - Correct Answers -True
T/F an array can be used for storage of a stack instead of using a Java ArrayList class -
Correct Answers -True
T/F the statement Stack<String> myStack = new Stack<String>(); defines a stack that
holds String objects - Correct Answers -True
T/F there is only one stack interface in Java - Correct Answers -False
A(n) _ is a data structure in which objects are inserted into and removed from the same
end - Correct Answers -Stack
A(n) _ is a string that reads the same in either direction: left to right or right to left -
Correct Answers -Palindrome
In terms of efficiency all stack operations using an array structure are - Correct Answers
-O(1)
The value of the following postfix expression is 12+4*3+ - Correct Answers -15
Rewrite the following statement as an infix expression 56* 10- - Correct Answers -5*6-
10
A(n) _ is a data structure with the property that only the top element is accessible -
Correct Answers –Stack
Consider the implementation of the stack using an array. What goes wrong if we try to
store the top of the stack at location [0] and the bottom of the stack at the last used
position if the array - Correct Answers -Both push and pop would require linear time
In the linked list implementation of the stack class where does the push method place
the new entry on the linked list - Correct Answers -At the head
In the array version of the stack class, which operations require linear time for their
worst case (is empty, peek, pop) - Correct Answers -None