You are on page 1of 28

Midterm II

Solution
Prof. Mohamed Batouche

Department of Computer Science
CCIS King Saud University
Saudi Arabia
Question 1
Solve the 8-puzzle problem using
IDA* with h1() heuristic:





Operators: slide-blank-up, slide-
blank-down, slide-blank-right, slide-
blank-left. Operators should be
applied in this order.
5 7
4 6 1
3 8 2
5 6 7
4 8
3 2 1
5 7
4 6 1
3 8 2
0+5=5
Cutoff = 5
Use DFS
5 7
4 6 1
3 8 2
5 7
4 6
1
3 8 2
0+5=5
1+5=6
Cutoff = 5
up
5 7
4 6 1
3 8 2
5 7
4 6
1
3 8 2
5
7
4 6 1
3 8 2
0+5=5
1+5=6
Cutoff = 5
1+4=5
up right
5 7
4 6 1
3 8 2
5 7
4 6
1
3 8 2
5
7
4 6 1
3 8 2
5
7
4
6
1
3 8 2
0+5=5
1+5=6
Cutoff = 5
1+4=5
2+3=5
up
up
right
5 7
4 6 1
3 8 2
5 7
4 6
1
3 8 2
5
7
4 6 1
3 8 2
5
7
4
6
1
3 8 2
5
7
4
6
1
3
8
2
0+5=5
1+5=6
Cutoff = 5
1+4=5
2+3=5
3+3=6
up
up
up
right
5 7
4 6 1
3 8 2
5 7
4 6
1
3 8 2
5
7
4 6 1
3 8 2
5
7
4
6
1
3 8 2
5
7

4
6
1
3 8 2
5
7
4
6
1
3
8
2
0+5=5
1+5=6
Cutoff = 5
1+4=5
2+3=5
3+3=6 3+4=7
up
up
up
right
right
5 7
4 6 1
3 8 2
5 7
4 6
1
3 8 2
5
7
4 6 1
3 8 2
5
7
4
6
1
3 8 2
5
7

4
6
1
3 8 2
5
7
4
6
1
3
8
2
5
7
4

6
1
3 8 2
0+5=5
1+5=6
Cutoff = 5
1+4=5
2+3=5
3+3=6
3+3=6
3+4=7
up
up
up
right
right
left
5 7
4 6 1
3 8 2
5 7
4 6
1
3 8 2
5
7
4 6 1
3 8 2
5 7
4 6 1
3 8 2
5
7
4
6
1
3 8 2
5
7

4
6
1
3 8 2
5
7
4
6
1
3
8
2
5
7
4

6
1
3 8 2
0+5=5
1+5=6
Cutoff = 5
1+4=5
2+3=5 2+5=7
3+3=6
3+3=6
3+4=7
up
up
up
right
right
right
left
5 7
4 6 1
3 8 2
5 7
4 6
1
3 8 2
5
7
4 6 1
3 8 2
5 7
4 6 1
3 8 2
5
7
4
6
1
3 8 2
5
7

4
6
1
3 8 2
5
7
4
6
1
3
8
2
5
7
4

6
1
3 8 2
0+5=5
1+5=6
Cutoff = 5
1+4=5
2+3=5 2+5=7
3+3=6
3+3=6
3+4=7
Failure: Change cutoff min(f(leaves)) = 6
up
up
up
right
right
right
left
5 7
4 6 1
3 8 2
0+5=5
Cutoff = 6
Use DFS
5 7
4 6 1
3 8 2
5 7
4 6
1
3 8 2
0+5=5
1+5=6
Cutoff = 6
up
5 7
4 6 1
3 8 2
5 7
4 6
1
3 8 2
0+5=5
1+5=6
Cutoff = 6
up
5 7
4 6
1
3 8
2
2+5=7
up
5 7
4 6 1
3 8 2
5 7
4 6
1
3 8 2
0+5=5
1+5=6
Cutoff = 6
up
5 7
4 6
1
3 8
2
5 7
4 6
1
3 8 2
2+5=7 2+5=7
up
right
5 7
4 6 1
3 8 2
5 7
4 6
1
3 8 2
5
7
4 6 1
3 8 2
0+5=5
1+5=6
Cutoff = 6
1+4=5
up right
5 7
4 6
1
3 8
2
5 7
4 6
1
3 8 2
2+5=7 2+5=7
up
right
5 7
4 6 1
3 8 2
5 7
4 6
1
3 8 2
5
7
4 6 1
3 8 2
5
7
4
6
1
3 8 2
0+5=5
1+5=6
Cutoff = 6
1+4=5
2+3=5
up
up
right
5 7
4 6
1
3 8
2
5 7
4 6
1
3 8 2
2+5=7 2+5=7
up
right
5 7
4 6 1
3 8 2
5 7
4 6
1
3 8 2
5
7
4 6 1
3 8 2
5
7
4
6
1
3 8 2
5
7
4
6
1
3
8
2
0+5=5
1+5=6
Cutoff = 6
1+4=5
2+3=5
3+3=6
up
up
up
right
5 7
4 6
1
3 8
2
5 7
4 6
1
3 8 2
2+5=7 2+5=7
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0+5=5
1+5=6
Cutoff = 6
1+4=5
2+3=5
3+3=6
up
up
up
right
5 7
4 6
1
3 8
2
5 7
4 6
1
3 8 2
2+5=7 2+5=7
up
right
5
7
4
6
1
3
8
2
5
7
4
6
1
3
8
2
right
left
5
7
4
6
1 3
8
2
down
5
7
4
6
1 3
8
2
down
right
5 6 7
4 8
3 2 1
4+4=8
4+2=6
5+1=6
6+2=8
Goal !!
Question 2
Explain the way to use hill
climbing for map coloring:

How to start:
Start with random solution: assign
randomly colors to regions

How to improve current solution
Select the best solution (minconflicts)
in the neighborhood obtained by
modifying region color.

When to stop:
Stop when the next solution is not
better than current solution (local
minimum)

Question 3
Consider the following map. The task is to color
the map using the four colors blue, green, red,
and yellow such that no two adjacent regions take
the same color.





Color the map using Backtracking Search with
MCV. Show the steps. The values should be
selected according to alphabetical order: (blue,
green, red, yellow)
1
4
2
3 6
5


Question 3
Solution


1
4
2
3 6
5
Order of variable selection using MCV (select first
the variable with most constraints on remaining
variables):
2, 1, 3, 5, 4, 6
Question 4
Consider the problem of Sudoku where:
No value appears twice in the same row.
No value appears twice in the same column.
No value appears twice in the same block
(22 block).
v
1
3 V
2
1
v3 1 V
4
4
3 4 1 2
v
5
V
6
4 V
7

Solve this problem using Backtracking with Arc
Consistency
Question 4
Solution
v
1

v
7
v
6
v
5

v
4
v
3

v
2








{2}
{4}
{2}
{1}
{2}
{3}
{3}
4 3 2 1
2 1 3 4
3 4 1 2
1 2
4
3

You might also like