DSA 依赖图:从数组到 DP 的逻辑路线图
Source: Dev.to

The Problem
我们常把数据结构与算法(DSA)当作购物清单——今天挑“堆”,明天挑“图”。但计算机科学的主题之间是有依赖关系的。没有先理解数组(它们的存储方式)和树(它们的可视化),你无法真正掌握堆。
我制定了一个 7 阶段路线图,帮助你一步步构建思维模型。这个顺序确保每个新主题都使用前一阶段已经掌握的工具。
Phase 1: Basic Linear Structures & Their Patterns
Goal: Master sequential data and index manipulation before touching complex nodes.
- Time & Space Complexity (Big‑O): 所有代码的衡量标准。
- Arrays: 内存模型(静态 vs 动态)。
- Searching & Sorting Algorithms: Two Pointers 的必备前置知识。
- Recursion (Pattern): 基础——基例 vs 递归例。
- Two Pointers (Pattern): 最常见的数组优化技巧。
- Binary Search (Algorithm):
O(log N)逻辑。 - Sliding Window (Pattern): 子数组与子串。
- Prefix Sum (Pattern): 一维和二维区间查询。
- Intervals (Pattern): 区间的合并与插入。
- Matrix Traversal (Pattern): 2D 网格遍历的基础。
Phase 2: The Power of Lookup (Hashing)
Goal: Trade space for speed.
- Hash Table / Hash Map:
O(1)查找之王。 - Strings: 不可变性与操作技巧。
Phase 3: Pointers & Recursion
Goal: Move from indexes to references.
- Linked List: 单向链表与双向链表。
- Recursion (Advanced): 多次递归调用(为记忆化做准备)。
- Stack & Queue: LIFO 与 FIFO 机制。
- Monotonic Stack (Pattern): 找“下一个更大元素”。
- Fast & Slow Pointers (Pattern): 环检测。
Phase 4: Non‑Linear Structures (Hierarchical)
Goal: Understand parent‑child relationships.
- Trees: 高度、深度、直径属性。
- Binary Trees: 面试常见结构。
- Tree Traversals: 前序、中序、后序、层序。
- Binary Search Tree (BST): 有序层次数据。
- Heaps / Priority Queue: 按优先级组织。
- Top K Elements (Pattern): 高效使用堆。
- Divide and Conquer (Pattern): 将归并排序的思路应用到树上。
Phase 5: Advanced Search & Backtracking
Goal: Explore all possibilities.
- Backtracking (Pattern): 解谜(数独、N 皇后)。
- Tries: 前缀树,用于自动补全。
Phase 6: Connectivity (Graphs)
Goal: Model many‑to‑many relationships.
- Graphs: 邻接矩阵 vs 邻接表。
- Matrix Traversal (Advanced): 将网格视作图。
- Graph Traversals: BFS(无权图最短路) & DFS。
- Union‑Find: 并查集(DSU)。
- Shortest Path: Dijkstra 算法。
Phase 7: Optimisation (The Hardest Part)
Goal: Solve overlapping sub‑problems.
- Bit Manipulation: 二进制逻辑。
- Dynamic Programming (DP):
- 流程:Recursion → Memoisation → Tabulation → Space Optimisation。
Why This Order?
- Recursion Split: 基础递归用于排序;高级递归用于树和 DP。
- Matrix Split: 必须先会矩阵遍历(Phase 1),才能在 Phase 6 中对矩阵进行 BFS。
- Patterns First: “Two Pointers” 紧随 Arrays,因为真实问题中数组往往这样使用。
保存这张路线图,别再在噪音中迷失! 🚀