Common Mistakes

Common errors to avoid

  • Forgetting to check for cycles: Always verify all nodes were processed. Remaining nodes indicate cycle.
  • Wrong edge direction: Edge goes from prerequisite TO dependent, not reverse.

Course[1] → course[0] for [course, prereq].

  • Not handling disconnected components: Initialize all nodes with in-degree 0 in queue, not just first one.
  • Confusing BFS vs DFS approach: Kahn's (BFS) builds order forward; DFS builds order backward (reverse post-order).