Depth-First Search Algorithm ?
Depth-First Search Algorithm ?
Graph searching:
The systematic follow up of the edges of the graph in
some specific order to visit the vertices of the graph is called
graph searching.
Tree edge:-
In a graph ‘G’ containing an edge (u,v) if a new
unvisited vertex ‘v’ is reachd from the current vertex the the
edge (u,v) is called tree edge.
Back edge:-
In a graph ‘G’ if previously visited ‘v’ is reached from the
current vertex ‘u’ then edge (u,v) is called back edge.
ALGORITHM:-
visit[v]=1
for (each vertex adjacent from v) do
{
if (visit[u]=0)
DFS(u) // recursive call from next selected vertex ‘u’
}
ANALYSIS:-
Every node is visited once hence the time complexity of
depth first search is O(V + E) if the graph is created using
adjacency list and it is O(V)2 if the graph is created using the
adjacent matrix.
For example