What type of data structures are queues?
2024
What type of data structures are queues?
- A.
Last in first out
- B.
Last in last out
- C.
First in last out
- D.
First in first out
Attempted by 705 students.
Show answer & explanation
Correct answer: D
A data structure's access pattern is classified by comparing what happens to the FIRST element added relative to when it is removed. Exactly two standard terms exist for this: a stack removes the most-recently-added element first (Last In, First Out - LIFO), and a queue removes the earliest-added element first (First In, First Out - FIFO).
Enqueue 1, then 2, then 3 at the rear of the queue - the queue now holds [1, 2, 3] with 1 at the front.
Dequeue removes from the front: element 1 leaves first.
The next dequeue removes element 2, then finally element 3.
Element 1, the FIRST one inserted, is also the FIRST one removed - this is exactly First In First Out (FIFO), the defining behaviour of a queue.
A student might argue that 'Last in, last out' says the same thing as FIFO, since the element inserted last is indeed removed last too - but data-structure classification names are not built by permuting temporal endpoints. For a queue, exactly one established term applies: FIFO (First In, First Out). ('First in, last out' is sometimes used as an alternate name for a STACK's LIFO behaviour, not a queue's - it restates the same stack rule from the other end.) 'Last in, last out' is not used anywhere as a classification for any data structure - it is a constructed phrase, not an accepted term - so only 'First in first out' correctly identifies how a queue is classified.