
CSC 1052 Homework 4 - Queue
Multiple Choice
1. One difference between a queue and a stack is:
oA. Queues require linked lists, but stacks do not.
oB. Stacks require linked lists, but queues do not.
oC. Queues use two ends of the structure; stacks use only one.
oD. Stacks use two ends of the structure, queues use only one.
o
2. If the characters 'D', 'C', 'B', 'A' are placed in a queue (in that order), and then
removed one at a time, in what order will they be removed?
oA. ABCD
oB. ABDC
oC. DCAB
oD. DCBA
3. Suppose we have a circular array implementation of the queue class, with ten items
in the queue stored at data[2] through data[11]. The current capacity is 12. Where
does the insert method place the new entry in the array?
oA. data[1]
oB. data[0]
oC. data[11]
oD. data[12]
o
4. Consider the implementation of the Queue using a circular array. What goes wrong
if we try to keep all the items at the front of a partially-filled array (so that data[0] is
always the front).
oA. The constructor would require linear time.
oB. The remove method would require linear time.
oC. The insert method would require linear time.
oD. The isEmpty method would require linear time.
5. In the circular array version of the Queue class, which operations require linear
time for their worst-case behavior?
oA. remove
oB. insert when the capacity has not yet been reached
oC. isEmpty
oD. None of these operations require linear time.
6. If data is a circular array of CAPACITY elements, and rear is an index into that
array, what is the formula for the index after rear?
oA. (rear % 1) + CAPACITY
oB. rear % (1 + CAPACITY)
oC. (rear + 1) % CAPACITY
oD. rear + (1 % CAPACITY)
1