Algorithms: Tổng quan
Section này tập trung vào pattern recognition — không phải học thuộc từng bài, mà học cách nhận ra loại bài và áp dụng template đúng.
Triết lý học algorithms
Giải 200 bài random < Giải 50 bài với tư duy pattern rõ ràng.
Mỗi khi giải xong một bài, ghi lại:
- Pattern gì? (Sliding Window, DP, Binary Search...)
- Dấu hiệu nhận biết là gì?
- Template có gì khác biệt không?
Các pattern chính
| Pattern | File | Khi nào dùng |
|---|---|---|
| Sliding Window | sliding-window.md |
Subarray/substring liên tiếp, tối ưu trong cửa sổ |
| Two Pointers | two-pointers.md |
Array đã sort, tìm cặp/bộ ba, partition |
| Binary Search | binary-search.md |
Search space có thể chia đôi, monotonic predicate |
| Dynamic Programming | dynamic-programming.md |
Optimal substructure, overlapping subproblems |
| Graph & Tree | graph-and-tree.md |
Traversal, shortest path, connected components |
| Pattern Guide | interview-patterns.md |
Cheat sheet nhận diện pattern nhanh |
Complexity cheat sheet
O(1) Hash map lookup, array index
O(log n) Binary search, balanced BST
O(n) Linear scan, sliding window
O(n log n) Sorting, heap operations × n
O(n²) Nested loops, brute force
O(2ⁿ) Subsets, recursive without memo
O(n!) Permutations