Deck 8: Queues

ملء الشاشة (f)
exit full mode
سؤال
The structure of a queue lends itself to either an array implementation or a linked implementation.
استخدم زر المسافة أو
up arrow
down arrow
لقلب البطاقة.
سؤال
Performing a pop operation on an empty queue throws an exception.
سؤال
The array implementation of a queue must access items at the logical beginning and the logical end.
سؤال
In the array implementation of a queue, the pop operation is most efficient if the front of the queue is fixed at index position 0.
سؤال
The list data structure in Python cannot be used to emulate a queue because there is no pop method.
سؤال
In computer science, process scheduling can be handled by simple or priority queues.
سؤال
By using a circular array implementation, you can simultaneously achieve good running times for both add and pop .
سؤال
The peek operation on a queue returns the item at the back of the queue without removing it.
سؤال
Both classes, LinkedStack and LinkedQueue, use a singly linked Node class to implement nodes.
سؤال
The add operation for a queue adds a node at the head of the structure.
سؤال
The most common type of CPU scheduling technique is called last in, first-out.
سؤال
The ready queue contains processes waiting to use the CPU.
سؤال
Each process on the ready queue is pushed onto a stack before being given a slice of CPU time.
سؤال
Similar to stacks, queues support a FILO protocol.
سؤال
An example of a computer simulation that can use queues is traffic flow on a busy highway.
سؤال
Queues are linear collections.
سؤال
A checkout line at a grocery store is an example of a queue.
سؤال
The two fundamental operations supported by queues are pop and insert.
سؤال
Simulation programs can use a range of integer values to mimic variability in the simulation.
سؤال
In a priority queue, items waiting in the queue the longest are always popped next.
سؤال
Which of the following is true about a standard queue?

A) the item that has been waiting the shortest is popped next
B) the items are popped in LIFO order
C) the item that has been waiting the longest is popped next
D) removals are done from the rear of the queue
سؤال
What happens to processes on the ready queue in a round-robin CPU scheduling scheme?

A) they are pushed and put in the priority queue
B) they are popped and allocated memory
C) they are pushed to the end of the queue
D) they are popped and given a slice of CPU time
سؤال
What type of collection is a queue?

A) linear
B) parallel
C) random
D) geometric
سؤال
When using a circular array implementation for a queue, during the add operation, the front pointer moves ahead of the rear pointer.
سؤال
In a linked implementation of a queue, what does the add operation do?

A) adds a node to the head
B) adds a node to the tail
C) inserts a node in the middle
D) creates a new instance of the queue
سؤال
Which protocol is supported by queues?

A) last-in first-out
B) last-in last-out
C) first-in first-out
D) first-in last-out
سؤال
What is the precondition to using the pop method on a queue?

A) the queue must not be empty
B) the queue must be full
C) the queue must not be full
D) the queue must first be resized
سؤال
When items are removed from a priority queue, items of lower priority are removed before those of higher priority.
سؤال
What is the returned value and the state of the queue after the operation is executed? Current queue state: x a z b
Q.peek()

A) b, x a z b
B) x, a z b
C) x, x a z b
D) b, x a z
سؤال
When using a circular array implementation for a queue, when either pointer is about to run off the end of the array, that pointer is reset to -1.
سؤال
What is one reason that it is difficult to devise formulas to answer simple questions about a supermarket checkout system?

A) the variability of essential factors
B) the regularity in which customers arrive
C) because customers always purchase the same number of items
D) because the same number of customers are there at all times of the day
سؤال
Which of the following is NOT true of a priority queue?

A) higher-priority items are popped before those of lower priority
B) items of equal priority are popped in LIFO order
C) items of equal priority are popped according to which item arrived first
D) higher-priority items can jump ahead of lower-priority items
سؤال
When using a circular array implementation for a queue, you maintain a count of the items in the queue to determine if it is full or empty.
سؤال
How would you use a Python list method to remove and return an item at the front of the queue?

A) peek(len(queue)-1)
B) peek(1)
C) pop(len(queue)-1)
D) pop(0)
سؤال
Which example best represents a queue?

A) print jobs sent to a printer
B) a pickup game of football
C) items selected via a random number generator
D) people exiting a sporting event
سؤال
What are the two fundamental operations of a queue?

A) insert, push
B) insert, pop
C) push, add
D) add, pop
سؤال
In the supermarket simulation, which of the following would be a property of a Cashier object?

A) assigns customers to cashiers
B) a queue of customer objects
C) a variable to track when service is received
D) generates new customer objects
سؤال
Which type of computer activity would likely be assigned to the priority queue?

A) a background process that defragments the disk
B) sending email
C) mouse movement
D) a background process that releases unused memory blocks
سؤال
When items are added to a priority queue, they are assigned an order of rank.
سؤال
Which of the following is NOT an important factor to consider by a manager of a supermarket trying to schedule checkout cashiers?

A) the frequency with which new customers arrive
B) the number of checkout cashiers available
C) the number of items in a customer's shopping cart
D) the number of aisles in the supermarket
سؤال
What must occur when a wrapped item is accessed with the peek or pop method in a priority queue?

A) it must be added to the priority queue
B) it must be unwrapped
C) it must be compared to the next item
D) it must be discarded
سؤال
In the following code for the pop method for a linked queue implementation, what is the missing code?
Def pop(self):
OldItem = self.front.data
Self.front = self.front.next
If self.front is None:
Self.rear = None
< missing code >
Return oldItem

A) self.rear -= 1
B) self.front = self.rear
C) self.size -= 1
D) self.size += 1
سؤال
What is the solution to achieving good performance for both the add and pop methods in the array implementation of a queue?

A) using a front pointer that advanced through the array
B) using a fixed front pointer to index position 0
C) using an insert function instead of add
D) using a circular array implementation
سؤال
What can you do if items in a priority queue cannot use the comparison operators?

A) user a wrapper class
B) remove them from the queue
C) remove them in FIFO order
D) put them in the back of the queue
سؤال
In the following code for the __eq__ method for the Comparable class, what is the missing code? def __eq__(self, other):
If self is other: return True
If type(self) != type(other): < missing code >
Return self.priority == other.priority

A) return type(other)
B) return other
C) return False
D) return self.priority
سؤال
Which of the following is NOT true of a priority queue?

A) when items are added, they are assigned an order of rank
B) items of higher priority are removed before those of lower priority
C) items of higher priority are removed in FIFO order
D) items of equal priority are removed in FIFO order
سؤال
What is the initial value of the front and rear instance variables in the linked queue?

A) -1
B) 0
C) None
D) 1
سؤال
In a priority queue, what does the add method do when handling a new item and the new item is greater than or equal to the item at the rear?

A) it adds the item to the front
B) it puts the item in a wrapper
C) it adds the item to the rear
D) it increases the size of the queue
سؤال
In the following code for the add method for a linked queue implementation, what is the missing code? def add(self, newItem):
NewNode = Node(newItem, None)
If self.isEmpty():
Self.front = newNode
Else:
Self.rear.next = newNode
< missing code >
Self.size += 1

A) self.rear = newNode
B) self.rear -= 1
C) self.rear.prev = None
D) self.front = self.next
سؤال
In the linked priority queue, what is the time and space analysis for the add method?

A) O( n2 )
B) exponential
C) logarithmic
D) O( n )
فتح الحزمة
قم بالتسجيل لفتح البطاقات في هذه المجموعة!
Unlock Deck
Unlock Deck
1/50
auto play flashcards
العب
simple tutorial
ملء الشاشة (f)
exit full mode
Deck 8: Queues
1
The structure of a queue lends itself to either an array implementation or a linked implementation.
True
2
Performing a pop operation on an empty queue throws an exception.
True
3
The array implementation of a queue must access items at the logical beginning and the logical end.
True
4
In the array implementation of a queue, the pop operation is most efficient if the front of the queue is fixed at index position 0.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
5
The list data structure in Python cannot be used to emulate a queue because there is no pop method.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
6
In computer science, process scheduling can be handled by simple or priority queues.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
7
By using a circular array implementation, you can simultaneously achieve good running times for both add and pop .
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
8
The peek operation on a queue returns the item at the back of the queue without removing it.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
9
Both classes, LinkedStack and LinkedQueue, use a singly linked Node class to implement nodes.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
10
The add operation for a queue adds a node at the head of the structure.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
11
The most common type of CPU scheduling technique is called last in, first-out.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
12
The ready queue contains processes waiting to use the CPU.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
13
Each process on the ready queue is pushed onto a stack before being given a slice of CPU time.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
14
Similar to stacks, queues support a FILO protocol.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
15
An example of a computer simulation that can use queues is traffic flow on a busy highway.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
16
Queues are linear collections.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
17
A checkout line at a grocery store is an example of a queue.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
18
The two fundamental operations supported by queues are pop and insert.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
19
Simulation programs can use a range of integer values to mimic variability in the simulation.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
20
In a priority queue, items waiting in the queue the longest are always popped next.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
21
Which of the following is true about a standard queue?

A) the item that has been waiting the shortest is popped next
B) the items are popped in LIFO order
C) the item that has been waiting the longest is popped next
D) removals are done from the rear of the queue
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
22
What happens to processes on the ready queue in a round-robin CPU scheduling scheme?

A) they are pushed and put in the priority queue
B) they are popped and allocated memory
C) they are pushed to the end of the queue
D) they are popped and given a slice of CPU time
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
23
What type of collection is a queue?

A) linear
B) parallel
C) random
D) geometric
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
24
When using a circular array implementation for a queue, during the add operation, the front pointer moves ahead of the rear pointer.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
25
In a linked implementation of a queue, what does the add operation do?

A) adds a node to the head
B) adds a node to the tail
C) inserts a node in the middle
D) creates a new instance of the queue
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
26
Which protocol is supported by queues?

A) last-in first-out
B) last-in last-out
C) first-in first-out
D) first-in last-out
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
27
What is the precondition to using the pop method on a queue?

A) the queue must not be empty
B) the queue must be full
C) the queue must not be full
D) the queue must first be resized
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
28
When items are removed from a priority queue, items of lower priority are removed before those of higher priority.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
29
What is the returned value and the state of the queue after the operation is executed? Current queue state: x a z b
Q.peek()

A) b, x a z b
B) x, a z b
C) x, x a z b
D) b, x a z
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
30
When using a circular array implementation for a queue, when either pointer is about to run off the end of the array, that pointer is reset to -1.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
31
What is one reason that it is difficult to devise formulas to answer simple questions about a supermarket checkout system?

A) the variability of essential factors
B) the regularity in which customers arrive
C) because customers always purchase the same number of items
D) because the same number of customers are there at all times of the day
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
32
Which of the following is NOT true of a priority queue?

A) higher-priority items are popped before those of lower priority
B) items of equal priority are popped in LIFO order
C) items of equal priority are popped according to which item arrived first
D) higher-priority items can jump ahead of lower-priority items
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
33
When using a circular array implementation for a queue, you maintain a count of the items in the queue to determine if it is full or empty.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
34
How would you use a Python list method to remove and return an item at the front of the queue?

A) peek(len(queue)-1)
B) peek(1)
C) pop(len(queue)-1)
D) pop(0)
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
35
Which example best represents a queue?

A) print jobs sent to a printer
B) a pickup game of football
C) items selected via a random number generator
D) people exiting a sporting event
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
36
What are the two fundamental operations of a queue?

A) insert, push
B) insert, pop
C) push, add
D) add, pop
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
37
In the supermarket simulation, which of the following would be a property of a Cashier object?

A) assigns customers to cashiers
B) a queue of customer objects
C) a variable to track when service is received
D) generates new customer objects
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
38
Which type of computer activity would likely be assigned to the priority queue?

A) a background process that defragments the disk
B) sending email
C) mouse movement
D) a background process that releases unused memory blocks
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
39
When items are added to a priority queue, they are assigned an order of rank.
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
40
Which of the following is NOT an important factor to consider by a manager of a supermarket trying to schedule checkout cashiers?

A) the frequency with which new customers arrive
B) the number of checkout cashiers available
C) the number of items in a customer's shopping cart
D) the number of aisles in the supermarket
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
41
What must occur when a wrapped item is accessed with the peek or pop method in a priority queue?

A) it must be added to the priority queue
B) it must be unwrapped
C) it must be compared to the next item
D) it must be discarded
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
42
In the following code for the pop method for a linked queue implementation, what is the missing code?
Def pop(self):
OldItem = self.front.data
Self.front = self.front.next
If self.front is None:
Self.rear = None
< missing code >
Return oldItem

A) self.rear -= 1
B) self.front = self.rear
C) self.size -= 1
D) self.size += 1
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
43
What is the solution to achieving good performance for both the add and pop methods in the array implementation of a queue?

A) using a front pointer that advanced through the array
B) using a fixed front pointer to index position 0
C) using an insert function instead of add
D) using a circular array implementation
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
44
What can you do if items in a priority queue cannot use the comparison operators?

A) user a wrapper class
B) remove them from the queue
C) remove them in FIFO order
D) put them in the back of the queue
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
45
In the following code for the __eq__ method for the Comparable class, what is the missing code? def __eq__(self, other):
If self is other: return True
If type(self) != type(other): < missing code >
Return self.priority == other.priority

A) return type(other)
B) return other
C) return False
D) return self.priority
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
46
Which of the following is NOT true of a priority queue?

A) when items are added, they are assigned an order of rank
B) items of higher priority are removed before those of lower priority
C) items of higher priority are removed in FIFO order
D) items of equal priority are removed in FIFO order
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
47
What is the initial value of the front and rear instance variables in the linked queue?

A) -1
B) 0
C) None
D) 1
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
48
In a priority queue, what does the add method do when handling a new item and the new item is greater than or equal to the item at the rear?

A) it adds the item to the front
B) it puts the item in a wrapper
C) it adds the item to the rear
D) it increases the size of the queue
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
49
In the following code for the add method for a linked queue implementation, what is the missing code? def add(self, newItem):
NewNode = Node(newItem, None)
If self.isEmpty():
Self.front = newNode
Else:
Self.rear.next = newNode
< missing code >
Self.size += 1

A) self.rear = newNode
B) self.rear -= 1
C) self.rear.prev = None
D) self.front = self.next
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
50
In the linked priority queue, what is the time and space analysis for the add method?

A) O( n2 )
B) exponential
C) logarithmic
D) O( n )
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.
فتح الحزمة
k this deck
locked card icon
فتح الحزمة
افتح القفل للوصول البطاقات البالغ عددها 50 في هذه المجموعة.