Function graph_algorithms::dfs
source · [−]pub fn dfs()Expand description
Performs Depth first search algorithm on a given directed graph represented as an adjacency list. Prints a graph, where the nodes of the graph are in the visited order.
Input
no_of_vertices- Input the number of vertices in the graphno_of_edges- Input the number of edges in the graphsource- The source vertex of an edge in the graphdestination- The destination of an edge in the graphStart_vertex- The start vertex where BFS algorithm starts from
Output
Prints the visit order of the graph
Sample input
Please Enter Number of Vertices : 5
Please Enter Number of edges in the graph : 5
Source : 0
Destination : 1
Source : 0
Destination : 2
Source : 0
Destination : 3
Source : 2
Destination : 1
Source : 2
Destination : 4
Enter Source Vertex : 0Sample output
Visited node: 0
Visited node: 1
Visited node: 2
Visited node: 4
Visited node: 3