General Graph Search Algorithm
The following is a general graph searching procedure.
Key Features
-
\(b \rightarrow \) breadth/average branching factor
-
\(d \rightarrow \) depth
-
Time Complexity: \(O(b^d)\)
-
Space Complexity: \(O(b^d)\)
-
OPENlist - contains the nodes which are to be visited. -
CLOSEDlist - contains the nodes which have been visited and their children nodes have been discovered.
As the search proceeds, more and more of the implicitly defined state space gets explicit.
Search might reach the same node n along different paths.
The Algorithm
-
Create a search graph, \(G\) consisting solely of the start node \(s\). Put \(s\) on a list called
OPEN. TheOPENlist will consist of nodes that need to be explored -
Create a list called
CLOSEDthat is initially empty TheCLOSEDlist will keep track of nodes that are already explored/visited -
LOOP: If
OPENis empty, exit with failure -
Select the first node from
OPEN, remove it fromOPENand put it onCLOSED. Call this node \(n\). -
If \(n\) is a goal node, exit successfully with the solution obtained by tracing a path along the pointers from \(n\) to \(s\) in \(G\).
Arcs are created in step 7
-
Expand node \(n\), generating a set \(M\) of its successors and install them as successors of \(n\) in \(G\).
-
Establish a pointer to \(m\) from those members of \(M\) that were not already in \(G\) (i.e. not already on either
OPENorCLOSED)-
Add these members of \(M\) to
OPEN -
For each member of \(M\) that was already on
OPENorCLOSED, decide whether or not to redirect its pointer to \(n\) -
For each member of \(M\) already on
CLOSED, decide for each of its descendants in \(G\) whether or not to redirect their pointers to \(n\).
-
-
Reorder the list
OPEN, either according to some arbitrary scheme or according to heuristic merit. -
Goto LOOP
Theorem: Termination of GRAPHSEARCH
GRAPHSEARCH always terminates for a finite graph.
The GRAPHSEARCH algorithm always terminates in step 3 or step 5. Notice that in every loop of the algorithm, a node is removed from the OPEN list and that only a finite number of new successors are added to OPEN.
For finite graphs, we ultimately run out of new successors and thus, unless the algorithm terminates successfully in step 5 by finding a goal node, it will terminate in step 3 after eventually depleting OPEN.
Therefore, the algorithm always terminates for finite graphs.