BFS Implementation in Python

Breadth First Search (BFS) algorithm is used to traverse a graph in a breadth ward motion. BFS Algorithm use data structure queue to remember to get the next vertex to start the search and we will required an array to keep the track of vertex that it is visited or unvisited.

C++ Program to detect a cycle in Directed Graph

C++ Program to detect a cycle in directed graph is given below. Approach is simple, we will do DFS traversal of graph from each vertex (which will be source) and look if there is any back edge to the source during traversal. If there is any back edge then it means there is cycle in the graph otherwise there is not any cycle.