Depth first search, Data Structure & Algorithms

DEPTH FIRST SEARCH (DFS)

The approach adopted into depth first search is to search deeper whenever possible. This algorithm frequently searches deeper through visiting unvisited vertices and whenever an unvisited vertex is not determined, it backtracks to earlier vertex to find out whether there are yet unvisited vertices.

As seen, the search described above is inherently recursive. We can determine a very simple recursive process to visit the vertices within a depth first search. The DFS is more or less alike to pre-order tree traversal. The procedure can be described as below:

Begun from any vertex (source) in the graph and mark it visited. Determine vertex that is adjacent to the source and not earlier visited via adjacency matrix & mark it visited. Repeat this procedure for all vertices that is not visited, if vertex is determined visited in this procedure, then return to the earlier step and begin the same process from there.

If returning back toward source is not possible, then DFS from the originally chosen source is complete and begin DFS using any unvisited vertex.

1686_DEPTH FIRST SEARCH.png

Figure: A Digraph

Let the digraph of Figure. Begun with S and mark it visited. Then visit the next vertex A, after that C & then D and finally E. Now there are no adjacent vertices of E to be visited next. Thus, now, backtrack to earlier vertex D as it also has no unvisited vertex. Now backtrack to C, then A, finally to S. Now S has an unvisited vertex B.

Begun DFS with B as a root node and then visit F. Now all of the nodes of the graph are visited.

Figure shows a DFS tree with a sequence of visits. The first number mention the time at which the vertex is visited first and the second number mention the time upon which the vertex is visited throughout back tracking.

386_DEPTH FIRST SEARCH1.png

Figure: DFS tree of digraph of above figure

The DFS forest is illustrated with shaded arrow in  above Figure.

Posted Date: 4/11/2013 5:06:29 AM | Location : United States







Related Discussions:- Depth first search, Assignment Help, Ask Question on Depth first search, Get Answer, Expert's Help, Depth first search Discussions

Write discussion on Depth first search
Your posts are moderated
Related Questions
what is queues? how it work? and why it used? i want an assignment on queue .....

In file access: what is the difference between serial, sequential and indexed sequential searching

We will start by defining a new structure called Heap. Figure 3 illustrates a Binary tree. Figure: A Binary Tree A complete binary tree is said to assure the 'heap con

implement multiple stacks ina single dimensional array. write algorithams for various stack operation for them.

A telephone directory having n = 10 records and Name field as key. Let us assume that the names are stored in array 'm' i.e. m(0) to m(9) and the search has to be made for name "X"

Data type An implementation of an abstract data type on a computer. Therefore, for instance, Boolean ADT is implemented as the Boolean type in Java, and bool type in C++;

Program segment for deletion of any element from the queue delete() { int delvalue = 0; if (front == NULL) printf("Queue Empty"); { delvalue = front->value;

what happen''s in my computer when i input any passage

Determine about the unreachable code assertion An unreachable code assertion is an assertion that is placed at a point in a program that shouldn't be executed under any circum

Adjacency list representation An Adjacency list representation of Graph G = {V, E} contains an array of adjacency lists mentioned by adj of V list. For each of the vertex u?V,