BFS Notes


  1. 0 - n-1 graph的表示方法用二维数组或者list[]
  2. Topological sort 关键是要找indegree和neighbour mapping
  3. Topological sort如果nodes是动态的最好是用map而不是数组。先初始化graph和indegree更好写
  4. 与memory相关比如number of island,在加进queue的时候就需要标记,不然会超时。 
  5. 凡是能不用BFS做的都比BFS做简单。比如能用union find做的。
  6. 在矩阵里面,memorize直接可以in place做,不需要额外空间。
  7. 坐标可以用int[2] 来表示

评论

此博客中的热门博文

663. Equal Tree Partition

776. Split BST

426. Convert Binary Search Tree to Sored Doubly Linked List