Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

Sam's 2025-CS420-ReviewExercisesForMidterm-22TT2

Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Course: CS420 - Artificial Intelligence

Class 22CTT – Term I/2024-2025

MIDTERM EXAMINATION REVIEW

Q1. The three couples problem. Three couples are on safari, when they come to a river. The only way
for them to cross is with a small rowboat which can only accommodate two people at a time.
Complicating the process is the fact that the women are all the jealous type and refuse to leave their
significant other in the presence of another woman unless she is there as well. How can the couples
cross the river without any romantic strife?
Consider a state as a tuple of values. Which values should be included in the tuple?

(mA_pos, wA_pos, mB_pos, wB_pos, mC_pos, wC_pos, boat_pos) in which the value of each
element can only be L (he/she is on the left side of the river) or R (he/she is on the right
side of the river)

From this point, answer the following questions according to the definition of a state above.

Define the initial state and the goal state.

Initial state: (L,L,L,L,L,L,L)


Goal state: (R,R,R,R,R,R,R)

What is the path cost?

How insane is this question??? I don’t even know whether it has a solution or not.
Path cost = the minimum number of boat crossings required to go from initial state to the goal
state while satisfying the given constraints = 9

((R,L),(R,L),(L,L),R)
((L,L),(R,L),(L,L),L)
((R,R),(R,L),(L,L),R): illegal
((R,R),(L,L),(L,L),L)
((R,R),(R,R),(L,L),R)
((R,R),(R,L),(L,L),L)
((R,R),(R,R),(L,R),R)
((R,R),(R,R),(L,L),L)
((R,R),(R,R),(R,R),R)

What is the maximum number of states in the state space, i.e., including illegal states? Explain.
Each element of a state tuple has 2 choices (L or R). We independently choose for each
element of a state tuple then the maximum number of states in the state space, including
illegal states is 2^7 = 128, which are all possible combinations of positions for each
individual and the boat

Q2. Consider the following graph. The


initial state is marked with a BLUE
circle, and the goal state is marked
with a RED circle. Ties are broken in
alphabetical order.

For each of the following search strategies, state the order in which states are expanded and the path
returned. Vertices should be presented in their exact order.
Note that the path returned will not be accepted if the list of expanded states is wrong.
We assume that DFS, BFS, GBFS follows early-goal test

Algorithms List of expanded states Path returned

Breadth-first search A, B, F, C, D, G, H, E A-B-C-E-J

Uniform cost search A, F, G, B, I, D, C, H, J A-F-G-I-J


Depth-first search A, B, C, D, E A-B-C-D-E-J

Greedy best-first search A, F, H, I A-F-H-I-J

Graph-search A* A, F, G, I, J A-F-G-I-J

Q3. Consider the 8-puzzle problem. Apply the hill-climbing algorithm with Manhattan distance
heuristic to find a solution for the following pair of initial and goal states.

Initial state 2 8 3 Goal state 1 2 3

1 6 4 8 - 4

7 - 5 7 6 5

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
We assume hill-climbing does track the visited states to avoid redundant moves
Q4. Consider the 4-bishops problem. Every state of the problem has 4
bishops on the board, each of which is in a separate column.

Answer the following questions:

What is the total number of states in the state space? Explain.


For each of the 4 bishops in each of the 4 columns, there are 4 choices since we independently
choose a row for a bishop. Thus, the total number of states in the state space is 4*4*4*4 = 256

Each step of the search moves a bishop within its own column. How many successors can a state
generate? Explain.
My question is do we need to consider how a bishop moves or just simply place a bishop within its
owns column???

Since a bishop occupies one row out of four, each bishop has 3 possible moves within its own
column. Therefore, the number of successors a state can generate is 3*4 =12

Each state of the problem can be represented in the genetic algorithm as 4 digits, each indicating the
position of a bishop in that column. For example, S = 4213.
Let nb be the number of attacking pairs of bishops of state n.
Define the fitness function for a state n:

The higher value the fitness function returns, the better state

N = the number of non-attacking pairs of bishops = 4C2 - n_b = 6 - n_b

The current generation includes 4 states: S1 = 2341; S2 = 2132; S3 = 1232; S4 = 4321.


Calculate the value of Fit(n) for each of the 4 states and the probability that each of them will be
chosen in the “selection” step.

State n S1 S2 S3 S4

Fit(n) 2 4 2 0

Prob(n) 25% 50% 25% 0%

Q5. Consider the following game tree. Assume that the root node corresponds to the MAX player and
the search always visits children left-to-right.
Compute the minimax values at every intermediate node. (No alpha-beta pruning at this step)
A B C D E F G

5 5 3 5 13 3 10
Compute the minimax values at every intermediate node using alpha-beta pruning. If a node is
pruned, mark X.
A B C D E F G

5 5 3 5 9 3 x
Using the minimax calculations from part a), without performing any alpha-beta calculation, rotate
the children of each node in the above tree at every level to ensure maximum alpha-beta pruning.
Fill in the nodes with the letter of the corresponding node. Draw the new edges.

To maximize alpha-beta pruning, we should reorder children at each level from the highest to
lowest values for MAX nodes and from lowest to highest for MIN nodes. This reordering can
potentially reduce the number of nodes the algorithm needs to evaluate.

We should reorder from top to bottom since each node has its own subtree.

Final Tree Structure with reordered nodes


Q6. This problem asks about the Map coloring problem. Each
region must be colored one of Red (R), Green (G), or Blue (B).
Neighboring regions must be of different colors.
Note that the following questions are mutually independent.

Cross out all values that would be eliminated by Forward Checking, after variable B has been
assigned as shown.
A B C D E F
R G B R R G B R G B R G B R G B

A and B have been assigned values as shown, but no constraint propagation has been done. Cross
out all values that would be eliminated by Arc Consistency AC-3.
A B C D E F

R G R G B R G B R G B R G B

Variable A is already assigned, and constraint propagation has been done. Circle all unassigned
variables that might be selected by the Minimum-Remaining-Values (MRV) Heuristic.
A B C D E F

R G B RG B G B R G B R G B

Variable A is already assigned, and constraint propagation has been done. Circle all unassigned
variables that might be selected by the Degree Heuristic.
A B C D E F

R G B RG B G B R G B R G B

Assume no variables have been assigned yet, solve the CSP using backtracking with forward
checking. Ties (after considering all necessary heuristics) are resolved by lexicographical order.
Note: for every step, present the MRV values for all regions that are not colored yet. If there are many
regions that have the same minimum MRV, present the DH values for these regions.

Step 1

Variables A B C D E F

MRV 3 3 3 3 3 3
DH 2 4 3 3 4 2
Assign to the variable ___________B_________ with the value ____________R__________________

Step 2

Variables A B C D E F

MRV 2 2 2 2 3
DH 1 2 2 3
Assign to the variable ____________E________ with the value ____________G__________________
Step 3

Variables A B C D E F

MRV 2 1 1 2
DH 1 1
Assign to the variable __________C__________ with the value _____________B_________________

Step 4

Variables A B C D E F

MRV 2 1 1
DH 1 0
Assign to the variable _________D___________ with the value ___________B____________________

Step 5

Variables A B C D E F

MRV 1 1
DH 0 0
Assign to the variable __________A__________ with the value _____________G_________________

Step 6

Assign to the variable __________F__________ with the value ________________R_____________

Q7. You wake up early in the morning, full of excitement and anticipation, so you decide to dress up
very specially. After a while you have narrowed down the choices for each of the four items of
clothing, (H)eadwear, (B)odywear, (L)egwear, and (A)ccessory as follows:
● H ∈ { hat, cap }
● B ∈ { shirt, blouse, jumper }
● L ∈ { leggings, skirt, trousers }
● A ∈ { scarf, tie, cravat }
Furthermore, you have derived the following constraints:
(1) If you choose the jumper, the cap is the only matching headwear.
(2) The leggings do not go together with the hat.
(3) If you wear a shirt or a blouse, then you have to take a tie or a cravat.

Formulate the problem as a CSP, stating the variables and corresponding domains.
Variables A B L H

Domains sc,ti,cr sh,bl,ju l,sk,tr h,c

Binary constraints:

B-H H-L A-B

Draw the constraint graph associated with your CSP,


in which each node represents a variable and an
edge connecting two nodes represents the relation
between the two variables denoted by these nodes.

Now, assume that you decide to take the hat. What can you deduce about your other clothing? Cross
out eliminated values to show the domains of the variables after arc consistency has been enforced.
Variables A B L H

Domains Sc, ti, cr Sh ,bl, ju L, sk, tr H, c

You might also like