Handling Scenario 2

To detect both cases of Scenario 2, states removed from the priority queue need to be saved on a searchable structure.

However, the number of states removed could become large, and a linear (O(n)) search of a large structure would take too much time.

Solution: Maintain a hash table "Closed" of states that have been removed from the priority queue and check to see if a state has already been created in constant (O(1)) time.