Bird
Raised Fist0

What is the overall time complexity of Kahn's Algorithm when used to find a topological order in a directed graph with V vertices and E edges?

medium🧠 Conceptual Q5 of Q15
Topological Sort - Course Schedule II (Topological Order)
What is the overall time complexity of Kahn's Algorithm when used to find a topological order in a directed graph with V vertices and E edges?
AO(V + E)
BO(V * E)
CO(V^2)
DO(E^2)
Step-by-Step Solution
Solution:
  1. Step 1: Analyze graph traversal

    Kahn's Algorithm visits each vertex once and processes each edge once.
  2. Step 2: Summarize complexity

    Visiting all vertices is O(V), processing all edges is O(E).
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Algorithm is linear in size of graph [OK]
Quick Trick: Each vertex and edge is processed once [OK]
Common Mistakes:
MISTAKES
  • Assuming nested loops over edges and vertices
  • Confusing with DFS complexity
  • Ignoring edge processing cost
Trap Explanation:
PITFALL
  • Options B, C, D incorrectly assume higher complexity due to nested processing.
Interviewer Note:
CONTEXT
  • Tests knowledge of algorithmic time complexity for graph algorithms.
Master "Course Schedule II (Topological Order)" in Topological Sort

3 interactive learning modes - each teaches the same concept differently

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Topological Sort Quizzes