Breadth First Search

Breadth First Search

Algorithme de parcours en largeur

Page d'aide sur l'homonymie Pour les articles homonymes, voir BFS.

L'algorithme de parcours en largeur (ou BFS, pour Breadth First Search) permet le parcours d'un graphe de manière itérative, en utilisant une file. Il peut par exemple servir à déterminer la connexité d'un graphe.

Principe

Cet algorithme diffère de l'algorithme de parcours en profondeur par le fait que, à partir d'un sommet S, il liste d'abord les voisins de S pour ensuite les explorer un par un. Ce mode de fonctionnement utilise donc une file FIFO dans laquelle il prend le premier sommet et place en dernier ses voisins non encore explorés.

Si le graphe est cyclique, il faudra en outre marquer les sommets déjà visités pour que l'algorithme puisse se terminer.


  1. Mettre le nœud de départ dans la file.
  2. Retirer le nœud du début de la file pour l'examiner.
  3. Mettre tous les voisins non examinés dans la file (à la fin).
  4. Si la file n'est pas vide reprendre à l'étape 2.

Implémentation

BFS(graphe G, sommet s):
{
  f= CreerFile();
  Marquer(s);
  Enfiler(f, s);
  TANT-QUE NON FileVide(f) FAIRE
      x = Défiler(f);
      Afficher(x)
      TANT-QUE ExisteFils(x) FAIRE
          z = FilsSuivant(x);
          SI NonMarqué(z) ALORS 
              Marquer(z);
              Enfiler(f, z);
          FIN-SI
      FIN-TANT-QUE
  FIN-TANT-QUE
}

Exemple

Sur le graphe suivant, cet algorithme va alors fonctionner ainsi:

Graphes.dfs-bfs.exemple.png

Il explore dans l'ordre les sommets A, B, C, E, D, F, G, contrairement à l'algorithme de parcours en profondeur qui cherche dans cet ordre : A, B, D, F, C, G, E.

Ce document provient de « Algorithme de parcours en largeur ».

Wikimedia Foundation. 2010.

Contenu soumis à la licence CC-BY-SA. Source : Article Breadth First Search de Wikipédia en français (auteurs)

Игры ⚽ Нужно сделать НИР?

Regardez d'autres dictionnaires:

  • Breadth-first search — Infobox Algorithm class=Search Algorithm Order in which the nodes are expanded data=Graph time=O(|V|+|E|) = O(b^d) space=O(|V|+|E|) = O(b^d) optimal=yes (for unweighted graphs) complete=yesIn graph theory, breadth first search (BFS) is a graph… …   Wikipedia

  • breadth-first-search — paieška į plotį statusas T sritis informatika apibrėžtis ↑Paieškos medžio apėjimo būdas, kai išanalizavus visus to paties lygio mazgus pereinama prie kito lygio mazgų. atitikmenys: angl. breadth first search ryšiai: dar žiūrėk – paieškos medis… …   Enciklopedinis kompiuterijos žodynas

  • Depth-first search — Order in which the nodes are visited Class Search algorithm Data structure Graph Worst case performance …   Wikipedia

  • Iterative deepening depth-first search — Graph and tree search algorithms Alpha beta pruning A* B* Beam Bellman–Ford algorithm Best first Bidirectional …   Wikipedia

  • Search algorithm — In computer science, a search algorithm, broadly speaking, is an algorithm that takes a problem as input and returns a solution to the problem, usually after evaluating a number of possible solutions. Most of the algorithms studied by computer… …   Wikipedia

  • A* search algorithm — In computer science, A* (pronounced A star ) is a best first, graph search algorithm that finds the least cost path from a given initial node to one goal node (out of one or more possible goals). It uses a distance plus cost heuristic function… …   Wikipedia

  • Beam search — is a heuristic search algorithm that is an optimization of best first search that reduces its memory requirement. Best first search is a graph search which orders all partial solutions (states) according to some heuristic which attempts to… …   Wikipedia

  • Uniform-cost search — In computer science, uniform cost search (UCS) is a tree search algorithm used for traversing or searching a weighted tree, tree structure, or graph. Intuitively, the search begins at the root node. The search continues by visiting the next node… …   Wikipedia

  • First Roumanian-American congregation — First Roumanian American congregation …   Wikipedia

  • Depth-limited search — Class Search Algorithm Data structure Graph Worst case performance O( | V | + | E | ) …   Wikipedia

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”