Searching is finding any information from a set of data stored in the form of elements in computer memory. The data is in different forms like an array, tree, graph, linked list, etc. Every type requires a different searching method. The types of searching are as follows :
This searching method is also the same as depth-first traversal for trees; just the difference is the graph may contain cycles, and the tree doesn’t. This algorithm starts from the root, tries to reach every node, and avoids visiting the same node again while traversing. Stack is used here as the data structure. In DFS, the traversing is done until we find the goal node.
The complexity is O(V+E), where V is the number of vertices and E is the number of edges.
Space Complexity: O(V) is the space complexity.