Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

ALGORITHM TO IMPLEMENT BREADTH FIRST SEARCH STEP 1: Enter the node to be found. STEP 2: Create a variable called NODE-LIST and set it to

image text in transcribedimage text in transcribed

ALGORITHM TO IMPLEMENT BREADTH FIRST SEARCH STEP 1: Enter the node to be found. STEP 2: Create a variable called NODE-LIST and set it to the initial state. STEP 3: Until a goal state is found or NODE-LIST is empty do : (a)Remove the first element from NODE-LIST and call it E. IF NODE-LISt was empty , quit. (b) For each way that each rule can match the state described in E do : i. Apply the rule to generate a new state. ii.If the new state is a goal state, quit and return this state. iii. Otherwise, add the new state to the end of NODE-LIST. STEP 4: Print the output as the path traversed. STEP 5: Exit. 1) Implement the given Breadth First Search function below in Prolog, 2) Draw a tree by hand and assign int values to each node 3) Use the tree in a query to: test and show how Breadth First Search function work 4) Explain the code and resulting output 5) Modify the code to add 5 to each node before printing (You can also add a trace screenshot for your goal) SWISH File Edit Examples Help Search Q ((new)) 277 sine start print bls(4,114.7.1,2],[7,81(1,0,3,5),(2,91.19,611.0 A Program A Program + 27 first call of the function (queue is empty) 28 start traversing the tree in BFS order, 29 targuments (Root of tree, complete tree, Queue to traverse nodes) 30 start print_bfs (Root, Tree, []):-write(Root), write(" "), 31 find_children (Root, Tree,Q), 32 print_bfs (Tree,m). 33 trecursive call, queue has nodes, 34 repeatedly: dequeue, get children: 35 if children - NULLI- enqueue them 36. 2- call with new queue 37 Barguments :: (complete tree, Queue to traverse nodes) 38 print_bfs (Tree, [X|Y]):- write(x), write(" "), 39 find_children (x,Tree, Children), 40 Children \- nill -> merge (Y, Children,Q), print bfs (Tree,m); print_bfe(Tree,Y). 42 tif queue is empty, stop. 43 print_bts(Tree, []). 44 45 46 get all child nodes of the node R: 47 trecursivly go through the every element in 48 #tree looking for node R 49 targuments!: (node we are expanding, complete tree 50 ,list of children to return) 51 find_children (R, IHNT),C):- R ---> copy(N,C); 52 find_children(RT,C). 53 find children (R,[1,nill). 54 55 tcopy the value to another variable 56 copy(x,x). 57 58 combine two lists together 59 merget 1,Y,Y). 60 merge [7],Y, [R]):-merge(T,Y,R). Singleton variables: [Tree) Singleton variables: (R) 4 7 12 8 0 3 596 true false 7- start_print_bf8(4,114,7,1,2],[7,8],[1,0,3,5),(2,9],[9,6]], 0) 61 Examples History Solutions table results Runt ALGORITHM TO IMPLEMENT BREADTH FIRST SEARCH STEP 1: Enter the node to be found. STEP 2: Create a variable called NODE-LIST and set it to the initial state. STEP 3: Until a goal state is found or NODE-LIST is empty do : (a)Remove the first element from NODE-LIST and call it E. IF NODE-LISt was empty , quit. (b) For each way that each rule can match the state described in E do : i. Apply the rule to generate a new state. ii.If the new state is a goal state, quit and return this state. iii. Otherwise, add the new state to the end of NODE-LIST. STEP 4: Print the output as the path traversed. STEP 5: Exit. 1) Implement the given Breadth First Search function below in Prolog, 2) Draw a tree by hand and assign int values to each node 3) Use the tree in a query to: test and show how Breadth First Search function work 4) Explain the code and resulting output 5) Modify the code to add 5 to each node before printing (You can also add a trace screenshot for your goal) SWISH File Edit Examples Help Search Q ((new)) 277 sine start print bls(4,114.7.1,2],[7,81(1,0,3,5),(2,91.19,611.0 A Program A Program + 27 first call of the function (queue is empty) 28 start traversing the tree in BFS order, 29 targuments (Root of tree, complete tree, Queue to traverse nodes) 30 start print_bfs (Root, Tree, []):-write(Root), write(" "), 31 find_children (Root, Tree,Q), 32 print_bfs (Tree,m). 33 trecursive call, queue has nodes, 34 repeatedly: dequeue, get children: 35 if children - NULLI- enqueue them 36. 2- call with new queue 37 Barguments :: (complete tree, Queue to traverse nodes) 38 print_bfs (Tree, [X|Y]):- write(x), write(" "), 39 find_children (x,Tree, Children), 40 Children \- nill -> merge (Y, Children,Q), print bfs (Tree,m); print_bfe(Tree,Y). 42 tif queue is empty, stop. 43 print_bts(Tree, []). 44 45 46 get all child nodes of the node R: 47 trecursivly go through the every element in 48 #tree looking for node R 49 targuments!: (node we are expanding, complete tree 50 ,list of children to return) 51 find_children (R, IHNT),C):- R ---> copy(N,C); 52 find_children(RT,C). 53 find children (R,[1,nill). 54 55 tcopy the value to another variable 56 copy(x,x). 57 58 combine two lists together 59 merget 1,Y,Y). 60 merge [7],Y, [R]):-merge(T,Y,R). Singleton variables: [Tree) Singleton variables: (R) 4 7 12 8 0 3 596 true false 7- start_print_bf8(4,114,7,1,2],[7,8],[1,0,3,5),(2,9],[9,6]], 0) 61 Examples History Solutions table results Runt

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Medical Image Databases

Authors: Stephen T.C. Wong

1st Edition

1461375398, 978-1461375395

More Books

Students also viewed these Databases questions

Question

What is an interface? What keyword is used to define one?

Answered: 1 week ago