Presentation is loading. Please wait.

Presentation is loading. Please wait.

Graph Search Applications, Minimum Spanning Tree

Similar presentations


Presentation on theme: "Graph Search Applications, Minimum Spanning Tree"— Presentation transcript:

1 Graph Search Applications, Minimum Spanning Tree

2 Classifying Back Edges
Run DFS, but also keep a third state: Unvisited (never started visiting) Exploring (began processing neighbors, but not done) Visited (visited and explored all neighbors) A “Back Edge” goes from current node to an Exploring node (or a Visited node, if a directed graph) Can be used to find cycles (back edges that aren’t a single undirected edge)

3 Articulation Points and Bridges
Find a vertex or an edge that when removed will disconnect the graph Option 1: naïve approach Calculate the number of connected components Try, one-by-one, removing each edge/vertex Recalculate number of CCs If more CCs, then it’s an articulation point or bridge.

4 Articulation Points and Bridges
Find a vertex or an edge that when removed will disconnect the graph Option 2: specialized algorithm Compute DFS, but also store two values per node: Num: the order in which the node was reached during DFS Low: lowest Num reachable from current subtree Update Low when you have a back edge If a neighbor vertex has a Low value greater or equal to your own Num, then you’re at an articulation point If Low(u) > Num (v), then u-v is a bridge Likewise, if Low(v) > Num (u), then u-v is a bridge

5 Strongly Connected Components (Directed)
Notice: can replace a SCC by a single node, and result is a directed acyclic graph. Perform DFS like before. SCCs are identified when a back edge creates a cycle (and therefore connects everything in that subtree. Update Low only for Visited (not Exploring) vertices. Add each node to a stack When you finish a node where Num == Low, it marks the root of a SCC Pop nodes off the stack until you get that node off; those nodes are a SCC

6 Minimum Spanning Tree Weight on edge; find set of edges that minimize connecting everything Kruskal’s algorithm: Sort edges from lowest weight to highest Add edges by doing a union-find set combination each Done when you have just one set (i.e. have added n-1 edges, thus joining all n vertices)

7 Minimum Spanning Tree Weight on edge; find set of edges that minimize connecting everything Prim’s algorithm: For each node, mark as “in” or “out”. Start with any node as the only one “in” Priority queue of edges, based on weight. Add the edges for the “in” node Repeatedly get next edge from queue. If one of the nodes is “out”, then: Mark that node “in” Add its edges to the priority queue.

8 MST variants Maximum spanning tree Minimum subgraph
Use Kruskal’s with edges sorted greatest to smallest Minimum subgraph Run Kruskal’s but with some stuff already merged Minimum forest (can have up to x components) Run Kruskal’s until just x sets Second-best tree Get MST, then try removing a link, and find first link to connect Repeat for all links Minimax – minimum of maximum edge weights along a path i to j Just a subset of the MST – path from i to j in the MST.


Download ppt "Graph Search Applications, Minimum Spanning Tree"

Similar presentations


Ads by Google