Computer Science

Assertion (A): Program should check for Overflow condition before executing Push operation on stack and similarly check for Underflow condition before executing Pop operation.

Reasoning (R): In stack, Underflow condition signifies that there is no element available in the stack while Overflow condition means no further element can be pushed in the stack.

  1. Both A and R are true and R is the correct explanation of A.
  2. Both A and R are true but R is not the correct explanation of A.
  3. A is true but R is false.
  4. A is false but R is true.

Python Stack

2 Likes

Answer

Both A and R are true and R is the correct explanation of A.

Explanation
It is essential to check for overflow conditions before executing a Push operation on a stack to ensure that the stack has enough space to accommodate the new element. Similarly, checking for underflow conditions before executing a Pop operation is necessary to prevent deleting elements from an empty stack. An underflow condition indicates an empty stack, while an overflow condition indicates a stack that has reached its maximum capacity and cannot accept more elements.

Answered By

1 Like


Related Questions