Stepping_Oline_Judge_BFS
Lintcode--Leetcode: Base + Senior BFS-- level order traversal 经典模板: 总结:使用queue作为维护每一层节点,并由上一层拓展到下一层的数据结构: 遍历一个节点所在层,队尾加入 队首pop,加入pop节点的儿子们,由x层拓展到x+1层。size动态变化。 连通块Connected Component问题: 图的表示:邻接表 lintcode: https://www.jiuzhang.com/solution/connected-component-in-undirected-graph/ Similar leetcode: https://leetcode.com/problems/number-of-connected-components-in-an-undirected-graph/description/ Lintcode--Leetcode: Base + Senior BFS in Binary Tree 经典模板: 总结:使用queue作为维护每一层节点,并由上一层拓展到下一层的数据结构: 遍历一个节点所在层,队尾加入 队首pop,加入pop节点的儿子们,由x层拓展到x+1层。size动态变化。 连通块Connected Component问题: 图的表示:邻接表 lintcode: https://www.jiuzhang.com/solution/connected-component-in-undirected-graph/ Similar leetcode: https://leetcode.com/problems/number-of-connected-components-in-an-undirected-graph/description/ 图中的bfs: 图和矩阵中,节点之间是双向关系,所以需要一个boolean矩阵,记录是否访问过,防止节点重复进入queue。 图和矩阵的bfs,for循环在外部 对比: 右边,bfs in graph, 相当于只做了一层的遍历 ...