All Exams Test series for 1 year @ ₹349 only
Question

Consider the following pseudocode for depth-first search (DFS) algorithm which takes a directed graph $G(V, E)$ as input, where $d[v]$ and $f[v]$ are the discovery time and finishing time, respectively, of the vertex $v \in V$.

DFS(G):
  unmark all v ∈ V
  t ← 0
  for each v ∈ V
    if v is unmarked
      t ← Explore(G, v, t)
    end if
  end for
Explore(G, v, t):
  mark v
  t ← t + 1
  d[v] ← t
  for each (v, w) ∈ E
    if w is unmarked
      t ← Explore(G, w, t)
    end if
  end for
  t ← t + 1
  f[v] ← t
  return t

Suppose that the input directed graph $G(V, E)$ is a directed acyclic graph (DAG).
For an edge $(u, v) \in E$, which of the following options will NEVER be correct?

To solve this problem, we need to analyze the behavior of the depth-first search (DFS) algorithm in terms of discovery and finishing times for a directed acyclic graph (DAG). Let's break down each option:

  1. \(d[u] < d[v] < f[v] < f[u]\):

This sequence of events is possible. In DFS, if \(u\) is discovered before \(v\) and \(v\) is a descendant of \(u\), then \(u\) will start before \(v\), and \(v\) will finish before \(u\). Thus, \(d[u] < d[v] < f[v] < f[u]\) is feasible when \((u, v)\) is in a DFS tree.

  1. \(d[v] < d[u] < f[u] < f[v]\):

This sequence is not possible in a DFS traversal of a directed graph. The reason is if \(v\) is discovered before \(u\), then \(f[v]\) must be calculated before \(f[u]\) since \(f[u]\) will only be set after all possible descendants of \(u\), including \(v\), are finished. Therefore, this sequence can never happen.

  1. \(d[v] < f[v] < d[u] < f[u]\):

This sequence is also possible and typically occurs when \(v\) is finished before \(u\) is even discovered, indicating they are different branches in the DFS forest. Therefore, \(d[v] < f[v] < d[u] < f[u]\) is possible.

  1. \(d[u] < d[v] < f[u] < f[v]\):

This sequence indicates that \(u\) is an ancestor of \(v\) in the search tree, discovered first, and finishes before \(v\) finishes. This is possible when the DFS returns to completing actions for \(u\) before moving on to backtrack \(v\)'s exploration.

Based on this analysis, the sequences that will NEVER be correct are:

\(d[v] < d[u] < f[u] < f[v]\) and \(d[u] < d[v] < f[u] < f[v]\).

Was this answer helpful?

Important Questions from Graph Search

  1. Which traversal algorithm is typically implemented using a stack data structure?

  2. The depth first search will use ________ as a structure to held nodes for further processing.
  3. Consider the following algorithm someAlgo that takes an undirected graph G as input.

    someAlgo (G)
    1. Let $v$ be any vertex in G. Run BFS on G starting at $v$. Let $u$ be a vertex in G at maximum distance from $v$ as given by the BFS.
    2. Run BFS on G again with $u$ as the starting vertex. Let $z$ be the vertex at maximum distance from $u$ as given by the BFS.
    3. Output the distance between $u$ and $z$ in G.

    The output of someAlgo (T) for the tree shown in the given figure is ____________ (Answer in integer)

  4. Which of the following statements about DFS are correct? 

    A. It can detect cycles in a graph

     B. It can be used to find connected components.

     C. It works for both directed and undirected graph. 

    D. Guarantees shortest path in unweighted graphs. 

    Choose the correct answer from the options given below:

  5. Given below are two statements: one is labelled as Assertion A and the other is labelled as Reason R 

    Assertion A: Depth first search can be used to perform a topological sort of a directed acyclic graph. 

    Reason R: A topological sort a directed acyclic graph G =(V, E) is a linear ordering of its vertices such that if G contain an edge (u, v) then u appears before v in the ordering.

     In the light of the above statements, choose the most appropriate answer from the options given below

Need Expert Advice?

Start Your Preparation with Prepp Mobile App

Download the app from Google Play & App Store
Download the app from Google Play & App Store
Prepp Mobile App