Professional Documents
Culture Documents
Naren Nidamanuri Assignment 3 BU Id:248645
Naren Nidamanuri Assignment 3 BU Id:248645
Assignment 3
BU id:248645
6.
Given the following adjacency list representation of a
weighted graph:
(a)
Write a function to perform breadth first (call your
function
bfs) search of the graph. The function should take as
arguments: a graph,
the starting node and the goal node. It should return as
output the path
from the start to the goal.
For example,
gt& (bfs graph 'a 'g) returns (a b d g)
Solution
(a (b c))
(b (a d))
(c (a d e))
(d (b c e g))
(e (c d f ))
(f (e g))
(g (d f))
(defun set_predecessor(x y)
(defun return_predecessor(x)
(gethash x predecessor_list)
)
(defun breadth(open closed goal)
(cond
(setq open (append (cdr open) (generate-descendants state open closed goal)))
(set_predecessor x state)
)
(defun find-children(state graph)
(t
)
(b) write a function which given a source node and a goal
node, it performs
a depth first search of the graph.
(setq graph '(
(a (b c))
(b (a d))
(c (a d e))
(d (b c e g))
(e (c d f ))
(f (e g))
(g (d f))
)
)
)
)
)
)
)
)