Data Structures and Algorithms - Graph Algorithm

12. A depth-first search is performed on a directed acyclic graph. Let d[u] denote the time at which vertex u is visited for the first time and f[u] the time at which the dfs call to the vertex u terminates. Which of the following statements is always true for all edges (u, v) in the graph?

  • Option : D
  • Explanation :

    Suppose v is starting vertex so start DFS at node v
    (i) visit t (v) → DFS(A) → visit (A) → DFS (v) → visit (u) → back track (A) → Back track (v)
    therefore d[v] > d[v], d[v] < f[v] f[v] < f[v]
    But visiting order is just opposite of finishing order.
    Hence f[v] > f[v]
Cancel reply
Cancel reply

14. Let G of be a graph with n vertices and m edges. What is the tightest upper bound on the running time of Depth First Search on G, when G is represented as an adjacency matrix?

  • Option : C
  • Explanation :
    DFS visits each vertex once and as it visits each vertex, we need to find all of its neighbours to figure out where to search next. Finding all its neighbour s in an adjacency matrix r equires O(V) time, so overall the running time will be O(V2).
Cancel reply
Cancel reply