Queue Review
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?
DCBA
In Java 6.0, the sequence interface represents a _______ queue
Double ended
T/F: a double linked list required the same amount of storage as that of a single linked list
False
T/F: although reallocating an array is an O(n) operation, it is amortized over n terms, so the cost per item is O(n^2)
False
T/F: in EmptyQueueException is associated with the action of attempting to remove an item from an empty queue
False
Two Java classes that implement deque are
Linked list and array deque
A(n) __________ is a data structure in which objects are inserted at one end and removed from the other
Queue
One difference between a queue and a stack is what
Queues use two ends of the structure and stack uses only one
T/F: in computer science, queues are used in operating systems to keep track of tasks waiting for a scarce resource and to ensure that the tasks are carried out in the order that they were generated
True
T/F: you can implement a queue as a single linked list
True
T/F: you can use a sequence object to implement a stack
True
Which of the following contains a syntax error
public Boolean isEmpty { Return size ==0; }
In a(n) _______ array, the elements wrap around so that the first element actually follows the last
Circular
If the queue is empty, element() method throws a(n) ________ exception
NoSuchElement
If a linked list is used, insertion at the rear of a queue is a(n) _________ operation
O(1)
If a single linked list is used to implement a queue (using variable front and rear) insertion can be done in _______ time
O(1)
Removal from the front of a queue is a(n) _______ operation
O(1)
When a queue is implemented using a circular array, insertion at the front is ______
O(1)
When a queue is implemented using a circular array, removal from the rear is _______
O(1)
If a non-circular array is used to implement a queue, insertion at the front of an _____ operation instead of O(1)
O(n)
15. Complete the following code. /*Insert an item at the rear of the queue. Post: item is added to the rear of the queue. @param item @return true Public boolean ___ (E item) { // Check for empty queue. If (front == null){ Rear = new Node<E> (item); Front = rear; } else { rear.next=new Node<E>(item; Rear = rear.next; } Size ++; Return true; }
Offer
14. Complete the following code: Public E___________(){ if( size() ==0 ) Return null; Else Return theQueue.getFirst(); }
Peek
Consider implementation of queue using a regular 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)
The poll() method would require linear time
Suppose we have a circular array implementation of the queue class, with 10 items in the queue stored at data[2] through data[11]. The current capacity is 24. Where does the insert method place the new entry in the array?
data[12]