Question
True/False (10) Chapter 10 - Queues, Deques, and Priority Queues Queues are used in operating systems. The item most recently added to a queue is
True/False (10)
Chapter 10 - Queues, Deques, and Priority Queues
-
Queues are used in operating systems.
-
The item most recently added to a queue is at the back of the queue.
-
Unlike a stack, a queue does not restrict access to its entries.
-
The Java Class Library interface for Queue has no operation to modify the contents of the front
entry.
-
You can push, pop and get items at either end of the ADT deque.
-
The Queue interface extends the Deque interface.
-
A priority queue cannot have null entries
-
The null value can be used to signal failure to remove or retrieve an entry from a priority queue
when it is empty.
-
The Java Class Library ADT PriorityQueue uses the compareTo method to determine how to
order entries.
-
The ArrayDeque class implements the Stack interface.
Short Answer (5)
1. Draw the contents of the queue after the following statements execute. Clearly label the front and back of the queue.
QueueInterface
bankLine .enqueue(Drew); bankLine .enqueue(Heather); bankLine .enqueue(David); next = bankLine .dequeue();
2. Draw the contents of the queue after the following statements execute. Clearly label the front and back of the queue.
QueueInterface
next = bankLine .dequeue(); bankLine .enqueue(Drew); bankLine .enqueue(Heather); next = bankLine .dequeue(); bankLine .enqueue(David); next = bankLine .dequeue();
3. Describe what happens when the following code is executed.
QueueInterface
bankLine .enqueue(Heather); next = bankLine .dequeue(); next = bankLine .dequeue(); bankLine .enqueue(Nancy); next = bankLine .dequeue(); next = bankLine .dequeue();
4. Draw the contents of the deque after the following statements execute. Clearly label the front and back of the deque.
DequeInterface
String name = waitingLine.getFront();
5. Draw the contents of the deque after the following statements execute. Clearly label the front and back of the deque.
DequeInterface
String name = waitingLine.getFront(); name = getFront();
Multiple Choice (30)
-
Which of the following real-world events could be simulated using a queue?
-
bank line
-
a shared network printer
-
restaurant reservation list
-
all of the above
-
-
The ____ ADT organizes its entries according to the order in which they were added.
-
queue
-
stack
-
list
-
priority queue
-
3. What a. first-in first-out
type of behavior defines a queue?
-
first-in last-out
-
last-in first-out
-
none of the above
-
How does a queue organize it items?
-
according to the order in which they were added
-
by priority
-
alphabetically
-
randomly
-
-
Where does a queue add new items?
-
at the back
-
at the front
-
in the middle
-
randomly
-
-
Where will you find the item added earliest to a queue?
-
at the front
-
at the back
-
in the middle
-
randomly
-
-
The method for adding a new item to the back of a queue is called a. enqueue
-
dequeue
-
getFront
-
none of the above
-
The method for removing an item from the front of a queue is called
-
dequeue
-
enqueue
-
getFront
-
none of the above
-
-
The method for retrieving the queues front entry without altering the queue is called
-
getFront
-
enqueue
-
dequeue
-
none of the above
-
-
A common alias for the queue method enqueue is
-
put
-
add
-
insert
-
all of the above
-
-
A common alias for the queue method dequeue is
-
get
-
remove
-
delete
-
all of the above
-
-
A common alias for the queue method getFront is
-
peek
-
get
-
put
-
all of the above
-
-
The dequeue method
-
throws an exception if the queue is empty
-
returns the item at the front of the queue
-
removes the item at the front of the queue
-
all of the above
-
-
After the following statements execute, what item is at the front of the queue? QueueInterface
zooDelivery = new LinkedQueue<>();
zooDelivery .enqueue(lion); zooDelivery .enqueue(tiger); zooDelivery .enqueue(cheetah); String next = zooDelivery .dequeue(); next = zooDelivery .dequeue(); zooDelivery .enqueue(jaguar);
-
cheetah
-
jaguar
-
tiger
-
lion
15. After the following statements execute, what item is at the back of the queue? QueueInterface
zooDelivery .enqueue(cheetah); String next = zooDelivery .dequeue(); next = zooDelivery .dequeue(); zooDelivery .enqueue(jaguar);
-
jaguar **
-
cheetah
-
tiger
-
lion
16. When a. time-driven simulation
a counter enumerates simulated time units, it is called a(n)
-
clock simulation
-
event-driven simulation
-
all of the above
-
In order to modify the front entry of a queue
-
you need a set method defined
-
you need to dequeue the front entry, modify the contents, and then use the requeue
method to place it back on the front of the queue
-
you cannot modify it under any circumstances
-
none of the above
-
-
The Java Class Library interface Queue method to put an entry on the back of a queue that throws an exception of the method fails is
a. add b. offer c. put d. poll
-
The Java Class Library interface Queue method to put an entry on the back of a queue that returns false if the method fails is
a. offer b. add c. put d. poll
-
The Java Class Library interface Queue method that retrieves and removes the entry at the front of a queue and throws a NoSuchElementException if the queue was empty is
a. remove b. poll c. retrieve d. get
-
The Java Class Library interface Queue method that retrieves and removes the entry at the front of a queue and returns null if the queue was empty is
a. poll b. remove c. retrieve d. get
-
The Java Class Library interface Queue method that retrieves the entry at the front of a queue
but throws a NoSuchElementException if the queue was empty is
a. empty b. peek c. poke d. look
23. The Java Class Library interface Queue method that retrieves the entry at the front of a queue but returns null if the queue was empty is
a. peek b. empty c. poke d. look
24. A deque ADT behaves a. like a queue
-
like a stack
-
both a & b
-
none of the above
-
What item is at the front of the list after these statements are executed?
DequeInterface
waitingLine = new LinkedDeque<>(); waitingLine.addToFront(Jack); waitingLine.addToFront(Rudy); waitingLine.addToBack(Larry); waitingLine.addToBack(Sam); String name = waitingLine.getFront();
a. Jack b. Rudy c. Larry d. Sam
-
What item is at the front of the list after these statements are executed?
DequeInterface
waitingLine = new LinkedDeque<>(); waitingLine.addToFront(Jack); waitingLine.addToFront(Rudy); waitingLine.addToBack(Larry); waitingLine.addToBack(Sam); String name = waitingLine.getBack();
a. Rudy b. Jack c. Larry d. Sam
-
The ADT priority queue organizes objects a. according to priority of the objects b. alphabetically c. from front to back
d. from back to front
-
What item is at the front of the list after these statements are executed?
DequeInterface
waitingLine = new LinkedDeque<>(); waitingLine.addToFront(Jack);
waitingLine.addToBack(Rudy); waitingLine.addToBack(Larry); waitingLine.addToFront(Sam); String name = waitingLine.getFront(); name = getBack(); waitingLine.addtoBack(Adam);
a. Jack b. Rudy c. Adam d. Sam
-
What item is at the front of the list after these statements are executed?
DequeInterface
waitingLine = new LinkedDeque<>(); waitingLine.addToBack(Adam); waitingLine.addToFront(Rudy); waitingLine.addToBack(Larry); waitingLine.addToBack(Sam); waitingLine.addtoFront(Jack); String name = waitingLine.getFront(); name = getFront();
a. Adam b. Rudy c. Jack d. Sam
-
The _____ ADT that has operations to add, remove, or retrieve entries at both the front and back of a queue is called a
-
deque
-
reversible queue
-
reversible stack
-
all of the above
-
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started