Graph Search Algorithm

// The frontier is an ordered collection -- i.e., stack, queue, or priority queue

GRAPH-SEARCH(initial_state, frontier){
    explored = {} // a set
    frontier.push(initial_state)

    while(frontier is not empty)
        u = frontier.pop() // depends on search strategy
        if(u is goal){
             return construct_path(u)
        }

        if(u not in explored){
             explored.add(u)
             for each successor s of u {
                frontier.push(s)
             }
        }
    }
    return FAIL
}