Data Structures and Algorithms Notes
Data structures and algorithms (DSA) are fundamental for efficient problem-solving.
**1. Arrays and Linked Lists**
Arrays store elements in contiguous memory locations, while linked lists use nodes.
- **Array example:** `int arr[5] = {1, 2, 3, 4, 5};`
- **Linked List example:**
```cpp
struct Node { int data; Node* next; };
```
**2. Trees and Graphs**
- **Binary Trees** Each node has at most two children.
- **Graphs** Represent networks (nodes and edges).
- **BFS & DFS** Used for searching graphs.
**3. Sorting Algorithms**
- **Merge Sort** Divide-and-conquer algorithm.
- **Quick Sort** Uses pivot selection for sorting.
**4. Recursion and Dynamic Programming**
- **Recursion** A function calling itself.
- **Dynamic Programming** Optimizes recursive problems by storing intermediate results.
**5. Hashing and Its Applications**
Hashing helps in fast lookups (e.g., HashMap in Java).
- Example:
```java
HashMap<String, Integer> map = new HashMap<>();
map.put("Alice", 25);
```
Mastering DSA improves problem-solving skills in coding interviews.