發表文章

目前顯示的是 2月, 2018的文章

Graph problems summary

In Leetcode graph problems, it usually uses BFS or DFS to retrieval the data. It depends on what problem ask and the understanding of the algorithm, I put notes here to help myself review in the future. [ basically, steps are ] 1. determine whether the problem is directional or unidirectional graph? 2. use dictionary or different way to translate the problem into the graph 3. analysis the problem and choose the algorithm 4. design, run algorithm(BFS or DFS) 5. return the answer [ why those steps ] for 1 & 2 it's important to understand the relationship between vertex( or node) and edge (sometimes I like to call it neighbors). Without step1, I'll not able to build up properly graph to represent the problem. for 3,4,5, decompose the problem and solve with most efficient way consider as engineering virtue. Problems.  [ Problem 133 Clone Graph ] Clone an undirected graph. Each node in the graph contains a  label  and a list of its  neighbors . ...