Algorithms Class Notes
1. Time and Space Complexity
Time Complexity measures the amount of time an algorithm takes relative to the input size.
Examples:
- O(1): Constant time
- O(log n): Binary Search
- O(n): Linear Search
- O(n log n): Merge Sort
- O(n^2): Bubble Sort
Space Complexity refers to the amount of memory used by the algorithm during its execution.
2. Divide and Conquer
A problem-solving strategy that breaks a problem into subproblems of the same type, solves them
recursively, and combines their solutions.
Example: Merge Sort
- Divide: Split the array into two halves
- Conquer: Recursively sort each half
- Combine: Merge the sorted halves
3. Dynamic Programming
Used for optimization problems by breaking them into overlapping subproblems and storing results.
Key concepts:
- Memoization (Top-down)
- Tabulation (Bottom-up)
Algorithms Class Notes
Example: Fibonacci sequence, 0/1 Knapsack, Longest Common Subsequence
4. Graph Algorithms
Graph algorithms solve problems related to graphs (nodes and edges).
Common algorithms:
- BFS (Breadth-First Search)
- DFS (Depth-First Search)
- Dijkstra's Algorithm (Shortest Path)
- Kruskal's and Prim's Algorithm (Minimum Spanning Tree)