Modifying The Expansion Algorithm

Currently, the expansion algorithm checks for solution cycles through a call to OccursOnPath, which checks the path back from a newly created state to the root for a duplicate state (O(d[n])).

Checking for duplicate states on Closed performs the same function more efficiently (O(1)).

Changes to Expand:

Expand(u)
   children = {}
   for each name ∈ moveNames do
      child = mover.doMove(name, u)
      if child ≠ null // and not OccursOnPath(child, u)
         then d[child] = d[u] + 1
              pred[child] = u 

              // Scenario 1
              if there is an x such that x = child and x ∈ Open
                 then if d[child] < d[x] // Case 2
                         then d[x] = d[child]
                              pred[x] = pred[child]
                              Promote(PQ,x)
		         else // Do nothing: Case 1
                      continue

              // Scenario 2
              if there is an x such that x = child and x ∈ Closed
                 then if d[child] < d[x] // Case 2
                         then d[x] = d[child]
                              pred[x] = pred[child]
                              Add(PQ,x)
                              Add(Open,x)
                              Remove(Closed,x)
                         else // Do nothing: Case 1
		      continue

              add child to children
   return children

Note that some (and perhaps many) of the states previously returned by Expand will now simply be ignored by the else clauses that do nothing.