Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Graph Theory Lecture 17: Graph Searching Algorithms.

Similar presentations


Presentation on theme: "Introduction to Graph Theory Lecture 17: Graph Searching Algorithms."— Presentation transcript:

1 Introduction to Graph Theory Lecture 17: Graph Searching Algorithms

2 Introduction DFS forest allows us to identify edges as tree or back edges. With the DFS forest, we are able to solve numerous graph-processing problems. We’ll discuss few simple ones in this lecture  Cycle detection  Two-way Euler tour  Spanning tree  Two-colorability

3 Cycle Detection Look for the existence of back/down edge. A back/down edge v-w belongs to a cycle consisting of the edge and the tree path connecting the two nodes. A graph is acyclic if and only if no back/down edges.

4 Two-way Euler Tour Finding a walk that uses all the edges in the graph exactly twice. Go back and forth on each back link (or down link, but not both)

5 Spanning Tree This is exactly what DFS generates  V(G)-1 recursive calls, one for each edge on a spanning tree.

6 Two-Colorability Two-colorrability (bipartiteness) = no-odd-cycle  Assigning alternate colors as we proceed down the DFS tree  Check back edge for consistency in the coloring.  Any back edge connecting two vertices of the same color => odd cycle

7 Separability We’re interested in finding bridges  Review: a bridge is an edge that, if removed, would turn a connected graph to disconnected. In any DFS tree, a tree edge v-w is a bridge if and only if there are no back edges that connects a descendant of w to an ancestor of w.  We also consider w its own descendant (so edge 6-2 is not a bridge in the next example) Breaking the v-w edge would disconnect the sub-tree rooted w from the rest of the graph.

8 (cont) Lowest preorder number referenced by any back edge in the subtree rooted at the vertex

9 Biconnectivity A graph is biconnected if  It has no cut-vertex  There exist two disjoint paths between any pair of vertices. Question: How do we determine if a graph is biconnected using a DFS-based approach?

10 (cont) After brainstorming, we reached the following conclusion:  In any DFS tree, a vertex w is a cut-vertex if and only if, for every subtree rooted at vertex u with st[u]=w, there is a back edge that connects a descendant of w to an ancestor of w.  Need to check if the root of the tree is an articulation point (what would be the criterion for that?)

11 Breadth-First-Search If what we want is to find the shortest path, DFS is no use here. With BFS, we need a FIFO queue (instead of a stack for DFS)  Taking edges from the queue until finding one that points to an unvisited vertex  Visit that vertex by putting onto the queue all edges that go from that vertex to unvisited vertices.

12 Example Level 1 Level 2 Level 3

13 Code

14 Applications of BFS Shortest path Single-source shortest path All-pairs shortest path


Download ppt "Introduction to Graph Theory Lecture 17: Graph Searching Algorithms."

Similar presentations


Ads by Google