TraceFlow

Stack

Visualisation

The stack is currently empty.

Explanation

Stack

A stack is a linear data structure that follows the Last In First Out (LIFO) principle. Elements are added and removed from the top of the stack.

Time Complexity

Push: O(1), Pop: O(1)

Space Complexity

O(n)

Current State

Stack:[]
Current Step:
The stack is ready.

Pseudo Code

1.procedure push(stack, value)
2. top = top + 1
3. stack[top] = value
4.end procedure
5.
6.procedure pop(stack)
7. if stack is empty then
8. return "Stack Underflow"
9. value = stack[top]
10. top = top - 1
11. return value
12.end procedure