Ch7 - Queues, Deques, And Priority Queues Verified Test Bank - Data Structures with Java 5e Complete Test Bank by Frank M. Carrano. DOCX document preview.
Chapter 7 - Queues, Deques, and Priority Queues
True/False (10)
- 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)
- Draw the contents of the queue after the following statements execute. Clearly label the front and back of the queue.
QueueInterface<String> bankLine = new LinkedQueue<>();
bankLine .enqueue(“John”);
bankLine .enqueue(“Matthew”);
String next = bankLine .dequeue();
bankLine .enqueue(“Drew”);
bankLine .enqueue(“Heather”);
bankLine .enqueue(“David”);
next = bankLine .dequeue(); - Draw the contents of the queue after the following statements execute. Clearly label the front and back of the queue.
QueueInterface<String> bankLine = new LinkedQueue<>();
bankLine .enqueue(“John”);
bankLine .enqueue(“Matthew”);
String next = bankLine .dequeue();
next = bankLine .dequeue();
bankLine .enqueue(“Drew”);
bankLine .enqueue(“Heather”);
next = bankLine .dequeue();
bankLine .enqueue(“David”);
next = bankLine .dequeue();
- Describe what happens when the following code is executed.
QueueInterface<String> bankLine = new LinkedQueue<>();
bankLine .enqueue(“John”);
bankLine .enqueue(“Matthew”);
String next = bankLine .dequeue();
bankLine .enqueue(“Heather”);
next = bankLine .dequeue();
next = bankLine .dequeue();
bankLine .enqueue(“Nancy”);
next = bankLine .dequeue();
next = bankLine .dequeue();
- Draw the contents of the deque after the following statements execute. Clearly label the front and back of the deque.
DequeInterface<String> waitingLine = new LinkedDeque<>();
waitingLine.addToFront(“Jack”);
waitingLine.addToFront(“Rudy”);
waitingLine.addToBack(“Larry”);
waitingLine.addToBack(“Sam”);
String name = waitingLine.getFront();
- Draw the contents of the deque after the following statements execute. Clearly label the front and back of the deque.
DequeInterface<String> waitingLine = new LinkedDeque<>();
waitingLine.addToBack(“Adam”);
waitingLine.addToFront(“Rudy”);
waitingLine.addToBack(“Larry”);
waitingLine.addToBack(“Sam”);
waitingLine.addtoFront(“Jack”);
String name = waitingLine.getFront();
name = getFront();
Multiple Choice (30) WARNING: CORRECT ANSWERS ARE IN THE SAME POSITION AND TAGGED WITH . YOU SHOULD RANDOMIZE THE LOCATION OF THE CORRECT ANSWERS IN YOUR EXAM.
- 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
- What type of behavior defines a queue?
- first-in first-out
- 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
- 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 queue’s 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<String> 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”
- After the following statements execute, what item is at the back of the queue?
QueueInterface<String> zooDelivery = new LinkedQueue<>();
zooDelivery .enqueue(“lion”);
zooDelivery .enqueue(“tiger”);
zooDelivery .enqueue(“cheetah”);
String next = zooDelivery .dequeue();
next = zooDelivery .dequeue();
zooDelivery .enqueue(“jaguar”);- “jaguar”
- “cheetah”
- “tiger”
- “lion”
- When a counter enumerates simulated time units, it is called a(n)
- time-driven simulation
- 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 if the method fails is
- add
- offer
- put
- 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
- offer
- add
- put
- 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
- remove
- poll
- retrieve
- 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
- poll
- remove
- retrieve
- 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
- element
- peek
- poke
- look
- 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
- peek
- empty
- poke
- look
- A deque ADT behaves
- 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<String> waitingLine = new LinkedDeque<>();
waitingLine.addToFront(“Jack”);
waitingLine.addToFront(“Rudy”);
waitingLine.addToBack(“Larry”);
waitingLine.addToBack(“Sam”);
String name = waitingLine.getFront();- Rudy
- Jack
- Larry
- Sam
- What item is at the front of the list after these statements are executed?
DequeInterface<String> waitingLine = new LinkedDeque<>();
waitingLine.addToFront(“Jack”);
waitingLine.addToFront(“Rudy”);
waitingLine.addToBack(“Larry”);
waitingLine.addToBack(“Sam”);
String name = waitingLine.getBack();- Rudy
- Jack
- Larry
- Sam
- The ADT priority queue organizes objects
- according to priority of the objects
- alphabetically
- from front to back
- from back to front
- What item is at the front of the list after these statements are executed?
DequeInterface<String> waitingLine = new LinkedDeque<>();
waitingLine.addToFront(“Jack”);
waitingLine.addToBack(“Rudy”);
waitingLine.addToBack(“Larry”);
waitingLine.addToFront(“Sam”);
String name = waitingLine.getFront();
name = getBack();
waitingLine.addtoBack(“Adam”);- Sam
- Rudy
- Adam
- Jack
- What item is at the front of the list after these statements are executed?
DequeInterface<String> waitingLine = new LinkedDeque<>();
waitingLine.addToBack(“Adam”);
waitingLine.addToFront(“Rudy”);
waitingLine.addToBack(“Larry”);
waitingLine.addToBack(“Sam”);
waitingLine.addtoFront(“Jack”);
String name = waitingLine.getFront();
name = getFront();- Jack
- Rudy
- Adam
- 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
Document Information
Connected Book
Data Structures with Java 5e Complete Test Bank
By Frank M. Carrano