(PLEASE EXPLAIN) A queue implemented in an array in the standard manner … A. is
ID: 3906074 • Letter: #
Question
(PLEASE EXPLAIN) A queue implemented in an array in the standard manner …
A.
is subject to false overflow.
B.
wraps around to recover deleted space, using front and rear pointers.
C.
wraps around to recover deleted space, using front and rear pointers, and is subject to false overflow. .
D.
shifts to recover deleted space, only uses a rear pointer and wraps around to recover deleted space, using front and rear pointers.
E.
shifts to recover deleted space, only uses a rear pointer.
A.
is subject to false overflow.
B.
wraps around to recover deleted space, using front and rear pointers.
C.
wraps around to recover deleted space, using front and rear pointers, and is subject to false overflow. .
D.
shifts to recover deleted space, only uses a rear pointer and wraps around to recover deleted space, using front and rear pointers.
E.
shifts to recover deleted space, only uses a rear pointer.
Explanation / Answer
Solution :
When queue is implemented using array, two pointers are maintained : one is rear and another is front.
initially rear and front both will point to same index as array is empty.
when elements are deleted from front end, to maintain the queue, array is considered to be circular queue.
Which is wrapping around to recover deleted spaces.
modulo is used with pointer while inserting and deleting to wrap around.
but when rear = front, the array can be completely full or completely empty.
Hence if array size is n, only n-1 elements are enqueued at a time in queue.
so when there are n-1 elements in queue , it can show overflow where as there is still one more space in array.
Hence option C is correct.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.