### What - A **stack** is a linear data structure that **follows the Last In, First Out (LIFO)** principle. ![](https://picture-guan.oss-cn-hangzhou.aliyuncs.com/20250707135949.png) ### Complexity Analysis - Push (Add at top): O(1) - Pop (Remove from top): O(1) - Peek (Look at top without removing): O(1) - Search (based on value/index): O(n) ### Grammar we use [[Array]] to implement stack in python ```python stack = [] # Push stack.append(10) # Pop top = stack.pop() # Peek top = stack[-1] # IsEmpty is_empty = len(stack) == 0 # Size size = len(stack) ```