Which one of the following is the overflow condition if linear queue is…
2023
Which one of the following is the overflow condition if linear queue is implemented using an array with a size MAX_SIZE?
- A.
rear = MAX_SIZE − 1
- B.
rear = MAX_SIZE
- C.
rear − front + 1
- D.
More than one of the above
- E.
None of the above
Attempted by 643 students.
Show answer & explanation
Correct answer: A
In a linear queue implemented with an array of size MAX_SIZE, valid indices are 0 to MAX_SIZE − 1.
In the standard implementation, rear points to the last inserted element. Before inserting a new element, we check whether rear has already reached the last valid index.
Overflow condition:
rear == MAX_SIZE − 1
MAX_SIZE − 1 is a valid index, but when rear is already at this index, there is no next valid position available for insertion. Therefore, the next insertion would cause overflow.
rear == MAX_SIZE would mean the pointer has already gone outside the array bounds. That is not the usual pre-insertion overflow check.
So the correct answer is option A: rear = MAX_SIZE − 1.