Stacks - DSA Notes 📝
01.05.2025
6 views
🎯 Learning Goals
- How are Stacks implemented?
- What are the time complexities?
🧠 Key Concepts (aka My Notes)
Stacks
- Dynamic arrays are already Stacks.
-
LIFO (Last In is the First Out)
- There should be a pointer for the last element in the array.
Push
- Appending an element to the end of a dynamic array
⌚ Time Complexity is O(1).
Push
- Removing an element to the end of a dynamic array
- It is wise to check if the stack is empty before popping
⌚ Time Complexity is O(1).
Peek
- Returning an element to the end of a dynamic array
⌚ Time Complexity is O(1).
⌚ Time Complexity for Stacks
Operation |
Big-O |
Push |
O(1) |
Pop |
O(1) |
Peek |
O(1) |
💪 LeetCode Problems
- 155. Min Stack (Link)
- 20. Valid Parentheses (Link)
Comments ()
Please
login to leave a comment