Carrano Chapter 8
What is the action performed by the enqueue operation?
The enqueue operation adds a new item at the back of a queue. It throws a QueueException if the operation is not successful.
The ______ operation retrieves and removes the front of a queue. isEmpty enqueue dequeue peek
dequeue
The pop operation of the ADT stack is similar to the ______ operation of the ADT queue. isEmpty enqueue dequeue peek
dequeue
If a queue is implemented as the ADT list, which of the following queue operations can be implemented as list.remove(1)? enqueue() dequeue() isEmpty() peek()
dequeue()
Which of the following methods of QueueInterface does NOT throw a QueueException? enqueue dequeue dequeueAll peek
dequeueAll
The ______ operation adds a new item to a queue. enqueue dequeue push peek
enqueue
If a string is added to a stack, characters removed from the stack will occur in the order in which they appear in the original string.
false
In a time-driven simulation, no action is required between events.
false
In an event-driven simulation of a bank, the arrival of a customer is an internal event.
false
New items enter a queue at its front.
false
Operations of the ADT stack can be viewed as general versions of the list and queue operations.
false
Rightward drift is a problem that is encountered in a reference-based implementation of a queue.
false
Write the code fragment to remove the front item of a queue that contains more than one items and which is represented by a circular linked list. ;
firstNode = lastNode.getNext(); lastNode.setNext(firstNode.getNext())
Which of the following code fragments is used to delete the item at the front of a queue represented by a circular array? front = MAX_QUEUE - front; --count; front = front - back; --count; front = (front+1) % MAX_QUEUE; --count; front = (back+1) % MAX_QUEUE; --count;
front = (front+1) % MAX_QUEUE; --count;
In an event-driven simulation of a bank, which of the following equations can be used to determine the time of a customer's departure? time of next departure = current time - arrival time time of next departure = time service begins + length of transaction time of next departure = arrival time + length of transaction time of next departure = current time - (arrival time + time service begins)
time of next departure = time service begins + length of transaction
In a queue, items can be added ______. only at the front of the queue only at the back of the queue either at the front or at the back of the queue at any position in the queue
only at the back of the queue
If a queue is implemented as the ADT list, which of the following queue operations can be implemented as list.get(1)? enqueue() dequeue() isEmpty() peek()
peek
The ______ operation retrieves the item that was added earliest to a queue, but does not remove that item. enqueue dequeue dequeueAll peek
peek
Which of the following operations leaves a queue unchanged? enqueue dequeue dequeueAll peek
peek
Which of the following is NOT an ADT queue operation? enqueue isEmpty pop peek
pop
The Java ______ operator is used to obtain the wraparound effect of a circular array-based queue. * + % /
%
To initialize a queue that is represented by a circular array, front is set to ______. 0 1 MAX_QUEUE MAX_QUEUE - 1
0
What is a deque?
A deque is an ADT that allows for insertions and deletions at both ends.
What is an event-driven simulation?
A simulation that uses events generated by a mathematical model that is based on statistics and probability.
What is meant by the first-in, first-out property of a queue?
According to the first-in, first-out property of a queue, the first item inserted into a queue is the first item to leave the queue.
What is the difference between an external event and an internal event?
An external event is an event that is determined from the input data to an event-driven simulation. An internal event is an event that is determined by a computation within an event-driven simulation.
What is the advantage an implementation of a queue that uses the ADT list over an implementation that uses a linked list?
An implementation of a queue that uses the ADT list is much simpler to write and read than an implementation that uses a linked list.
What is the goal of a simulation?
Generally, the goal of a simulation is to generate statistics that summarize the performance of an existing system or to predict the performance of a proposed system.
What is the main difference between a stack and a queue?
In a stack, all operations are performed at the top of the stack. As a result, the first item to enter the stack is the last item to leave the stack. In contract, operations are performed at both ends of a queue. In a queue, the first item to enter the queue is the first item to leave the queue.
Give two examples of run-time errors or exceptions that may occur when we enqueue or dequeue.
It's an error to attempt to dequeue from an empty queue. Also, if the queue is represented as an array and we try to enqueue, we may run up against the maximum size of the queue.
To initialize a queue that is represented by a circular array, back is set to ______. 0 1 MAX_QUEUE MAX_QUEUE - 1
MAX_QUEUE - 1
Define the problem of rightward drift in an array-based implementation of a queue.
Rightward drift is the problem of the front of the queue moving toward the end of the array.
What is the action performed by the dequeue operation?
The dequeue operation retrieves and removes the front of a queue - the item that was added earliest. It throws a QueueException if the operation is not successful.
What is the action performed by the dequeueAll operation?
The dequeueAll operation removes all items from a queue.
What is the action performed by the peek operation?
The peek operation retrieves the front of a queue, but does not change the queue. That is, it retrieves the item that was added earliest. It throws a QueueException if the retrieval is not successful.
What are three examples of position-oriented ADT?
Three position-oriented ADTs are the list, the stack and the queue.
If an object is inserted into a queue, how soon can it be removed? Answer: We have to wait for all of the other elements to be dequeued first, because of the inherent FIFO policy of queues.
We have to wait for all of the other elements to be dequeued first, because of the inherent FIFO policy of queues.
If you wanted to write a program to simulate queues in front a bank teller, on what basis would you decide on a maximum size of your queue?
We would first consider how many people could realistically be waiting on line at the same time.
An event list for an event-driven simulation of a bank contains ______. all arrival events all arrival events that will occur but have not occurred yet all departure events all departure events that will occur but have not occurred yet all arrival and departure events that will occur but have not occurred yet
all arrival and departure events that will occur but have not occurred yet
In the ADT list, items can be added ______. only at the front of the list only at the back of the list either at the front or at the back of the list at any position in the list
at any position in the list
Write the code fragment to insert the item newItem into a queue that is represented by a circular array.
back = (back+1) % MAX_QUEUE; items[back] = newItem; ++count;
Operations on a queue can be carried out at ______. its front only its back only both its front and back any position in the queue
both its front and back
Which of the following is true about a time-driven simulation of a bank? arrival times are obtained from an input file transaction times are obtained from an input file currentTime is incremented by 1 to simulate the ticking of a clock no action is required between events
currentTime is incremented by 1 to simulate the ticking of a clock
The ADT ______ allows you to insert into, delete from, and inspect the item at any position of the ADT. stack queue list array
list
In an implementation of a queue uses the ADT list, which of the following can be used to implement the operation enqueue(newItem)? list.add(list.size(), newItem) list.add(list.size()+1, newItem) list.add(newItem.size(), newItem) list.add(newItem.size()+1, newItem)
list.add(list.size()+1, newItem)
A reference-based implementation of a queue that uses a circular linked list would need at least ______ external references. one two three four
one
Write the code fragment to insert a new node, referenced by newNode, into a nonempty queue represented by a circular linked list.
newNode.setNext(lastNode.getNext()); lastNode.setNext(newNode); lastNode = newNode;
Which of the following is the code to insert a new node, referenced by newNode, into an empty queue represented by a circular linked list? newNode.setNext(lastNode); lastNode.setNext(lastNode); lastNode = newNode; newNode.setNext(lastNode); newNode = lastNode; newNode.setNext(newNode); lastNode = newNode;
newNode.setNext(newNode); lastNode = newNode;
The enqueue operation of the ADT queue is similar to the ______ operation of the ADT stack. isEmpty peek push pop
push
Which of the following is an operation of the ADT stack? enqueue push add get
push
The line of customers in a bank can be represented as a(n) ______. list queue stack array
queue
Which of the following ADTs is like a line of people? list stack queue tree
queue
Which of the following is an operation of the ADT list? pop dequeue peek remove
remove
In an event-driven simulation of a bank, which of the following is an internal event? the arrival at the bank of a new customer the start of the transaction of a customer the end of the transaction of a customer the departure from the bank of a customer
the departure from the bank of a customer
A queue can be used to preserve the order of occurrences.
true
In an event-driven simulation of a bank, the departure times of customers are determined by the simulation.
true
The addition of an item to an empty queue is a special case.
true
The first item to be added to a queue is the first item to be removed from the queue.
true
A reference-based implementation of a queue that uses a linear linked list would need at least ______ external references. one two three four
two