retagged by
858 views
1 votes
1 votes

Given a graph $G$ with vertex set $V$ and edge set $E$, which of the following statements is/are correct about graph $G$?

  1. If $G$ is directed and acyclic, the asymptotic algorithmic complexity of topological sort on $G$ is $O$$\left ( \left [ V \right ] +\left [ E \right ]\right )$, assuming edges are represented in adjacency lists rather than an adjacency matrix.
  2. If $G$ is directed or undirected, the asymptotic algorithmic complexity of breadth-first search on $G$ is $O$$\left ( \left [ V \right ] +\left [ E \right ]\right )$, assuming edges are represented in adjacency lists rather than an adjacency matrix.
  3. If $G$ is undirected, during a depth-first search of $G$, exactly four types of edges might be identified: tree edges (members of the spanning forest), back edges (linking descendants to ancestors), forward edges (non-tree edges linking ancestors to descendants), and cross edges (all other remaining links).
  1. I only
  2. III only
  3. I and II only
  4. I, II and III
retagged by

1 Answer

Best answer
3 votes
3 votes

Option I  True

Reason :

The topological sort algorithm uses a depth-first search. As nodes are finished, they are added to the front of a linked list. Since no node can be finished after its ancestors are, nodes will appear later in the final list than their ancestors.

(Ancestors, meaning sources of incoming edges on a node x, are like “dependencies” of x.) Since depth-first search
runs in O(|V | + |E|), so  topological sort also takes O(|V|  + |E| ) .

Option II  True 

Reason:

Both BFS and DFS  maintain a collection of nodes waiting to be visited; while the collection is non-empty, these algorithms pull another node out of the collection and put the node’s children into the collection.

 The collection is a Stack, while for depth-first search, For a breadth-first search, the collection is a Queue .

Since each node is touched twice (once on entering the collection and once when it is visited), and each edge is touched once, the algorithms run in O(|V | + |E|) asymptotic algorithmic complexity.

Option III False 

Reason: " If G is undirected, during a depth-first search of G, exactly four types of edges might be identified " - This line is wrong.

G is UNDIRECTED GRAPH. When we do a depth-first search of a directed graph, four edge types could be possible. 

On an undirected graph, edges can be traversed in both direction, so only tree edges and back edges can be possible in undirected graphs . 

Answer:

Related questions

1 votes
1 votes
1 answer
3
Bikram asked Jan 24, 2017
272 views
Which of the following sorting algorithms has the lowest best-case asymptotic algorithmic complexity?Selection sortMerge sortInsertion sortHeap sort