Professional Documents
Culture Documents
AI-Problem Set 1
AI-Problem Set 1
I. Search: Algorithms A
2 1 3
Consider the state space search problem shown to the right. A is the 1 1 0
B C D
start state and the shaded states are goals. Arrows encode possible
state transitions, and numbers by the arrows represent action costs. 2 1 1 3 1 1
Note that state transitions are directed; for example, 0 0 0 0 0 0
A → B is a valid transition, but B → A is not. E F G H J K
Numbers shown in diamonds are heuristic values that estimate the
optimal (minimal) cost from that node to a goal.
For each of the following search algorithms, write down the nodes that are removed from fringe in the course of the
search, as well as the final path returned. Because the original problem graph is a tree, the tree and graph versions of
these algorithms will do the same thing, and you can use either version of the algorithms to compute your answer.
Assume that the data structure implementations and successor state orderings are all such that ties are broken
alphabetically. For example, a partial plan S → X → A would be expanded before S → X → B; similarly, S → A → Z would
be expanded before S → B → A.
SOLUTION:
VISITED – A, B, E, F
FRINGE
A //Starting node
BCD //Node A is removed from fringe and added to the node visited
E, F, C, D //Node B is removed from fringe and added to the node visited and the
successors of node B is added to the fringe
F, C, D // Node E is removed from fringe and added to the node visited
C, D // Node F is removed from fringe and added to the node visited
Since we reached the node F (goal), we’ll now stop traversing the tree and give the best path.
The best path to reach the goal node F is A->B->F.
1
SOLUTION:
VISITED – A, B, C, D
FRINGE
A //Starting node
B,C, D //Node A is removed from fringe and added to the node visited
C, D, E, F //Node B is removed from fringe and added to the node visited and the
successors of node B is added to the fringe
D, E, F, G, H // Node C is removed from fringe and added to the node visited and
the successors of node C is added to the fringe
E, F, G, H, J, K // Node D is removed from fringe and added to the node visited and
the successors of node D is added to the fringe
Since we reached the node D (goal), we’ll now stop traversing the tree and give the best path.
The best path to reach the goal node D is A->D.
SOLUTION:
VISITED – A, C, B, G
FRINGE (PATHCOST)
A(0) //Start node
B(2), C(1), D(3) //Node A is removed from fringe and added to the node visited
and the successors of node A is added to the fringe
B(2), D(3), G(2), H(4) // Since Node C has the lowest cost in the fringe, it is removed
from fringe and added to the node visited and the successors
of node C is added to the fringe
D(3), E(4), F(3), G(2), H(4) // Since Node B and Node G are the lowest cost in the fringe, we
will choose the node with the highest level in the tree, therefore, Node B is removed from
fringe and added to the node visited and the successors of node B is added to the fringe
D(3), E(4), F(3), H(4) // Since Node G has the lowest cost in the fringe, it is removed
from fringe and added to the node visited
Since we reached the node G (goal), we’ll now stop traversing the tree and give the best path.
The best path to reach the goal node G is A->C->G.
(d) [2 pts] Greedy Search
SOLUTION:
VISITED – A, D
FRINGE (Hcost)
A(2) //Starting node
B(1), C(1) ,D(0) //Node A is removed from fringe and added to the node visited
B(1), C(1) //Since Node D has the lowest heuristic cost, it will be
removed from fringe and added to the node visited
Since we reached the node D (goal), we’ll now stop traversing the tree and give the best path.
The best path to reach the goal node D is A->D.
SOLUTION:
VISITED – A, C, G
FRINGE (Fcost = Hcost + Gcost)
A(2) //Starting node
B(3), C(2) ,D(3) //Node A is removed from fringe and added to the
node visited
B(3), D(3), G(2), H(4) //Since Node C has the lowest Fcost , it will be removed
from fringe and added to the node visited and the
successors of node C is added to the fringe
B(3), D(3), H(2) //Since Node G has the lowest Fcost, it will be removed
from fringe and added to the node visited
Since we reached the node G (goal), we’ll now stop traversing the tree and give the best path.
The best path to reach the goal node G is A->C->G.
3
II. Search: Heuristic Function Properties
For the following questions, consider the search problem shown on the left. It has only three states, and three directed
edges. A is the start node and G is the goal node. To the right, four different heuristic functions are defined, numbered I
through IV.
6
A G
h(A ) h(B ) h(G )
2 I 4 1 0
3 II 5 4 0
B III 4 3 0
IV 5 2 0
Admissible? Consistent?
I Yes No Yes No
II Yes No Yes No
IV Yes No Yes No
SOLUTION:
Admissibility: The Estimated cost is never more than the Actual cost from Current Node to Goal Node.
h(n) <= h*(n) for every node n where h* is the real cost to the goal.
Consistency: A heuristic is consistent if for all paths, h(N) – h(L) <= path cost(N->L), where N and L stand
in for the actual node.
I.
When N = A and L=G then, h(N) – h(L) <= path cost(N->L) is 4-0 = 4 is less than to path cost which
is 6
4
When N = A and L = B then, h(N) – h(L) <= path cost(N->L) is 4-1 = 3 is not less than to path cost
which is 2
When N = B and L = G then, h(N) – h(L) <= path cost(N->L) is 1-0 = 1 is less than to path cost
which is 3
Since there some added heuristics that is not less than to the sum of their path cost, therefore
heuristic I is not consistent.
II.
When N = A and L=G then, h(N) – h(L) <= path cost(N->L) is 5-0 = 5 is less than to path cost which
is 6
When N = A and L = B then, h(N) – h(L) <= path cost(N->L) is 5-4 = 3 is not less than to path cost
which is 2
When N = B and L = G then, h(N) – h(L) <= path cost(N->L) is 4-0 = 4 is not less than to path cost
which is 3
Since there some added heuristics that is not less than to the sum of their path cost, therefore
heuristic II is not consistent.
III.
When N = A and L=G then, h(N) – h(L) <= path cost(N->L) is 4-0 = 4 is less than to path cost which
is 6
When N = A and L = B then, h(N) – h(L) <= path cost(N->L) is 4-3 = 1 is less than to path cost
which is 2
5
When N = B and L = G then, h(N) – h(L) <= path cost(N->L) is 3-0 = 3 is equal to path cost which is
3
Since there are no added heuristics that is greater than to the sum of their path cost, therefore
heuristic III is consistent.
IV.
When N = A and L=G then, h(N) – h(L) <= path cost(N->L) is 5-0 = 5 is less than to path cost which
is 6
When N = A and L = B then, h(N) – h(L) <= path cost(N->L) is 5-2 = 3 is not less than to path cost
which is 2
When N = B and L = G then, h(N) – h(L) <= path cost(N->L) is 2-0 = 2 is less than to path cost
which is 3
Since there some added heuristics that is not less than to the sum of their path cost, therefore
heuristic IV is not consistent.
6
Heuristic Function IV dominates Heuristic Function I because each of the heuristic functions of IV is
greater than Heuristic Function I.
6. Heuristic functions I and IV have no dominance relationship.
Heuristic Function I and Heuristic Function IV have dominance relationship because each of the
heuristic functions of IV is greater than Heuristic Function I.
Consider the state space graph shown above. A is the start state and G is the goal state. The costs for each edge are
shown on the graph. Each edge can be traversed in both directions. Note that the heuristic h1 is consistent but the
heuristic h2 is not consistent.
For each of the following graph search strategies (do not answer for tree search), mark which, if any, of the listed paths
it could return. Note that for some search strategies the specific path returned might depend on tie-breaking behavior.
In any such cases, make sure to mark all paths that could be returned under some tie-breaking scheme.
SOLUTIONS:
Depth first search = DFS can return any path therefore, A-B-D-G, A-C-D-G and A-B-C-D-F-G can be
returned.
Breadth first search = A-B-D-G and A-C-D-G are the only path that can be returned because both path
are the shallowest possible path. The path A-B-C-D-F-G cannot be return because it is deeper than the
two paths and BFS will only return all the shallowest path.
Uniform Cost Search (solution below):
Visited Node: A, B, C, D, F, G
Path returned: A-B-C-D-F-G
Fringe(Path Cost)
A(0) //Start Node
7
B(1),C(4) //Node A is removed from previous fringe and added to the node
visited and the connected nodes to node A is the new values of the
fringe
A(1),C(1),D(5) // Since Node B has the lowest cost in the previous fringe, it is added to
the node visited and the connected nodes to node B is the new values
of the fringe
A(4),B(1),D(3) //Since node A and Node C has the lowest cost in the previous fringe,
but node A is already visited, therefore we will choose Node C and add
it to the node visited and the connected nodes to node B is the new
values of the fringe
B(5),C(3),E(8),F(3),G(9) //Since node A and Node B are already visited, therefore we will
choose Node D from the previous fringe and add it to the node visited
and the connected nodes to node D is the new values of the fringe
D(3),G(5) //Since node C and Node F has the lowest cost in the previous fringe,
but node C is already visited, therefore we will choose Node F and add
it to the node visited and the connected nodes to node F is the new
values of the fringe
Fringe is empty //Since node D is already visited even if it has the lowest cost, it will
not be visited anymore, therefore, we will choose node G from the
previous fringe and add it to the visited node
Since the goal node (node G) is found, we will stop traversing return the path found.
Visited Node: A, B, C, D, F, G
Path returned: A-B-C-D-F-G
B 10 = 9+1 //Node A is removed from the previous fringe and added to node
C 12 = 8+4 visited and its successors that is not yet visited is the new values of the
fringe
C 10=8+2 //Since Node B has the lowest Fcost from the previous fringe, it is
D 13=7+6 removed from the previous fringe and added to node visited and its
successors that is not yet visited is the new values of the fringe
8
D 12=7+5 //Since Node C has the lowest Fcost from the previous fringe, it is
removed from the previous fringe and added to node visited and its
successors that is not yet visited is the new values of the fringe
E 15.5=1.5+14 //Node D is removed from the previous fringe and added to node
F 13=4+9 visited and its successors that is not yet visited is the new values of the
G 15=0+15 fringe
Fringe is empty //Since Node G is the only node in the previous fringe, we will just add
it to the node visited
Since the goal node(Node G) is already found, we will stop traversing and return the path found.
Visited Node: A, B, C, D, F, G
Path returned: A-B-C-D-F-G
A 10 = 10 + 0 //Start Node
B 13 = 12+1 //Node A is removed from the previous fringe and added to node
C 14 = 10+4 visited and its successors that is not yet visited is the new values of the
fringe
C 12 = 10+2 //Since Node B has the lowest Fcost from the previous fringe, it is
D 14=8+6 removed from the previous fringe and added to node visited and its
successors that is not yet visited is the new values of the fringe
D 13=8+5 //Since Node C has the lowest Fcost from the previous fringe, it is
removed from the previous fringe and added to node visited and its
successors that is not yet visited is the new values of the fringe
E 15=1+14 //Node D is removed from the previous fringe and added to node
F 13.5=4.5+9 visited and its successors that is not yet visited is the new values of the
G 15=0+15 fringe
Fringe is empty //Since Node G is the only node in the previous fringe, we will just add
it to the node visited
9
(b) Heuristic function properties
Suppose you are completing the new heuristic function h3 shown below. All the values are fixed except h3(B).
Node A B C D E F G
h3 10 ? 9 7 1.5 4.5 0
For each of the following conditions, write the set of values that are possible for h3(B). For example, to denote all non-
negative numbers, write [0, ∞], to denote the empty set, write ∅, and so on.
To make h3 admissible, h3 has to be less than or equal to the actual cost from Node B to Node G.
Using the consistency condition h(n) <= c(n,n’) + h(n’), we can see that other nodes satisfies this
except node B. Here are the consistency conditions that will involve node B:
10
(a) (6 pt) The Flea
You now control a single flea as shown in the maze above, which must reach a designated target location X.
However, in addition to moving along the maze as usual, your flea can jump on top of the walls. When on a
wall, the flea can walk along the top of the wall as it would when in the maze. It can also jump off of the wall,
back into the maze. Jumping onto the wall has a cost of 2, while all other actions ( including jumping back into
the maze) have a cost of 1. Note that the flea can only jump onto walls that are in adjacent squares (either
north, south, west, or east of the flea).
i. (2 pt) Give a minimal state representation for the above search problem.
The flea’s location is the state which consists of (x, y) coordinates. On the given map, the
environment includes walls and a target location or the goal. The possible move of the flea
depends on its location.
ii. (2 pt) Give the size of the state space for this search problem.
Based on the given statement, the size of state space can be determined by M x N (the map has
grids). Any of these locations are possible to be occupied by the flea including walls and open
squares.
11
(b) (6 pt) Long Lost Bug Friends
You now control a pair of long lost bug friends. You know the maze, but you do not have any information
about which square each bug starts in. You want to help the bugs reunite. You must pose a search problem
whose solution is an all-purpose sequence of actions such that, after executing those actions, both bugs will be
on the same square, regardless of their initial positions. Any square will do, as the bugs have no goal in mind
other than to see each other once again. Both bugs execute the actions mindlessly and do not know whether
their moves succeed; if they use an action which would move them in a blocked direction, they will stay where
they are. Unlike the flea in the previous question, bugs cannot jump onto walls. Both bugs can move in each
time step. Every time step that passes has a cost of one.
i. (2 pt) Give a minimal state representation for the above search problem.
Every state will have a boolean variable(one for each tile) so that we can mark if a certain
position contains a bug. Their starting position are said to be unknown, thus we don’t need to
keep track of the bugs. Also, since they are not allowed to jump or pass through the walls, only a
single square must be possible for both.
ii. (2 pt) Give the size of the state space for this search problem.
The size of the state is M x N but since every possible maze positions has a boolean value, the size
of A state can be represented as 2MN which is the binary value for the base of 2.
iii. (2 pt) Give a nontrivial admissible heuristic for this search problem.
hbugs = maximum Manhattan Distance of all possible positions the bugs can be in
Admissible heuristics must not overestimate the number of moves to solve a problem. Since the
bugs can only move to another position 1 block at a time and in only 4 directions, the optimal
scenario is that it has clear and unobstructed path (with no obstacles). It will not overestimate
because the number of the steps for each bug to meet is uncertain (both bugs acts mindlessly).
Which means the assurance is at least the shortest path between their farthest possible position
from one another.
12
3. (12 points) A* Graph Search function A*
Graph Search(problem) fringe ← an empty
priority queue
fringe ← Insert(Make-Node(Initial-State[problem]), fringe) closed ← an empty
set
Add Initial-State[problem] to closed loop if
fringe is empty then return failure
end if
node ← Remove-Front(fringe) if Goal-
Test(problem, State[node]) then return node
end if
for successor in GetSuccessors(problem, State[node]) do if
successor not in closed then Add successor to closed
fringe ← Insert(Make-Successor-Node(successor, node), fringe)
end if
end for
end loop
end function
The above implementation of A* graph search may be incorrect! In the list below circle all of the problems that the
bugs may cause when executing graph search and justify your answer. Note that the fringe is a priority queue.
Nodes are inserted into the fringe using the standard key for A*, namely f = g + h. h is a consistent heuristic.
(a) The GetSuccessors function could be called multiple times on the same state.
(b) The algorithm is no longer complete.
(c) The algorithm could return a sub optimal solution
(d) The implementation is incorrect, but none of the above problems will be caused.
(e) The implementation is correct.
To receive any credit you must briefly justify your answer in space below.
(a) This statement is false because when a node arrives at S state and is positioned in a fringe, S is also on the
closed list. So on all cases, a node can’t be placed in a fringe if it stops in the same state which is the S state,
and for this reason, the said state can be called to GetSuccessors once.
(b) The statement is false because the algorithm is A*search tree and it is complete. Whenever a node is
positioned on the fringe that terminated on the same state in the past the algorithm above will break off
the parts of the search tree and that is the distinction. In contrast to tree search, the sub trees that are
covered loses its copies.
(c) The statement is true because in the process of the insertion of the successor into closed which is the bug
itself, the time of the node insertion into the fringe happens, somewhat the node gets popped at that time
from that fringe. The state will be in a closed list in the first path the bug has passed, as an aftereffect. Sub
optimality can be the cause of it, we just need to make sure that the node that will reach it gets popped of
the fringe so we can say that a state has reached optimally.
(d) This statement is false, because when the implementation is incorrect, one of the problems in A, B, or C
will occur.
(e) This state is false, because we have seen that the implementation is incorrect.
13