Multiple Choices
-
A queue is generally endowed with operations called…
- Requeue
- Dequeue
- Enqueue
- Unqueue
-
A queue implements which principle?
- LIFO
- FIFO
- LILO
- FOFI
-
LIFO stands for…
- Least Is First Out
- Last Is First Outside
- Last In First Out
- Low Input Fast Output
Exercises
-
Suppose given an empty
Queueobject, and assume that we store the values 10 and 20 (in that order), and then remove one and insert 30. Draw the resulting queue, labelling explicitly the front (or beginning) and end of your queue.Solution
We get: (end →) 30 ; 20 (← front).
Problem
-
This problem is about min-priority queue, i.e., queues where the most important element is the one with the lowest priority. Draw the priority queue after
- Inserting values with priority 10, 2, 5, 7,
- Removing the most important element,
- Inserting values with priority 3, 12,
(you can either draw the queue after each step, or only at the very end)
-
If the queue is implemented using an array.
Solution
This is supposing an implementation like the one shared in class.
We decompose each step:- Insert value with priority 10
- Insert value with priority 2
- Insert value with priority 5
- Insert value with priority 7
- Remove value with priority 2 (the lowest in the queue)
- Insert value with priority 3
- Insert value with priority 12
Solution
Step \ Index 0 1 2 3 4 5 1 10 nullnullnullnullnull2 10 2 nullnullnullnull3 10 2 5 nullnullnull4 10 2 5 7 nullnull5 10 null5 7 nullnull6 10 3 5 7 nullnull7 10 3 5 7 12 null -
If the queue is implemented using a binary heap.
Solution
This is supposing an implementation like the one shared in class.
We decompose each step:- Insert value with priority 10
- Insert value with priority 2
- Insert value with priority 5
- Insert value with priority 7
- Remove value with priority 2 (the lowest in the queue)
- Insert value with priority 3
- Insert value with priority 12
Solution
Step \ Index 0 1 2 3 4 5 1 10 nullnullnullnullnull2 2 10 nullnullnullnull3 2 10 5 nullnullnull4 2 7 5 10 nullnull5 5 7 10 nullnullnull6 3 5 10 7 nullnull7 3 5 10 7 12 null