As you said, you have set of jobs, it need to be executed in certain order. Topological sort
given you required order for scheduling of jobs(or for dependency problems if it is a direct acyclic graph
). Run dfs
and maintain a list, and start adding node in the beginning of the list, and if you encountered a node which is already visited. Then you found a cycle in given graph.