programming beginner 10 sample questions

Queues MCQ Practice Test

FIFO (First-In-First-Out) operations with efficient dequeue.

Q1. A priority queue is implemented using a min-heap. Three elements are enqueued: (priority 5, 'apple'), (priority 2, 'banana'), (priority 8, 'cherry'). Two elements are then dequeued. What data is at the root of the heap?

Explanation: The min-heap always dequeues the smallest priority first: 'banana' (2), then 'apple' (5). That leaves only 'cherry' (priority 8) at the root. The old key ('banana') was the first element dequeued, not the one remaining.

Q2. A bakery uses a queue to manage customer orders. The first order received is for a croissant, followed by a muffin, then a bagel. If the baker fulfills orders in a FIFO (First-In, First-Out) manner, what baked good will be completed *second*?

Explanation: In a FIFO queue, elements are processed in the order they were added. The croissant is first, followed by the muffin, then the bagel.

Q3. A queue is used to manage print jobs. Job A arrives at 1:00 PM, Job B at 1:05 PM, and Job C at 1:10 PM. Assuming a FIFO (First-In, First-Out) queue, what will be the order of completion if there are no interruptions?

Explanation: FIFO queues process elements in the order they were added. Since Job A arrived first, it will be completed first, followed by Job B, and then Job C.

Q4. A bakery uses a queue to manage customer orders. The first customer orders a croissant, the second a muffin, and the third a bagel. If the baker follows a FIFO (First-In, First-Out) approach, which item will be baked "second"?

Explanation: In a FIFO queue, the first element added is the first element removed. The croissant was added first, then the muffin, so the muffin is baked second.

Q5. A bakery uses a queue to manage customer orders. The first order received is for a croissant, followed by a muffin, then a bagel. After the croissant order is processed, what is the next item at the front of the queue?

Explanation: Queues operate on a First-In, First-Out (FIFO) basis. Since the croissant is processed first, the muffin, which was the second item added, moves to the front of the queue.

Q6. A bakery uses a queue to manage customer orders. The first customer orders a croissant, the second a muffin, and the third a bagel. If the baker processes orders in FIFO (First-In, First-Out) order, which item will be baked "last"?

Explanation: In a FIFO queue, the first element added is the first element removed. Since the bagel was added last, it will be processed last.

Q7. A bakery uses a queue to manage customer orders. The first order received is for a chocolate cake (C), followed by a blueberry muffin (B), then a croissant (R). If the baker completes orders in a FIFO (First-In, First-Out) manner, which order will be completed *second*?

Explanation: In a FIFO queue, the first element added is the first element removed. Since the chocolate cake was added first, it's completed first. The blueberry muffin was added second, making it the second order completed.

Q8. A bakery uses a queue to manage customer orders. The first customer to place an order is assigned order number 1, the second customer is assigned order 2, and so on. If customer orders are processed in a FIFO (First-In, First-Out) manner, which customer's order will be completed first if order numbers 7, 12, 3, and 9 are currently in the queue?

Explanation: Queues operate on a FIFO basis. The element that enters the queue first is the first one to leave. In this case, order number 3 entered the queue before all other orders.

Q9. A bakery uses a queue to manage customer orders. The first customer to arrive orders a croissant, the second a muffin, and the third a bagel. If the baker processes orders in FIFO (First-In, First-Out) order, which pastry will be baked "last"?

Explanation: In a FIFO queue, the first element added is the first element removed. Therefore, the bagel, added last, will be baked last.

Q10. Given a queue of tasks with associated deadlines, which of the following algorithms is used to schedule them to minimize the maximum lateness?

Explanation: The Earliest Deadline First (EDF) scheduling algorithm is a dynamic priority scheduling algorithm that schedules tasks based on their deadlines. It assigns a priority to each task based on its deadline and executes the task with the earliest deadline first. This algorithm is used to minimize the maximum lateness in a queue of tasks with deadlines.

That was just a sample. Sign up to unlock the full question bank with timed tests and certificates.

Sign Up Free
Queues MCQ Practice Test | Mind Hustle