Class 23CLC – Term II/2024-2025
Course: CSC14003 – Artificial Intelligence
Homework 01
Submission Notices:
● Conduct your homework by filling answers into the placeholders given in this file (in Microsoft Word format).
Questions are shown in black color, instructions/hints are shown in italic and blue color, and your content
should use any color that is different from those.
● After completing your homework, prepare the file for submission by exporting the Word file (filled with
answers) to a PDF file, whose filename follows the following format,
<StudentID-1>_<StudentID-2>_HW01.pdf (Student IDs are sorted in ascending order)
E.g., 2252001_2252002_HW01.pdf
and then submit the file to Moodle directly WITHOUT any kinds of compression (.zip, .rar, .tar, etc.).
● Note that you will get zero credit for any careless mistake, including, but not limited to, the following things.
1. Wrong file/filename format, e.g., not a pdf file, use “-” instead of “_” for separators, etc.
2. Disorder format of problems and answers
3. Conducted not in English
4. Cheating, i.e., copying other students’ works or let the other student(s) copy your work.
Problem 1 (2pts) Answer the following simple questions.
Questions (0.5pt each) Filling in the blanks
Suppose heuristic value h2 dominates h1 (provided
Assume that there are several heuristics for
that it is consistent). Then using A* with heuristic h2
the same problem. Why is it better to use a
will never expand more nodes than A* with heuristic
heuristic that dominates others?
h1 => better to use a heuristic that dominates others
The temperature function evaluates the probability
when picking a worse move among successors during
What role does the temperature function the search process. The probability decreases as the
play in Simulated Annealing? temperature goes down. The schedule will lower the
temperature T slowly enough to find a global optimum
with the probability approaching 1.
A plateau is a flat area of the state-space landscape. It
What is plateau in local search algorithm? can be a “flat” local maximum (no uphill exit exists)
How does it affect the algorithm? or a shoulder (uphill exit exists). The hill-climbing
search algorithm might get lost on the plateau.
Stochastic hill climbing (a Hill-climbing variant)
behaves similarly to the mutation operator in Genetic
algorithm.
Which Hill-climbing variation behaves
Stochastic hill climbing: chooses randomly among
similarly to the mutation operator in Genetic
uphill moves, with the probability of selection vary
algorithm?
with the steepness of the uphill move.
Genetic algorithm: each location is subject to random
mutation with a small independent probability.
Hint: Please refer to Lecture 2 – P3 for the definition of heuristic dominance.
1
Problem 2 (1pt) Consider two heuristics, ℎ1 and ℎ2. They are both admissible, and ℎ1 dominates ℎ2. Is
it possible to conduct that ℎ1 is a consistent heuristic? Explain your answer by either reasoning or
visualization.
Hint: Please refer to Lecture 2 – P3 for the definition of heuristic dominance.
Admissible heuristics ℎ1 , ℎ2 and ℎ1 dominating ℎ2 are not enough data to conclude that ℎ1 is a
consistent heuristic. Because the domination only indicates that ℎ1(𝑛) >= ℎ2(𝑛), for all node n, it does
not ensure the consistency of the heuristic function (cannot prove that it will obey the triangle
inequality). Here’s an example of a graph with two admissible heuristics ℎ1 , ℎ2 (ℎ1 dominates ℎ2)
and ℎ1 is inconsistent.
From the graph above, we see that both ℎ1, ℎ2 are admissible heuristics and ℎ1 dominates ℎ2. But for
node A and C, ℎ1(A) = 7 > ℎ1(C) + 3 = 5 and C is the successor of A, which violates the
consistency of the heuristics function. Thus, ℎ1 cannot be concluded as a consistent heuristic.
Problem 3 (2.5pts) Starting from city A we want to find the shortest path to city S (goal). The labels on
the links show the distance between the cities. The coordinate of each city is available beside the nodes.
To estimate the distance from a city to the goal, we use the city block distance, i.e., the distance between
X(a, b) and Y(c, d) is |a-c|+|b-d|.
2
For each of the following search strategies, work out the order in which states are expanded, as well as
the path returned. In all cases, assume ties resolve in such a way that states with earlier alphabetical
order are expanded first.
a) Breadth-first search
b) Uniform-cost search
c) Tree-search depth-first search (which avoid loops by checking new states against those on the
path from the root to the current node)
d) Greedy best-first search
e) Graph-search A*
Note that
● A state is expanded at most once in graph search, while it may be expanded more than once in
tree search.
● Tree-search DFS avoids repeated states by checking new states against those on the path from
the root to the current node.
● For DFS, BFS, and GBFS, the goal test is applied to each node when it is generated rather than
when it is selected for expansion.
● In each algorithm, the list of expanded states gives 0.25pt and the return path gives 0.25pt. 0pt if
the list of expanded states is wrong.
● It is optional to include the goal state in the list of expanded states for BFS, DFS, IDS, and
GBFS (because these ignores the cost). However, it is mandatory for UCS and A*.
g(n): Actual cost from node A (initial state) to node n
h(n): heuristic function that estimates the cost from node n to node S (goal state)
g(n) 0 50 90 80 110 120 130 195 160 190 235 185
h(n) 200 170 120 150 110 80 130 80 40 90 60 0
n A B C D E F G H M N P S
3
Algorithm Expanded states Returned path
BFS A-B-D-C-E-G-F-H-N-M-P A-B-C-F-M-S
UCS A-B-D-C-E-F-G-M-S A-B-C-F-M-S
DFS A-B-C-E-D-G-H-P-N-F-M A-B-C-F-M-S
GBFS A-D-E-C-F-M A-D-E-C-F-M-S
A* A-B-C-F-M-S A-B-C-F-M-S
Problem 4. (1.5pts) The wolf, goat, and cabbage problem. Once upon a time a farmer went to a market
and purchased a wolf, a goat, and a cabbage. On his way home, the farmer came to the bank of a river
and rented a boat. But crossing the river by boat, the farmer could carry only himself and one of his
purchases: the wolf, the goat, or the cabbage. If left unattended together, the wolf would eat the goat, or
the goat would eat the cabbage. The farmer's challenge was to carry himself and his purchases to the far
bank of the river, leaving each purchase intact.
Formulate the above problem as a search problem by answering the following questions.
● How do you represent a state? That is, which elements are included in a single state and what is the
range of value for each element? (0.5pt)
- Represent the Wolf by W, the Goat by G, the Cabbage by C, the Farm by F.
Side1 {W, G, C, F} Side2 {}
● What is the upper bound for the number of states in the state space? Justify your answer. (0.5pt)
There are 24 states in the state space. Because there are 4 factors, and 2 sides of the river.
● Draw a directed acyclic graph (DAG) of the state space. Mark the optimal solution. (0.5pt)
4
5
Problem 5. (1.5pts) The 8-puzzle problem. Apply Hill-climbing algorithm with Manhattan distance
heuristic to find a solution for the following pair of initial and goal states.
Initial Goal state
state 1 2 3 1 2 3
7 6 4 5 6
5 4 8 7 8
Your work should address the following requirements
- Draw the search tree including all possible successors of expanded states (except the goal).
- Calculate the heuristic value for every node
- Mark the optimal strategy found
Note that there will be ties at some steps. The hill-climbing search may be stuck after a few moves if it
follows an unpromising branch, yet it theoretically has no way to predict this. Let assume that our
search is “smart” enough to pick the correct one among ties.
Each incorrect/missing state gives -0.25pt. No optimal strategy marked: -0.5pt.
States on the optimal path are marked in yellow color and bolded font.
6
Problem 6. (1.5pts) The pancake problem. We are given a stack of N pancakes, each of different size.
Our goal is to sort this stack from smallest to largest (largest being on the bottom of the stack). The only
thing we are allowed to do is to insert the spatula in between two pancakes (or between the bottom
pancake and the plate) and flip over all the pancakes that are on top of the spatula.
Formulate the above problem as a search problem by answering the following questions.
● Consider a state as a tuple of values. Which values should be included in the tuple? (0.5pt)
7
Let’s consider M shows the state of pancakes in position. M has an arrangement: P1, P2,…PN which
shows that the pancake with size Pi is at position i.
Example: M {4, 2, 1, 3, 5}
Pancake 4 is at position 1 (bottom)
Pancake 2 is at position 2
….
Pancake 5 is at position 5 (top)
From this point, answer the following questions according to the definition of a state above.
● Define the initial state and the goal state. (0.25pt)
- Initial state: Any state can be designated as the initial state.
- Goal state: stack of N pancakes that is sorted from smallest to largest (largest being on the bottom of
the stack).
Goal state {5, 4, 3, 2, 1}
● How many states are there in the state space? Justify your answer. (0.25pt)
There are N! states. Because all pancakes are of different sizes and there are n possible positions for
each, thus there are total N! permutations as well as N! states.
● Define the successor function. (0.25pt)
- A set of pancake can be moved from current state M to new state M’ if:
+ The spatula is in between two pancakes (or between the bottom pancake and the plate).
+ Flip over all the pancakes that are on top of the spatula.
● What is path cost? (0.25pt)
- Each move has a unit cost.