You are on page 1of 13

Name: Shehryar Rauf Kiyani

RegNo: FA18-BCS-097
Subject: Artificial Intelligence

Assignment 1
Solving Squares World Problem by Using Search Algorithms

1. Show the search tree for depth-first search. Mark the nodes with the orders they are visited.
How many nodes are visited until you reach the goal?

In depth first search we maintained the stack to reach the goal state. First we visit node1 than put it
out from the stack then its children node2 and node 3 put in the stack as the rule is last in first out so
we search the top node in the stack which is node3 and then put it out and check node2 and again put
it out and insert node4 than check it is goal state or not

Node1 B C

Node3

A
Node2
B C
A B C

Node4

A B

This is the search tree


Node1

Node3

A
Node2
B C
A B C

Node4

A B
Node1

Node3

Node2

A B C

Node4

A B
Node1

Node3

Node2

Node4

A B
Node1

Node3

Node2

Node4

Hence the number of nodes visited to reach the goal state is 4

Node1 ->Node3->Node2->Node->4
2. Show the search tree for breadth-first search. Mark the nodes with the orders they are visited.
How many nodes are visited?

Node1 A

B C

Node3

Node2
A B C B C

Node4
C

A B

This is the search tree

In breadth first search we visited the nodes from level by level. First we visit node1 than node2 and
node3 and then node4.
Node1

Node3

A
Node2
B C
A B C

Node4

A B
Node1

Node3

A
Node2
B C

Node4

A B
Node1

Node3

Node2

Node4

A B
Node1

Node3

Node2

Node4

Hence to reach the goal state we visited 4 nodes

Node1 ->Node2->Node3->Node->4
3) Show the search tree for A∗ with g(s) being the number of moves so far and h(s) of your own
definition. Mark the nodes with the values of f(s) = g(s) + h(s). How many nodes are visited?

Node1
A

B C

g=1 g=1

Node3

A
Node2
B C
H=5 H=10
A B C

Node4 g=1

C H=0

A B

G=Number of moves h=estimated value to reach to goal state

N ode1 ------->Node2 Node1------------ >Node3

F(n)=g(s)+h(s) F(n)=g(s)+h(s)

F(n)=1+5 F(n)=1+10

F(n)=6 F(n)=11

As 6<11

So we choose the path Node1->Node2

Node1Node2----- >Node4
F(n)=g(s)+h(s)

F(n)=1+1+0

F(n)=2

So the number of nodes visited to reach the goal state is 3

Node1->Node2->Node4

4) Which search method worked the best in this specific problem? Why?

Ans According to analysis of among three searches A* work best in this specific problem because in
this search the number of nodes to reach the goal state is less than remaining two searches(best
first search and depth first search) and the best first search and depth search are blind searches
technique and we not sure to get the optimal solution as both these searches provide good solution
and may or may not provide optimal solution but in the case of A* algorithm we assure to get the
optimal solution. So A* worked best in this specific problem

You might also like