60 likes | 144 Views
Extra notes Modified from Callan R (2003) Artificial Intelligence Palgrave ISBN 0-333-80136-9 pg 50-55. The graph. Psudeocode for BFS. node current; queue toVisit; List alreadyVisited; put root node in toVisit; while toVisit is notEmpty current=first node in toVisit;
E N D
Extra notes Modified from Callan R (2003) Artificial Intelligence Palgrave ISBN 0-333-80136-9 pg 50-55
Psudeocode for BFS • node current; • queue toVisit; • List alreadyVisited; • put root node in toVisit; • while toVisit is notEmpty • current=first node in toVisit; • remove first node in toVisit; • if current==goal • add current to alreadyVisited; • return true; • endif • for each child node C of current • add C to toVisit; • endfor; • add current to alreadyVisited; • endwhile;
toVisit alreadyVisited • A [] • BC A • CDE AB • DEFGH ABC • EFGHI ABCD • FGHIJK ABCDE • GHIJKLM ABCDEF • HIJKLM ABCDEFG • IJKLMN ABCDEFGH • JKLMNO ABCDEFGHI • KLMNO ABCDEFGHIJ • LMNO ABCDEFGHIJK • MNOP ABCDEFGHIJKL • NOPQ ABCDEFGHIJKLM • OPQ ABCDEFGHIJKLMN • PQ ABCDEFGHIJKLMNO • Q ABCDEFGHIJKLMNOP • [] ABCDEFGHIJKLMNOPQ
Psudeocode for DFS • node current; • stack toVisit; • List alreadyVisited; • put root node in toVisit; • while toVisit is notEmpty • current=first node in toVisit; • remove first node in toVisit; • if current==goal • add current to alreadyVisited; • return true; • endif • for each child node C of current • add C to toVisit; • endfor; • add current to alreadyVisited; • endwhile;
toVisit alreadyVisited • A [] • BC A • DEC AB • IEC ABD • OEC ABDI • EC ABDIO • JKC ABDIOE • KC ABDIOEJ • C ABDIOEJK • FGH ABDIOEJKC • LMGH ABDIOEJKCF • PMGH ABDIOEJKCFL • MGH ABDIOEJKCFLP • QGH ABDIOEJKCFLPM