Divide and Conquer Graph related problem in a General way

graph is a data structure like every other structures, it is more general, everything can be seen as graph. that causes a hugh mass, so I’m terrified about it’s transformation.
many times, unlike tree or other questions, we are facing a well constructed graph, so the only thing we need to worry about is to search what we want in graph.
and generally, there are two ways to search a graph: dfs and bfs. which can both implemented in recursion and iterate way.
what do bfs and dfs can do in general?
bfs: shortest path
dfs: check graph connected, check path existed or not, check if there is a cycle

we have generally three ways to show a graph:

  1. List<List<Integer>> map //can’t represents weighted graph
  2. class GraphNode { //can’t represent wighted graph either
    }
  3. class Edge { //can represent weighted graph
    }
    and we can also use HashMap<Node, List<Node>> map

there are several kind of problems for graph:
4. shortest path :(1059AllPathsFromSourceLeadToDestination) 743 Network delay time
5. MST(310 MinimumHeigthTrees: find the root that has shortest length to furthest node)
6. topological 207/210CourseSchedule1/2, 269AlienDictionary, 332ReconstructItinerary 444SequenceReconstruction 841 keys and rooms
7. union find(LC323NumberOfConnectedComponenetsInAnUndirectedGraph)839 similar string groups ,854 k-similiar strings ,928 minimize malware spread2, 959 regions cut by slashes
8. bigraph(maximum match)785 is graph bipartite?

  1. none of them: 133Clone graph,
    261GraphValidTree,
    399EvaluateDivision
    684 redundnt connection: remove redudant connection from an undirected graph so that it becomes a tree(a tree in an undirected, connected, noncycle graph)
    685 redundant connection2: remove redudant connection from a directed graph so that it becomes a tree
    765 couple holding hands: use minimum times of swap to let every couple sit together.
    802 find eventual safe states: find all the nodes that is not included in cycle or do not lead to a cycle. this is pretty hard to undertand, so take a look at https://www.youtube.com/watch?v=v5Ni_3bHjzk
    990 satisfiability of equality equations: check if two supposed connected node is connected or not
    996 number of squareful arrays(use backtracking or DP)
    997 find the town judge
    1043 partition array for maximum sum: dp

it seems that graph problem have many kinds and can’t be categorized.

posted @ 2020-04-21 06:09  EvanMeetTheWorld  阅读(16)  评论(0)    收藏  举报