Question 0 Traversal & Reachable模版
Graph Node
// Some code
class GraphNode {
int id;
List<GraphNode> neighbors;
// assume the graphNode has already overridden hashCode(), equals(), toString();
@Override
public int hashCode(){
}
@Override
public int equals() {
}
@Override
public int toString() {
}
}DFS对点的遍历
BFS对点的遍历
去重的位置
DFS对connection& reachable
BFS对connection& reachable
对边的遍历:Backtracking(see the future section)
The Representation of the Graph in these questions
面试中图论的基本要素
题库喜欢的表示方法1: int[][] graph
Case 1: Telling me is an Undirected Graph
Case 2: Telling me is a Directed Graph
题库喜欢的表达方法2: int[][] matrix 扔给你个地图
Question 1: 用每个点的matrix坐标表示一个node会不会超界
Question 2 方向怎么办?
Use Case: 给你一个点(curX, curY) 能不能访问所有邻居
Last updated