What is the time complexity of the push() operation in an array-based stack?

2025

What is the time complexity of the push() operation in an array-based stack?

  1. A.

    O(1)

  2. B.

    O(log n)

  3. C.

    O(n log n)

  4. D.

    O(n)

Attempted by 276 students.

Show answer & explanation

Correct answer: A

In an array-based stack, the push() operation adds an element to the top of the stack. This operation typically involves:

Incrementing the top pointer/index.
Inserting the element at the new top position.

Both actions take constant time and do not depend on the number of elements in the stack.

Therefore, the time complexity of push() is O(1).

Explore the full course: Niacl Ao It Specialist