You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A **Stack** is a linear data structure that follows the Last-In-First-Out (LIFO) principle. This means the last element added is the first one to be removed.
3
+
4
+
### Key Characteristics
5
+
- Operates in a **LIFO** order.
6
+
- Can be implemented using arrays or linked lists.
7
+
8
+
### Common Operations
9
+
-**Push(x)**: Adds element `x` to the top of the stack.
10
+
- Complexity: \(O(1)\)
11
+
-**Pop()**: Removes and returns the top element.
12
+
- Complexity: \(O(1)\)
13
+
-**Peek/Top()**: Returns the top element without removing it.
14
+
- Complexity: \(O(1)\)
15
+
-**isEmpty()**: Checks if the stack is empty.
16
+
- Complexity: \(O(1)\)
17
+
18
+
### Applications
19
+
-**Expression Parsing**: Evaluating postfix and infix expressions.
20
+
-**Function Calls**: Recursive calls use a call stack.
21
+
-**Backtracking**: Helps in scenarios where previous states are revisited, like maze solving or browser history.
0 commit comments