Professional Documents
Culture Documents
(1) To define the states, we denote the number of missionaries, cannibals, and boat on the left side of
the river by an array (m, c, b). Correspondingly, the number of missionaries, cannibals, and boat
on the other side of the river are given by 3 − m, 3 − c, and 1 − b.
(2) The initial state then can be denoted by (3, 3, 1), i.e., three missionaries, three cannibals and one
boat are on the left side of the river.
(3) The goal state is defined by (0, 0, 0), i.e., all missionaries, cannibals and the boat are on the other
side of the river.
(4) We use pq to denote an action of moving p missionaries and q cannibals across the river and use
symbols B and C to denote the direction of moving people. The all possible actions can be given
by: 01B, 02B, 10B, 11B, 20B, 01C, 02C, 10C, 11C, and 20C.
Q2: Five example states are: (3, 3, 1), (0, 0, 0), (3, 2, 1), (2, 2, 1), (0, 2, 0). For the state (0, 2, 0), the
results of applying the successor function are:
• BFS or uniform-cost search as they both guarantee a cost-optimal solution in this case since all
actions cost the same.
• Iterative deepening search as it saves memory and guarantees to find the a solution.
2 3
4 5 6 7
8 9 10 11 12 13 14 15
1
Q2: The order of visited nodes are as follows:
Q3: The iterative deepening search is the best algorithm to use. First, the state space is infinite, DFS
could go deep in a wrong branch and does not have a chance to find the solution. BFS is too space-
expensive.
A A A
B C K B C K B K C
D P L H D P L H H L D P
Q G Q G G
or or
Some examples of correct orders of nodes expanded are (The answer must align with the search tree
plotted):
Q2: We use uniform-cost search as it fins the cost-optimal solution. In this problem, the cheapest
flight corresponds to the cost-optimal solution when we consider the price as the cost. The search tree
constructed is:
B K C
H L C D P
G Q
2
Problem 4: Heuristic Search
Q1: h1 is admissible because for each misplaced number, it requires at least one step to recover it. So
h1 will not be larger than the actual cost for all states. h2 is also admissible because for each misplaced
tile, the minimum number to move it to the correct place is the Manhattan distance (since the tile can
only move horizontally and vertically) between its current location and the goal location. Since there are
other numbers blocking this shortest way, it will always take steps no less than the Manhattan distance.
Therefore, h2 will never overestimate the actual cost.
Q2: h2 is a better heuristic function as it is a more accurate estimation of the cost from each state to the
goal state. It is always grater than or equal to h1 yet still admissible.
7 2 4
(0) 7 2 4
5 0 6 (0)
8 3 1
5 0 6
step 1: 8 3 1
step 1:
7 2 4 7 0 4 7 2 4 7 2 4
0 5 6 5 2 6 5 6 0 5 3 6 7 2 4 7 0 4 7 2 4 7 2 4
8 3 1 8 3 1 8 3 1 8 0 1 0 5 6 5 2 6 5 6 0 5 3 6
(1) (2) (3) (4) 8 3 1 8 3 1 8 3 1 8 0 1
(1) 1+17 (2) 2+19 (3) 3+17 (4) 4+17
step 2:
0 2 4 7 2 4 step 2: step 4:
7 5 6 8 5 6
8 3 1 0 3 1 0 2 4 7 2 4 7 2 0 7 2 4
(5) (6) 7 5 6 8 5 6 5 6 4 5 6 1
8 3 1 0 3 1 8 3 1 8 3 0
step 3:
(5) 3+16 (6) 5+18 (8) 5+17 (9) 7+16
2 0 4
7 5 6 step 3:
8 3 1
2 0 4
(7)
7 5 6
step 4: 8 3 1
2 5 4 2 4 0 (7) 5+17
7 0 6 7 5 6
8 3 1 8 3 1
(b) A* Search. The numbers underneath each state are in
(8) (9)
the format of g(n) + h2 (n), where g is the cost and h2 is
(a) Greedy Search the heuristic function.
Figure 1: An example of the portion of the search tree after the first four steps using greedy search and
A* search.
Q3: The resulting portion of the search tree is shown in Fig. 1a. In the first step, (0) is expanded because
it is the only node in the frontiers. In the second step, (1), (3), and (4) have the smallest heuristic function
h2 , so we randomly choose one to expand. In this example solution, we expand (1). In the third step,
(5) is the node with smallest h2 , so we expand (5). In the fourth step, (3), (4), and (7) all have the same
smallest h2 , so we randomly choose one. In this example solution, we expand (7).
Q4: The resulting portion of the search tree is shown in Fig. 1b. The numbers underneath each state are
in the format of g(n) + h2 (n), where g is the cost and h2 is the heuristic function. In the first step, (0) is
expanded because it is the only node in the frontiers. In the second step, (1) has the smallest g +h2 = 18,
so we expand (1). In the third step, (5) has the smallest g + h2 = 19, so we expand (5). In the fourth
step, (3) has the smallest g + h2 = 20, so we expand (3).