Chapter 12: Introduction to Collections and Stacks
Chapter 13: Linked Structures and Stacks
Chapter 14: Queues
Multiple Choice Questions:
1) A stack is a ___________________ data structure.
a) LIFO
b) FIFO
c) link based
d) array based
e) none of the above
Answer: a
Explanation: A stack is a LIFO (last in, first out) data structure. This means that the last element to be put on the stack will be the first element that is removed.
2) Which of the following is not an operation on a stack?
a) push
b) pop
c) peek
d) dequeue
e) all of the above are operations on a stack
Answer: d
Explanation: The dequeue operation is a queue operation.
3) A queue is a ____________________ data structure.
a) LIFO
b) FIFO
c) link based
d) array based
e) none of the above
Answer: b
Explanation: A queue is a FIFO (first in, first out) data structure, meaning that the first element that is put into the queue is the first element to be removed from the queue.
4) Which of the following is not a queue operation?
a) enqueue
b) dequeue
c) first
d) isEmpty
e) all of the above are queue operations
Answer: e
Explanation: All of the listed operations are queue operations.
5) Which of the following is not a valid postfix expression?
a) 5 4 +
b) 6 5 4 + –
c) 4 + 5
d) 8 2 + 2 /
e) all of the above are valid postfix expressions
Answer: c
Explanation: Choice c is in infix notation, not postfix.
6) What is the result of evaluating the following postfix expression: 4 8 + 2 *
a) 40
b) 24
c) 64
d) 20
e) none of the above are correct
Answer: b
Explanation: Converting this postfix expression to infix notation yields the following expression: (4+8) * 2. This is equal to 24.
7) What exception is thrown if the pop method is called on an empty stack?
a) EmptyStackException
b) NoSuchElementException
c) ArrayOutOfBoundsException
d) EmptyCollectionException
e) none of the above
Answer: d
Explanation: If a pop method is called on an empty stack, the EmptyCollectionException is thrown.
8) Which of the following methods removes an element from a queue?
a) enqueue
b) dequeue
c) first
d) pop
e) push
Answer: b
Explanation: The dequeue method removes an element from a queue.
9) Which of the following methods inserts an element into a stack data structure?
a) enqueue
b) dequeue
c) push
d) pop
e) peek
Answer: c
Explanation: The push method inserts an element into a stack.
10) A queue is helpful in implementing a __________________ sort.
a) insertion
b) selection
c) quick
d) radix
e) merge
Answer: d
Explanation: A queue is helpful in implementing a radix sort.
Reviews
There are no reviews yet.