Complete the code to identify the type of graph suitable for topological sorting.
A topological sort can only be performed on a [1] graph.Topological sorting is only possible on directed acyclic graphs (DAGs) because cycles prevent a linear ordering.
Complete the code to describe the output of a topological sort.
The output of a topological sort is a [1] of the vertices such that for every directed edge u -> v, u comes before v.
Topological sorting produces a linear ordering of vertices respecting the direction of edges.
Fix the error in the statement about cycle detection in topological sorting.
If a graph contains a cycle, topological sorting [1] be performed.Topological sorting cannot be performed on graphs with cycles because no linear ordering exists that respects all edges.
Fill both blanks to complete the description of a common algorithm for topological sorting.
One common method uses Depth-First Search (DFS) and adds each vertex to a stack after visiting all its [1]. Then, the stack is [2] to get the topological order.
The DFS method visits all children (outgoing edges) before adding a vertex to the stack. Reversing the stack gives the topological order.
Fill all three blanks to complete the pseudocode for Kahn's algorithm for topological sorting.
Initialize a queue with all vertices having [1] zero. While the queue is not empty, remove a vertex [2] and add it to the result. Then, decrease the [3] of its neighbors by one.
Kahn's algorithm starts with vertices with in-degree zero, processes them from the front of the queue, and decreases the in-degree of their neighbors.