Algorithm of in-depth course

The algorithm of in-depth course (or DFS, for Depth First Search ) allows the recursive course of a unspecified graph.

Principle

It is an algorithm of research which progresses starting from a top S while being called recursively for each top close to S.

The name of in-depth algorithm is with the fact that, contrary to the Algorithme of course in width, it explores in fact “at bottom” the ways one by one: for each top, it takes first top close until a top do not have any more neighbors (or whom all its neighbors are marked), and returns then at the top father.

If G is not a tree, the algorithm could turn indefinitely, therefore one must moreover mark each top already traversed, and traverse only the not yet marked tops.

Lastly, it will be noted that it is completely possible to repeatedly implement it using a pile LIFO containing the tops to be explored: one depilates a top and one piles up his not yet explored neighbors.

Recursive implementation

DFS (graph G, top S): { To mark (S); beginning FOR EACH element sfils of Neighbor (S) TO MAKE IF NonMarqué (sfils) THEN DFS ( G , sfils); FIN-SI FIN-POUR fine }

Neighbor (S): return the list of the adjacent tops to S.

To mark (Node): mark a node, so as not to consider it several times.

SousArbre (node U): turn over the under-tree of root U.

Example

Concretely let us see the operation of this algorithm on the following graph:

Algorithm DFS starts at the top has, we will be appropriate that the tops on the left on this graph will be selected before those of right-hand side. If the algorithm uses indeed a marking of the tops to avoid turning indefinitely buckles some, there will be then the order of visit according to: WITH, B, D, F, C, G, E.

Let us suppose now that we do not use the method of marking, one would then have the visit of the following tops in the order: With, B, D, F, E, has, B, D, F, E, etc indefinitely, since the algorithm cannot leave the loop has, B, D, F, E and will thus reach never C or G.

Or:

Depth (G, S) For each U in NR to make considering: = false RP (G, S) RP (G, U) considering: = true for each edge in (U, v) in making so considering: = false then RP (G, v)

G= (NR, A), NR being the tops and have the edges of a graph and S a starting top.

considering is a table of Booléen considering: = true if and only if the top is accessible from S.

Random links:Gretchen Bleiler | TEE Rheingold | List sultans of Anjouan | Anthony Swofford | Navegantes (Santa Catarina) | Dmitri_Donskoi