1. Brute Force
- Try all possibilities until you find the answer.
- ✅ Simple but usually slow (
O(2ⁿ)
,O(n!)
).
2. Divide and Conquer
- Break problem → solve subproblems → combine results.
- 🔑 Examples: Merge Sort, Quick Sort, Binary Search.
3. Greedy Algorithms
- Make the best local choice at each step → hope it leads to global optimum.
- 🔑 Examples: Dijkstra’s shortest path, Huffman coding.
4. Dynamic Programming (DP)
- Break problem into overlapping subproblems.
- Save (memoize) results to avoid recomputation.
- 🔑 Examples: Fibonacci, Knapsack, Matrix path problems.
5. Backtracking
- Try a path, if it fails → go back and try another.
- 🔑 Examples: Sudoku solver, N-Queens, Maze solving.
6. Graph Algorithms
- Work with nodes/edges (networks, maps, dependencies).
- 🔑 Examples: BFS, DFS, Dijkstra, Kruskal, Prim.
7. Sorting & Searching
- Sorting: QuickSort, MergeSort, HeapSort, BubbleSort.
- Searching: Binary Search, Linear Search.
8. Recursion
- A function calls itself to solve smaller versions of a problem.
- Often combined with DP, divide & conquer, backtracking.
9. Mathematical / Number Theory
- 🔑 Examples: GCD (Euclidean), Prime tests, Modular arithmetic.
10. String Algorithms
- Work on text patterns and substrings.
- 🔑 Examples: KMP, Rabin-Karp, Trie-based search.
✅ TL;DR
- Optimization → Greedy or DP.
- Paths/Networks → Graph.
- Exploring possibilities → Backtracking.
- Ordering/Searching data → Sorting/Searching.
- Formula-style tricks → Math/Number theory.
If you found this helpful, consider supporting my work at ☕ Buy Me a Coffee.