D

Recherche en profondeur (DFS)

DFS

La Recherche en Profondeur (DFS) est un algorithme pour parcourir ou rechercher des structures de données en arbre ou en graphe.

La recherche en profondeur (DFS) est une méthode fondamentale algorithm used in l'informatique for traversing or searching tree or graph et des dimensions des données d'entrée.. The algorithm starts at the root node (or an arbitrary node in the case of a graph) and explores as far as possible along each branch before backtracking. This approach results in a depthward exploration of the structure.

DFS peut être implémenté en utilisant une structure de données pile, soit explicitement avec une pile, soit implicitement par la récursion. Les étapes de l'algorithme incluent :

  1. Commencez par la racine (ou un nœud arbitraire).
  2. Marquez le nœud comme visité.
  3. Explorez chaque nœud adjacent non visité, en approfondissant dans la structure.
  4. Si un nœud n’a pas de nœuds adjacents non visités, revenez au dernier nœud visité avec des voisins non visités.

DFS is particularly useful for problems where a solution might be found deep within the structure, such as solving mazes, puzzle-solving, or conducting searches in intelligence artificielle applications. It can also be leveraged to find connected components in graphs or to perform topological sorting.

However, DFS has its limitations, such as the potential for deep recursion leading to stack overflow and the inability to find the shortest path in unweighted graphs. Due to its nature, it may explore paths that do not lead to a solution, making it less efficient in some scenarios compared to other algorithms comme la recherche en largeur (BFS).

oEmbed (JSON) + /