AlgoScope

Push

Place an item on top. Nothing else moves, so it is O(1).

Stack and queue algorithms, algorithm, beginner
Push 5. 5 is now the top item. The stack has 1 item.5bottomtoptop
Push 5. 5 is now the top item. The stack has 1 item.5bottomtoptop

Stack: Push, pop, peek

Step, step 2 of 10

push 5 and it lands on top. Size 1.

Cost

Best
O(1)
Average
O(1)
Worst
O(1)
Space
O(1)

Before this

Taught by the same lesson

Stack covers these too, in the same run.