edited by
502 views
6 votes
6 votes

If $s$ is the source node in the following graph, the number of back edges, forward edges, cross edges and tree edges respectively are (assuming that whenever there is a choice in the depth-first traversal), the vertex earlier in the alphabetical order is to be chosen) ____________

  1.  $3,2,2,6$
  2.  $2,4,1,6$
  3.  $3,2,1,4$
  4.  $2,1,4,6$
edited by

1 Answer

Best answer
5 votes
5 votes

We are starting from $s.$

  • $(s-w)$ and $(s-z)$ are possible edges to traverse to. Since the vertex earlier in the alphabetical order is to be chosen $(s-w)$ will be chosen as the first tree edge. $z$ stays in the stack behind $w.$

Now, $w$ is the next vertex from the stack.

  • $(w-x)$ becomes a next tree edge.

$x$ is the next vertex from the stack.

  • $(x-z)$ becomes a next tree edge.

$z$ is the next vertex from the stack.

  • $(z-w)$ becomes a back edge as $w$ is already visited.
  • $(z-y)$ becomes a next tree edge.
  • $(s-z)$ becomes a forward edge.

$y$ is the next vertex from the stack.

  • $(y-x)$ becomes a back edge as $x$ is already visited.

All the vertices in stack are now visited. Any of the remaining $3$ vertices are the possible choices now and as we are following alphabetical order $t$ will be chosen next.

  • $(t-u)$ becomes a tree edge and $v$ stays behind $u$ in the stack.

$u$ is the next vertex from the stack.

  • $(u-t)$ becomes a back edge as $t$ is already visited.
  • $(u-v)$ becomes a tree edge.

$v$ is the next vertex from the stack.

  • $(v-s)$ and $(v-w)$ become cross edges as both $s$ and $w$ are visited earlier but both are not having a path to $v.$
  • $(t-v)$ becomes a forward edge.

All vertices are covered.

  • Tree edges: $\{(s-w), (w-x), (x-z), (z-y), (t-u), (u-v) \}$
  • Back edges: $\{(z-w), (y-x), (u-t)\}$ 
  • Forward edges: $\{(s-z), (t-v) \}$
  • Cross edges: $\{(v-s), (v-w)$ 

 So, correct answer is A.

https://cs.stackexchange.com/questions/11116/difference-between-cross-edges-and-forward-edges-in-a-dft

https://courses.csail.mit.edu/6.006/fall11/rec/rec14.pdf

edited by
Answer:

Related questions