189k views
4 votes
Consider a STACK implemented with an array and containing N elements. The TOP operation has worst-case time complexity of...

a. O(1)
b. O(log N)
c. O(N)
d. O(N²)

User Fiacre
by
7.6k points

1 Answer

1 vote

Final answer:

Accessing the top element of a stack implemented with an array has a worst-case time complexity of O(1), as it is a direct action that takes constant time regardless of the stack's size.

Step-by-step explanation:

The worst-case time complexity of the TOP operation in a stack implemented with an array is O(1). This means that accessing the top element of the stack takes constant time, regardless of the number of elements (N) in the stack. The top element of the stack is always at a known position (the last inserted element), and no traversal or additional computation is necessary to access it. Therefore, retrieving the top element is a direct action and does not depend on the size of the stack.

User Anushree
by
7.7k points