1 / 11

Exploring BFS Trees: Properties, Claims, and Edge Types

Learn about BFS trees, layering in graphs, edge types, ancestor relationships, and graph algorithms with practice problems included.

maggiet
Download Presentation

Exploring BFS Trees: Properties, Claims, and Edge Types

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. CS330 Discussion 5 Spring 2017

  2. BFS Tree • In lecture, we discussed a DFS tree. Given a DFS run on graph edge is in the DFS tree if is first arrived at using . • We can define a BFS tree using the exact same definition.

  3. Properties of BFS trees • When we run BFS and get a BFS tree, we can create a layering on the graph. • We start by saying layer 0 consists of the root of the BFS. • Then, layer 1 is all vertices which are adjacent to the root. • Layer 2 is all vertices adjacent to vertices in layer 1, except the root. • Continuing the pattern, layer is all vertices adjacent to vertices in layer , that do not appear in any previous layers.

  4. Properties of BFS trees • Claim: Let be an edge in a directed graph. If we run a BFS and split the vertices into layers, the layer of cannot exceed the layer of by more than 1. • Why? • What’s the equivalent claim for an undirected graph?

  5. Properties of DFS trees • is an ancestor of in a DFS/BFS tree if is on the path in the tree from the root of the DFS/BFS to . • Claim: If is an edge in an undirected graph, then in any DFS either is an ancestor of , or is an ancestor of . • Why? • Is there an equivalent claim for a directed graph?

  6. Edge types in a DFS/BFS tree • Given a DFS/BFS tree, we can define different types of edges. • First, all edges which are a part of the DFS/BFS tree are referred to as tree edges.

  7. Edge types in a DFS/BFS tree • Edges may exist in the graph but not be included in the DFS/BFS tree (i.e. not be tree edges). These edges are split into three types. • is a forward edge if is an ancestor of • is a back edge if is an ancestor of • is a cross edge if is not an ancestor of and is not an ancestor of

  8. Edge types in a DFS/BFS tree • Consider a directed graph, and a DFS/BFS for the graph. • For both DFS and BFS, if the graph has edges then clearly we will always have tree edges. Whether the other types will exist is not so apparent. • In a DFS, can we have a cross edge? A forward edge? A back edge? • In a BFS, can we have a cross edge? A forward edge? A back edge?

  9. A note on undirected graphs • We can also define tree, forward, back, and cross edges for DFS/BFS on a directed graph. • However, the definition of forward/back becomes a bit less clear since the edge does not have a direction. • To resolve this, we’ll assign each edge whichever direction the DFS/BFS first explores that edge in. • So if we try to visit from before visiting from in the DFS/BFS, we’ll treat the edge as being directed from to .

  10. Graph Algorithm Practice Problem 1 • You are given a directed graph with unweighted edges, as well as two vertices and a subset of vertices which does not include either or . • Write an algorithm to find the shortest path from to that passes through at least one vertex in .

  11. Graph Algorithm Practice Problem 2 • You are given a graph with unweighted edges, and two disjoint subsets of , and • Write an algorithm to determine the shortest path from any vertex in to any vertex in . Also provide its runtime.

More Related