1

Theorem 22.10 in CLRS - Introduction to Algorithms says that

In a depth first search of an undirected graph G, every edge of G is either a tree edge or a back edge.

Now in this the explanation for tree edge portion is obvious, but I didn't get the back edge part. For eg:- take an undirected graph such that

1----2----3

Now in this if edge 1-2 is explored first such that d1 < d[2], then edge 1-2 will be the tree edge. Now as this is an undirected graph so can we say that edge 2-1 is the back edge in the graph (d[2] > d1) ??

I am not getting the hang of this back edge thingy.

ComicSansMS
  • 51,484
  • 14
  • 155
  • 166
Akshay Jindal
  • 115
  • 3
  • 11

3 Answers3

2

I don't have a copy of CLRS at hand, so I'm writing this from the back of my head. Apologies if I say something stupid.

You only get back edges if you have circles.

For any given undirected graph you can partition the set of edges such that every edge is either a tree edge or a back edge. If your original graph happens to be a tree already, the set of back edges will be empty. If you remove all back edges from the graph, your graph will become a tree. Naturally there might exist more than one such partitioning for a given graph.

In your example, the graph 1--2--3 is already a tree so there are no back edges. A DFS would visit each node exactly once. Note that the DFS never uses the same edge twice! So if you already used 1-2 to go from 1 to 2, you cannot go back from 2-1 via that same edge.

The concept of a cycle can be a bit difficult to grasp for undirected graphs: An undirected graph has a cycle if you can find two nodes such that you can get from one to the other using more than one path, where you are not allowed to walk the same edge twice.

ComicSansMS
  • 51,484
  • 14
  • 155
  • 166
  • @AkshayJindal Expanded the answer a bit to make it clearer. Your main source of confusion seems to be your attempt to split an undirected edge into two directed ones. You are not allowed to do that in this case. The results of the DFS will change, as it will now only mark one direction when walking an edge, where before it marked both. – ComicSansMS Jul 19 '13 at 11:35
0

Copying from wiki link. A back edge is an unvisited edge which takes you from current node to a already visited node.

kdurga
  • 97
  • 1
  • 8
  • So in an undirected graph, we can say that if edge 1-2 (visited) is a tree edge then edge 2-1 (unvisited) is a back edge rite?? – Akshay Jindal Jul 19 '13 at 11:44
0

Simplest example of a back edge:

  a
 / \
b   c
 \ /
  d

If you dfs from a->b->d->c, then the edge c->a is a back edge because it is an unvisited edge going to an already visited node.

Alex
  • 759
  • 5
  • 12