Bird
Raised Fist0

Consider the graph with a single node and no edges: [[]]. What does the optimal approach (reverse graph + Kahn's algorithm) return as eventual safe states?

medium🧾 Code Trace Q4 of Q15
Topological Sort - Find Eventual Safe States
Consider the graph with a single node and no edges: [[]]. What does the optimal approach (reverse graph + Kahn's algorithm) return as eventual safe states?
A[0,0]
B[]
C[0]
D[1]
Step-by-Step Solution
Solution:
  1. Step 1: Initialize in-degree and reverse graph

    Single node with no edges means in-degree[0] = 0 and reverse_graph[0] = [].
  2. Step 2: Queue contains node 0 and is processed

    Node 0 is safe since it has no outgoing edges; returned list is [0].
  3. Final Answer:

    Option C -> Option C
  4. Quick Check:

    Single node with no edges is always safe [OK]
Quick Trick: Node with zero out-degree is safe [OK]
Common Mistakes:
MISTAKES
  • Returning empty list for single node
  • Duplicating nodes in output
Trap Explanation:
PITFALL
  • Some candidates incorrectly exclude isolated nodes or duplicate them in output.
Interviewer Note:
CONTEXT
  • Checks handling of minimal edge cases in topological sort approach.
Master "Find Eventual Safe States" 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