What is the time complexity of the push and pop operations in a stack implemented using an array?

Options

  • A. O(1)
  • B. O(n)
  • C. O(log n)
  • D. More than one of the above
  • E. None of the above

Correct Answer (Detailed Explanation is Below)

A. O(1)

Detailed Explanation

Correct Answer: A. O(1)

Explanation: Both push and pop operations take constant time in a standard array-based stack.

  • Push: Inserts an element at the top.
  • Pop: Removes the top element.
  • No traversal of the entire stack is required.