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 .