# Topic 7 Stack

## 🧑‍💻 Introduction to Stack

A **stack** is a linear data structure that follows the **Last In, First Out (LIFO)** principle. Think of it like a stack of plates 🍽️ — you always add new plates on top and take the top one off first.

Stacks are powerful tools used to solve a variety of problems efficiently. They’re like a magic box 🧙‍♂️ for handling nested structures, evaluating expressions, and keeping track of previous elements in many algorithms.

### ⚡ Key Operations of a Stack

* **Push**: Add an element to the top of the stack 🆙
* **Pop**: Remove the top element from the stack 🔽
* **Peek** or **Top**: Look at the top element without removing it 👀
* **IsEmpty**: Check if the stack is empty 🚫
* **Size**: Get the number of elements in the stack 📏

### 💡 Where are Stacks Used?

Stacks are commonly used in scenarios like:

* **Expression evaluation** (e.g., arithmetic expressions, reverse Polish notation) ➗
* **Parsing and backtracking** (e.g., balanced parentheses) 🧩
* **Depth-first search (DFS)** in graph traversal 🌲

They can be implemented using arrays or linked lists, and many algorithms rely on stack-based operations to solve problems effectively.

***

## 📝 Problems in the Stack Topic

1. **Valid Parentheses** Problem URL: [LeetCode - Valid Parentheses](https://leetcode.com/problems/valid-parentheses/) [Study here](topic-7-stack/052-valid-parentheses) 📘
2. **Simplify Path** Problem URL: [LeetCode - Simplify Path](https://leetcode.com/problems/simplify-path/) [Study here](topic-7-stack/053-simplify-path) 📘
3. **Min Stack** Problem URL: [LeetCode - Min Stack](https://leetcode.com/problems/min-stack/) [Study here](topic-7-stack/054-min-stack) 📘
4. **Evaluate Reverse Polish Notation** Problem URL: [LeetCode - Evaluate Reverse Polish Notation](https://leetcode.com/problems/evaluate-reverse-polish-notation/) [Study here](topic-7-stack/055-evaluate-reverse-polish-notation) 📘
5. **Basic Calculator** Problem URL: [LeetCode - Basic Calculator](https://leetcode.com/problems/basic-calculator/) [Study here](topic-7-stack/056-basic-calculator) 📘

***

## 🎉 Conclusion

Congrats on diving into stacks! 🎊 Stacks are a fundamental data structure that can help you solve problems efficiently in various scenarios, like evaluating expressions, navigating through nested structures, and backtracking. 🚀

Take your time exploring each problem and its solution. You'll see how stacks can make even the trickiest problems simpler and more manageable! 😊

***

### ✨ Happy coding! 💻✨
