Deck 8: Queues
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Question
Unlock Deck
Sign up to unlock the cards in this deck!
Unlock Deck
Unlock Deck
1/60
Play
Full screen (f)
Deck 8: Queues
1
Which of the following code fragments is used to delete the item at the front of a queue represented by a circular array?
A)front = MAX_QUEUE - front;
--count;
B)front = front - back;
--count;
C)front = (front+1)% MAX_QUEUE;
--count;
D)front = (back+1)% MAX_QUEUE;
--count;
A)front = MAX_QUEUE - front;
--count;
B)front = front - back;
--count;
C)front = (front+1)% MAX_QUEUE;
--count;
D)front = (back+1)% MAX_QUEUE;
--count;
C
2
To initialize a queue that is represented by a circular array,front is set to ______.
A)0
B)1
C)MAX_QUEUE
D)MAX_QUEUE - 1
A)0
B)1
C)MAX_QUEUE
D)MAX_QUEUE - 1
A
3
In a queue,items can be added ______.
A)only at the front of the queue
B)only at the back of the queue
C)either at the front or at the back of the queue
D)at any position in the queue
A)only at the front of the queue
B)only at the back of the queue
C)either at the front or at the back of the queue
D)at any position in the queue
B
4
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?
A)newNode.setNext(lastNode);
B)lastNode.setNext(lastNode);
LastNode = newNode;
C)newNode.setNext(lastNode);
NewNode = lastNode;
D)newNode.setNext(newNode);
LastNode = newNode;
A)newNode.setNext(lastNode);
B)lastNode.setNext(lastNode);
LastNode = newNode;
C)newNode.setNext(lastNode);
NewNode = lastNode;
D)newNode.setNext(newNode);
LastNode = newNode;
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
5
Which of the following methods of QueueInterface does NOT throw a QueueException?
A)enqueue
B)dequeue
C)dequeueAll
D)peek
A)enqueue
B)dequeue
C)dequeueAll
D)peek
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
6
The Java ______ operator is used to obtain the wraparound effect of a circular array-based queue.
A)*
B)+
C)%
D)/
A)*
B)+
C)%
D)/
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
7
Which of the following ADTs is like a line of people?
A)list
B)stack
C)queue
D)tree
A)list
B)stack
C)queue
D)tree
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
8
A reference-based implementation of a queue that uses a circular linked list would need at least ______ external references.
A)one
B)two
C)three
D)four
A)one
B)two
C)three
D)four
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
9
The ______ operation retrieves and removes the front of a queue.
A)isEmpty
B)enqueue
C)dequeue
D)peek
A)isEmpty
B)enqueue
C)dequeue
D)peek
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
10
Which of the following is NOT an ADT queue operation?
A)enqueue
B)isEmpty
C)pop
D)peek
A)enqueue
B)isEmpty
C)pop
D)peek
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
11
A reference-based implementation of a queue that uses a linear linked list would need at least ______ external references.
A)one
B)two
C)three
D)four
A)one
B)two
C)three
D)four
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
12
Which of the following operations leaves a queue unchanged?
A)enqueue
B)dequeue
C)dequeueAll
D)peek
A)enqueue
B)dequeue
C)dequeueAll
D)peek
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
13
The ______ operation retrieves the item that was added earliest to a queue,but does not remove that item.
A)enqueue
B)dequeue
C)dequeueAll
D)peek
A)enqueue
B)dequeue
C)dequeueAll
D)peek
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
14
The ______ operation adds a new item to a queue.
A)enqueue
B)dequeue
C)push
D)peek
A)enqueue
B)dequeue
C)push
D)peek
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
15
To initialize a queue that is represented by a circular array,back is set to ______.
A)0
B)1
C)MAX_QUEUE
D)MAX_QUEUE - 1
A)0
B)1
C)MAX_QUEUE
D)MAX_QUEUE - 1
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
16
The ADT ______ allows you to insert into,delete from,and inspect the item at any position of the ADT.
A)stack
B)queue
C)list
D)array
A)stack
B)queue
C)list
D)array
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
17
If a queue is implemented as the ADT list,which of the following queue operations can be implemented as list.remove(1)?
A)enqueue()
B)dequeue()
C)isEmpty()
D)peek()
A)enqueue()
B)dequeue()
C)isEmpty()
D)peek()
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
18
In an implementation of a queue uses the ADT list,which of the following can be used to implement the operation enqueue(newItem)?
A)list.add(list.size(),newItem)
B)list.add(list.size()+1,newItem)
C)list.add(newItem.size(),newItem)
D)list.add(newItem.size()+1,newItem)
A)list.add(list.size(),newItem)
B)list.add(list.size()+1,newItem)
C)list.add(newItem.size(),newItem)
D)list.add(newItem.size()+1,newItem)
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
19
Operations on a queue can be carried out at ______.
A)its front only
B)its back only
C)both its front and back
D)any position in the queue
A)its front only
B)its back only
C)both its front and back
D)any position in the queue
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
20
If a queue is implemented as the ADT list,which of the following queue operations can be implemented as list.get(1)?
A)enqueue()
B)dequeue()
C)isEmpty()
D)peek()
A)enqueue()
B)dequeue()
C)isEmpty()
D)peek()
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
21
Which of the following is an operation of the ADT list?
A)pop
B)dequeue
C)peek
D)remove
A)pop
B)dequeue
C)peek
D)remove
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
22
The line of customers in a bank can be represented as a(n)______.
A)list
B)queue
C)stack
D)array
A)list
B)queue
C)stack
D)array
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
23
Which of the following is true about a time-driven simulation of a bank?
A)arrival times are obtained from an input file
B)transaction times are obtained from an input file
C)currentTime is incremented by 1 to simulate the ticking of a clock
D)no action is required between events
A)arrival times are obtained from an input file
B)transaction times are obtained from an input file
C)currentTime is incremented by 1 to simulate the ticking of a clock
D)no action is required between events
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
24
In an event-driven simulation of a bank,the arrival of a customer is an internal event.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
25
In the ADT list,items can be added ______.
A)only at the front of the list
B)only at the back of the list
C)either at the front or at the back of the list
D)at any position in the list
A)only at the front of the list
B)only at the back of the list
C)either at the front or at the back of the list
D)at any position in the list
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
26
Operations of the ADT stack can be viewed as general versions of the list and queue operations.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
27
In an event-driven simulation of a bank,which of the following is an internal event?
A)the arrival at the bank of a new customer
B)the start of the transaction of a customer
C)the end of the transaction of a customer
D)the departure from the bank of a customer
A)the arrival at the bank of a new customer
B)the start of the transaction of a customer
C)the end of the transaction of a customer
D)the departure from the bank of a customer
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
28
New items enter a queue at its front.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
29
Which of the following is an operation of the ADT stack?
A)enqueue
B)push
C)add
D)get
A)enqueue
B)push
C)add
D)get
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
30
In an event-driven simulation of a bank,the departure times of customers are determined by the simulation.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
31
The enqueue operation of the ADT queue is similar to the ______ operation of the ADT stack.
A)isEmpty
B)peek
C)push
D)pop
A)isEmpty
B)peek
C)push
D)pop
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
32
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.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
33
The pop operation of the ADT stack is similar to the ______ operation of the ADT queue.
A)isEmpty
B)enqueue
C)dequeue
D)peek
A)isEmpty
B)enqueue
C)dequeue
D)peek
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
34
A queue can be used to preserve the order of occurrences.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
35
In a time-driven simulation,no action is required between events.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
36
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?
A)time of next departure = current time - arrival time
B)time of next departure = time service begins + length of transaction
C)time of next departure = arrival time + length of transaction
D)time of next departure = current time - (arrival time + time service begins)
A)time of next departure = current time - arrival time
B)time of next departure = time service begins + length of transaction
C)time of next departure = arrival time + length of transaction
D)time of next departure = current time - (arrival time + time service begins)
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
37
The addition of an item to an empty queue is a special case.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
38
The first item to be added to a queue is the first item to be removed from the queue.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
39
An event list for an event-driven simulation of a bank contains ______.
A)all arrival events
B)all arrival events that will occur but have not occurred yet
C)all departure events
D)all departure events that will occur but have not occurred yet
E)all arrival and departure events that will occur but have not occurred yet
A)all arrival events
B)all arrival events that will occur but have not occurred yet
C)all departure events
D)all departure events that will occur but have not occurred yet
E)all arrival and departure events that will occur but have not occurred yet
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
40
Rightward drift is a problem that is encountered in a reference-based implementation of a queue.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
41
What is meant by the first-in,first-out property of a queue?
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
42
What is a deque?
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
43
What is the action performed by the dequeue operation?
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
44
What is the action performed by the enqueue operation?
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
45
What is the goal of a simulation?
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
46
What is the difference between an external event and an internal event?
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
47
Write the code fragment to insert a new node,referenced by newNode,into a nonempty queue represented by a circular linked list.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
48
Write the code fragment to insert the item newItem into a queue that is represented by a circular array.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
49
What is the action performed by the dequeueAll operation?
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
50
What is the advantage an implementation of a queue that uses the ADT list over an implementation that uses a linked list?
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
51
What are three examples of position-oriented ADT?
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
52
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.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
53
If an object is inserted into a queue,how soon can it be removed?
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
54
Give an example of a queue that one may find in a computer system.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
55
Define the problem of rightward drift in an array-based implementation of a queue.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
56
Give two examples of run-time errors or exceptions that may occur when we enqueue or dequeue.
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
57
What is the action performed by the peek operation?
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
58
What is an event-driven simulation?
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
59
What is the main difference between a stack and a queue?
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck
60
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?
Unlock Deck
Unlock for access to all 60 flashcards in this deck.
Unlock Deck
k this deck