What is the time complexity of a push operation in a stack, when implemented…

2023

What is the time complexity of a push operation in a stack, when implemented using an array?

  1. A.

    O(1)

  2. B.

    O(n)

  3. C.

    O(n log n)

  4. D.

    O(n^2)

Attempted by 532 students.

Show answer & explanation

Correct answer: A

The time complexity of the PUSH operation in a stack, when implemented using an array, is O(1). This is because it only takes one operation to add an element to the top of the stack.

Explore the full course: Cocubes Preparation