Balanced Parentheses
Push openers and pop on closers. Balanced when every closer matches the top and the stack ends empty.
Stacks for Expressions: Balanced brackets
'{' at 0. An opener: push it. The stack is now {.
Cost
- Best
- O(n)
- Average
- O(n)
- Worst
- O(n)
- Space
- O(n)
Related
Taught by the same lesson
Stacks for Expressions covers these too, in the same run.