Overview
This paper introduces the basic concept of depth first and breadth first search method.
Open Table saves paths that have not been visited
The close table saves the visited path, preventing entry into a dead loop. Specific Algorithms
Accessing all reachable vertices from one of the start nodes is useful in many scenarios, such as how do we want to traverse from H to C in the following image?
The specific steps from H, to find the direct successor of H {b,d, L}, thus constituting the three candidate path {h->b,h->d,h->l}, at this time {b,d,l} becomes open vertices will open vertices (and the path to which they belong) are placed in the open table. Select a vertex from the open table to remove the open table and generate a successor to this vertex
For example, we chose L, whose successor is {m,f,h}, because H has been visited, so it cannot be placed in the open table, otherwise it will cause a dead loop, so there is {b,d,m,f} in the Open table.
To prevent a dead loop, there will be a close table that records the points that have been visited, and once a point enters the close table, it will never be accessed the second time so continue knowing that the target vertex is found or the target vertex is not found
Note: Breadth first or depth first is entirely determined by the way data is accessed from the Open table
* Open Table is advanced and out is the depth first
* Open Table is FIFO is the breadth first example and pseudo code depth First sample
| Vertex visited (and hence closed) |
Open list (stack top | at left)
| H |
B D L |
| B |
D d L |
| D |
G J D L |
| G |
J J D L |
| J |
E I M J D L |
| E |
K I M J D L |
| K |
I M J D L |
| I |
F M J D L |
| F |
A l M J D L |
| A |
L M J D L |
| L |
M m J D L |
| M |
C M J D L |
| C |
M J D L |
Depth-first pseudo-code
/* Initialization *
/Queue openlist = {Startvertex}
/* loop *
/while (closednodes! = Numberofnodes &&am p;!openlist.empty ())
{
Closingvertex = Openlist.dequeue ();
Increment number of closednodes;
For each non-closed vertex not in the openlist, and with a
edge to it from Closingvertex
{
Openlist.enqueue (v Ertex);
}
}
Breadth First similar References
Http://jhave.org/algorithms/graphs/depthbreadth/depth-breadth.shtml