leetcode课程安排:https ://leetcode.com/problems/course-schedule/
这个问题涉及到检测一个循环,如果有一个循环,那么你就无法完成所有课程。
我听说最推荐使用 DFS 来检测周期,但建议使用 Kahn 算法来解决课程安排问题,这是一种 BFS 解决方案。
那么..是哪一个?DFS 和 BFS 哪个更适合检测循环?
algorithm graph breadth-first-search depth-first-search data-structures