Consider the following statements: i. First-in-first out types of computations…
19962024
Consider the following statements:
i. First-in-first out types of computations are efficiently supported by STACKS.
ii. Implementing LISTS on linked lists is more efficient than implementing LISTS on an array for almost all the basic LIST operations.
iii. Implementing QUEUES on a circular array is more efficient than implementing QUEUES on a linear array with two indices.
iv. Last-in-first-out type of computations are efficiently supported by QUEUES.
Which of the following is correct?
Answer: A. (ii) and (iii) are true — ConceptA stack and a queue are defined by the order in which they give stored items back, not by how the storage is laid out: a stack releases the item…
- A.
(ii) and (iii) are true
- B.
(i) and (ii) are true
- C.
(iii) and (iv) are true
- D.
(ii) and (iv) are true
Attempted by 188 students.
Show answer & explanation
Correct answer: A
Concept
A stack and a queue are defined by the order in which they give stored items back, not by how the storage is laid out: a stack releases the item inserted most recently (last-in-first-out), while a queue releases the item inserted earliest (first-in-first-out). How efficient an implementation is follows instead from the cost model of its primitives — a contiguous array reaches any position in constant time by index but must shift up to n neighbours to insert or delete, whereas a chain of linked nodes relinks in constant time at a position already reached but must be walked to reach that position. And taking an array index modulo the array length makes it wrap, so storage released at one end becomes reusable without moving anything.
Applying the concept to each statement
Statement i assigns first-in-first-out service to a STACK. By definition a stack pops the item pushed most recently, so whatever entered first leaves last; the service order named here is the one a queue provides, not a stack. This statement does not hold.
Statement ii compares the two LIST implementations over the basic LIST operations — insert, delete, splice and traverse onward from a position already reached. On a linked representation each of these is a constant-time pointer rearrangement and the structure grows one node at a time; on an array representation the same insert or delete shifts up to n elements, and the capacity is fixed until the whole block is reallocated and copied. Over that operation set the linked representation is the more efficient one, and that is how the statement is read. Indexed random access is the single operation where the array wins outright — see the cross-check below.
Statement iii compares two QUEUE implementations. With a linear array and two indices, every dequeue advances front and the cells it vacates at the low end are stranded: the queue reports itself full while most of the block sits empty, unless the remaining elements are shifted down at O(n) cost. Advancing front and rear modulo the array length makes rear wrap into those vacated cells, so enqueue and dequeue both stay O(1) and no capacity is wasted. This statement holds.
Statement iv assigns last-in-first-out service to a QUEUE. By definition a queue removes from the front, so whatever entered first leaves first; the service order named here is the one a stack provides, not a queue. This statement does not hold.
Cross-check
Basic LIST operation | Array representation | Linked representation |
|---|---|---|
Reach the k-th element | O(1) — direct indexing | O(k) — walk the chain |
Insert or delete at a position already reached | O(n) — shift the tail | O(1) — relink two pointers |
Grow past the current capacity | Reallocate the block and copy | Attach one more node |
The array wins exactly one row of that table, which is why statement ii is an examination-level simplification rather than a universal law; read over the basic LIST operations above, relinking dominates shifting.
Statements i and iv invert the two defining service orders, so every pairing that names either of them can be discarded: “(i) and (ii)”, “(iii) and (iv)” and “(ii) and (iv)” all fall away. Exactly one pairing is left naming only the two statements that hold, and it is the answer: (ii) and (iii) are true.