in DS
5,334 views
0 votes
0 votes
Consider a stack is implemented using an array. What is worst case time complexity of push operation?

A) O(n)

B) O(log n)

C) O(n log n)

D) O(1)
in DS
by
5.3k views

4 Comments

like stack how array do deletion in O(1) time?

means in array we have to go from 1st element,rt?
0
0
I will use a variable top, whenever i will insert i will insert at array[top], increment top and whenver delete i will delte array[top] , bcoz i dont need to remember how many elements are there in stack , this top variable will be doing it.

Insert delete both in O(1)
0
0
i think here O(n) is correct
0
0

Please log in or register to answer this question.