"graph searchusing paths stack instead of recursiondef search(startgoalgraph)solns generate(([start][])goalgraphsolns sort(key=lambda xlen( )return solns def generate(pathsgoalgraph)solns [while pathsfrontpaths paths state front[- if state =goalsolns append(frontelsefor arc in graph[state]if arc not in frontpaths (front [arc])paths return solns returns solns list use tuple-stack pop the top path goal on this path add all extensions if __name__ ='__main__'import gtestfunc gtestfunc tests(searchto avoid cyclesboth searchers keep track of nodes visited along path if an extension is already on the current pathit is loop the resulting solutions list is sorted by increasing lengths using the list sort method and its optional key value transform argument to test the searcher modulessimply run themtheir self-test code calls the canned search test in the gtestfunc modulec:\pp \dstruct\classicspython gsearch py [[' '' '' '][' '' '' '' '' '' ']ag [[' '' '][' '' '' '][' '' '' '' '' ']gf [[' '' '' '' '][' '' '' '' '' '' '][' '' '' '' '' '' '][' '' '' '' '' '' ']ba [[' '' '' '' '' ']da [ :\pp \dstruct\classicspython gsearch py [[' '' '' '][' '' '' '' '' '' ']ag [[' '' '][' '' '' '][' '' '' '' '' ']gf [[' '' '' '' '][' '' '' '' '' '' '][' '' '' '' '' '' '][' '' '' '' '' '' ']ba [[' '' '' '' '' ']da [this output shows lists of possible paths through the test graphi added two line breaks to make it more readable (python pprint pretty-printer module might help with readability here as wellnotice that both searchers find the same paths in all testsbut the order in which they find those solutions may differ the gsearch order depends on data structures