Page 1 of 1

Given the representation of a directed graph as an adjacency list (list of neighbors): >(setq graph '( (a b c ) (b a d )

Posted: Sun Jul 03, 2022 9:59 am
by answerhappygod
Given the representation of a directed graph as an adjacencylist (list of neighbors): >(setq graph '( (a b c ) (b a d ) (c ad e ) (d b c e g) (e c d f) (f e g) (g d f) ) ) where, the firstelement of each sub-list is the source node and the tail of thesub-list are its neighbors, (for example the sub-list (a b c) meansthere is a link from a to b and a link from a to c). >Write afunction to perform depth first search of a graph (call yourfunction dfs). The function should take as arguments: a graphdefined as above, the starting node for the search and the goalnode of the search. It should return as output the path found fromthe starting node to the goal node. For example, >(dfs graph 'a'g) returns (a b d c e f g) >(dfs graph ‘c ‘d) returns (c a bd