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 graph
  • no_of_edges - Input the number of edges in the graph
  • source - The source vertex of an edge in the graph
  • destination - The destination of an edge in the graph
  • Start_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 : 0

Sample output

Visited node: 0
Visited node: 1
Visited node: 2
Visited node: 4
Visited node: 3