Lecture 17 - Problems

Goals:

  1. What’s the runtime of DFS(u) on a graph with n nodes explorable along m edges from u?
  2. What’s the runtime of BFS(u) on a graph with n nodes explorable along m edges from u?

  3. Try running BFS(2) on the following undirected graph:

    image-20200902152831248

    Write the order in which nodes are visited, then label each node with the path length to the origin (2). What do you notice about the visit order of BFS?

Consider this: a tree is a special kind of undirected graph with only one path between all pairs of nodes (you could also define it to be a directed graph with edges pointing from parent to child).

  1. DFS(root) on a tree corresponds to which tree traversal?

  2. BFS(root) on a tree corresponds to which tree traversal?

  3. For this problem, let’s stick to thinking about undirected graphs. A connected component is a subgraph that is connected. The number of connected components in a graph is the smallest number of components that, taken together, comprise the whole graph. For example, the following graph has 3 connected components:

    image-20200902154141294

    Suppose you have an adjacency list representation of a graph. Devise an algorithm to count the number of connected components. Hint: What can you say about the subgraph containing the set of nodes visited by a DFS and all edges that connect pairs of those nodes (this is called the induced subgraph)?