What is Graph?
A graph is just a set of vertices (nodes), together with edges (connections) between some pairs of nodes. If the connections have a direction, the graph is said to be “directed graph”, otherwise the graph is said to be “undirected graph”.
A graph G = (V, E) with V, i.e. set of vertices and E, i.e. set of edges.
Searching a graph: Systematically follow the edges of a graph to visit the vertices of the graph. And is used to discover the structure of a graph.
Standard graph searching algorithms are
- Depth First Search (DFS)
- Breadth First Search (BFS)
Problem Statement
Deeply search a graph to make logical tree.
Depth First Search
Depth first is an algorithm for traversing or searching a tree. It explore edges out of the most recently discovered vertex v. When all edges of v have been explored, backtrack to explore other edges leaving the vertex from which v was discovered (its predecessor).
“Search as deep as possible first.”
Depth first search is another way of traversing graphs, which is closely related to preorder traversal of a tree.