cs188 sp24 Midterm Solutions
cs188 sp24 Midterm Solutions
First name
Last name
SID
Honor code: “As a member of the UC Berkeley community, I act with honesty, integrity, and respect for others.”
By signing below, I affirm that all work on this exam is my own work, and honestly reflects my own understanding of
the course material. I have not referenced any outside materials (other than my cheat sheets), nor collaborated with any
other human being on this exam. I understand that if the exam proctor catches me cheating on the exam, that I may face
the penalty of an automatic "F" grade in this class and a referral to the Center for Student Conduct.
Signature:
1
Q1. [12 pts] Potpourri
In the next two subparts, consider a search problem with maximum branching factor of 𝑏, and maximum search tree depth of 𝑚
(i.e. the search tree is finite).
(a) [1 pt] What is the space complexity (maximum number of nodes on the fringe at any given time) for breadth-first tree
search?
In the worst case, breadth-first search needs to keep all the search nodes on the current layer of the search tree on the
fringe (after dequeueing everything at layer 𝑚 − 1 and enqueueing everything at layer 𝑚).
At the bottom layer 𝑚, there are 𝑂(𝑏𝑚 ) nodes that could potentially all be on the queue at the same time.
(b) [1 pt] What is the time complexity (maximum number of nodes explored in the worst case) for depth-first tree search?
In the worst case, we may need to explore the entire tree before finding a solution. The tree contains roughly 1 + 𝑏 + 𝑏2 +
… + 𝑏𝑚 = 𝑂(𝑏𝑚 ) search nodes.
In the next three subparts, consider a search problem with a finite state space. Suppose we have an admissible heuristic function
ℎ1 (𝑛), a consistent heuristic function ℎ2 (𝑛), and a heuristic function ℎ3 (𝑛) = max(ℎ1 (𝑛), ℎ2 (𝑛)).
(c) [2 pts] Select all heuristics that will guarantee that A* graph search (used with that heuristic) will return the optimal
solution.
For A* graph search to be optimal, we need to use a consistent heuristic: ℎ2 (𝑛). ℎ1 (𝑛) is admissible, but this does not
imply that it is consistent. We can find a counterexample where ℎ3 (𝑛) is admissible, but not consistent. Suppose that
ℎ1 (𝑛) is admissible but not consistent and ℎ2 (𝑛) = 0. Thus, ℎ3 (𝑛) = max(ℎ1 (𝑛), 0) = ℎ1 (𝑛), which means that ℎ3 (𝑛) is not
consistent.
(d) [2 pts] Select all heuristics that will guarantee that A* tree search (used with that heuristic) will return the optimal solution.
For A* tree search to be optimal, we need to use an admissible heuristic. ℎ1 (𝑛) is admissible, ℎ2 (𝑛) is consistent, which
implies admissibility, and we can show ℎ3 (𝑛) is admissible. Since ℎ1 (𝑛) and ℎ2 (𝑛) are admissible (consistency implies
admissibility), then we know that
and,
0 ≤ ℎ2 (𝑛) ≤ ℎ∗ (𝑛) (2)
Where ℎ∗ (𝑛) is the true heuristic. Using equation (1) and (2), we get
2
■ 𝐴∗ graph search is optimal if the heuristic function used is consistent.
# None of the above
Option (A): A* tree search can be suboptimal with an non-admissible heuristic.
Option (B): A* graph search is only optimal if the heuristic is consistent, which is a stricter criterion than admissibility.
Option (C): See Option (B)’s explanation.
(f) [2 pts] In the context of Monte Carlo Tree Search (MCTS), when are nodes likely to be visited more frequently during the
search process? Select all that apply.
□ Nodes that have a lower win rate, as the algorithm seeks to explore less successful paths more thoroughly.
■ Nodes that have a higher win rate, as the algorithm prioritizes paths with a higher probability of success.
■ Nodes that have fewer rollouts, as the algorithm prioritizes exploration.
□ Nodes at the deepest level of the tree, as the algorithm focuses on fully exploring the end.
# None of the above
In MCTS, we want to allocate rollouts to nodes that have a higher win rate (Option (B)) or more uncertainty ((Option (C))
(refer to slide 55 and 56 in lecture 6). Option (A) contradicts our strategy of maximizing our success under uncertainty.
In many problems we apply MCTS, there are many ending states (like the board game Go), and it would be intractable to
explore all of them. This means that many of the nodes at the deepst level end up not being searched (Option (D)). MCTS
allows us to search the state space intelligently, so we do not have to look at every leaf node.
(g) [2 pts] Which of these scenarios would be most appropriate for a Hidden Markov Model (HMM) setup?
# You receive daily reports of “sun” or “no sun.” You know the probability of sun only depends on whether there
was sun the previous day. You want to estimate the probability of sun on future days.
You receive daily reports of a patient’s symptoms, but cannot directly observe the state of the patient’s disease.
You know how the disease causes the symptoms, and you know that the state of the disease on a given day only
depends on the state of the disease on the previous day. You want to estimate the probability of disease on each day.
# You receive the exact location of a vehicle every minute. You control the vehicle, and you want to guide the
vehicle to its destination.
Option (A) is false because there is no hidden variable. This can be represented with a Markov model, where you directly
observe the variable you are trying to predict (sun or no sun).
Option (B) is true. You cannot directly observe the query variable (disease), but you can observe evidence (symptoms),
and you know how the disease causes the symptoms. Also, you have the Markov assumption that the probability of disease
on a given day only depends on the state of the disease on the previous day. Therefore, an HMM would be a good choice
here.
Option (C) is false. HMMs are used for reasoning over an uncertain query variable. There is no notion of taking actions
or reaching a goal in an HMM.
3
Q2. [17 pts] Search: Half the Dots
Recall the “All-the-Dots” problem from Project 1. Here are some reminders of Pacman rules: Pacman lives in an 𝑀 by 𝑁 grid.
He can move up, down, left, or right, but he is not allowed to take actions that move into a wall. Walls may exist throughout the
grid, but the locations of the walls do not change for the entire problem. In the starting state, there are 𝐾 dots throughout the
grid. Pacman’s goal in Project 1 was to eat all 𝐾 dots.
In this question, Pacman has built a spaceship and has landed on a new world, Earth Prime (also an 𝑀 by 𝑁 grid), with 𝐾 dots.
For this entire question, you can assume that 𝑀, 𝑁, and 𝐾 are fixed, and you can assume that 𝐾 is even. Pacman’s new goal
is to solve the “Half-the-Dots” search problem and eat any 𝐾∕2 dots!
(a) [2 pts] Select all pieces of information that should be part of a minimal state representation.
Note: In other words, all the options you select should, together, form the smallest valid state representation. Consider
only space complexity (do not consider time complexity).
□ Coordinates of Pacman’s starting position.
■ Coordinates of Pacman’s current position.
□ A boolean matrix with the dots’ starting positions.
■ A boolean matrix indicating which dots have not been eaten.
□ A boolean matrix indicating where Pacman has visited.
In general, we require Pacman’s current position, as well as a way to track where the dots are. (B) and (D) together provide
a minimal state representation, by tracking these two things.
Since we don’t require Pacman’s starting position or the dots starting position, answer choices (A) and (C) are incorrect.
Answer choice (E) is also not useful for this search problem; we only need to eat all the dots, not something like visit
every square.
For the rest of the question, assume that Pacman’s state representation is an 𝑀 by 𝑁 matrix of integers, where the integers
are interpreted as follows: 0 indicates an empty square, 1 indicates a wall is present, 2 indicates that Pacman is present, and 3
indicates that a dot is present.
(b) [2 pts] Suppose Pacman implements a goal test, 𝐺(𝑠). This function takes in a state (and no other information about the
problem), and returns whether this state passes the goal test.
What is the time complexity (in big 𝑂 notation) of 𝐺(𝑠), in terms of 𝑀, 𝑁, and 𝐾? Assume the function is optimal
(written to be as fast as possible).
( )
𝑂
𝑂(𝑀𝑁), because you have to iterate over the entire matrix to count how many dots remain; ie. count how many 3’s are
in the state representation. If this number is less than 𝐾∕2, then the goal test returns True; otherwise, return False.
Given the state representation above, there is no other way to directly count how many dots there are without iterating
through the entire matrix, which has size 𝑀 by 𝑁.
(c) [2 pts] Blinky thinks that Pacman’s state representation is inefficient, and suggests adding this variable to the state space:
𝑅 = the number of remaining dots Pacman needs to eat to solve the problem.
Select all true statements about Blinky’s modified problem.
□ The original successor function, with no modifications, can output successor states for the modified problem.
■ The logic of the original goal test can still be used for the modified problem.
□Running BFS (with all necessary modifications made) will explore fewer search nodes, compared to the un-
modified problem.
□ If we only count valid, reachable states, the size of the state space will increase by a factor of 𝑅.
# None of the above
4
The key realization in this problem is that 𝑅 is a redundant variable. 𝑅 does not change the search problem; it only changes
the representation of the search problem.
Option (A) is false. The successor function now needs to update 𝑅 when generating successor states as well.
Option (B) is true. The original goal test of checking the 𝑁 × 𝑀 grid for 𝐾∕2 (or fewer) dots remaining is still valid,
even if there is an extra variable that could make computation faster (as seen in the next subpart).
Option (C) is false. Intuitively, we are solving the exact same search problem (just with a redundant variable added to the
state space), so we should end up exploring the exact same set of search nodes.
Option (D) is false. The number of states is still the same; every state just has an extra counter 𝑅 attached. You might
be tempted to argue that the state space expands by a factor of 𝑅, but remember that each state in the original problem
only has one valid corresponding state in the modified problem (the state where the 𝑅 value matches the number of dots
left on the grid). For example, you can’t have a state where there are 5 dots left on the grid, but 𝑅 = 6. This state is not
reachable, and the question asks to only count valid, reachable states.
(d) [2 pts] With Blinky’s modification, what is the time complexity of the goal test function? Assume the function is optimal
(written to be as fast as possible).
( )
𝑂
𝑂(1), because you can read off 𝑅. This takes the same amount of time, no matter how large the grid is. 𝑂(log 𝑅), the
number of bits in 𝑅 is also acceptable.
5
(e) [3 pts] Suppose we have an arbitrary admissible heuristic ℎ(𝑠) for the All-the-Dots problem. Select all heuristics that are
guaranteed to be admissible for the Half-the-Dots problem.
□ ℎ(𝑠)
□ 12 ℎ(𝑠)
□ 12 𝑐𝑜𝑠𝑡(𝑠), where 𝑐𝑜𝑠𝑡(𝑠) is the cost of the optimal solution to the All-the-Dots problem from state 𝑠.
□ Half of the currently remaining number of dots.
■ The number of remaining dots that need to be eaten for 𝐾∕2 dots to be eaten in total.
# None of the above
For answer choices (A) through (E), consider that the heuristic ℎ(𝑠) = ℎ∗𝑎𝑙𝑙 (𝑠), the true cost for the All-the-Dots problem.
(A), (B), (C) will all overestimate the goal. Consider the following counterexample:
𝑃
Here, the optimal cost for the All-the-Dots problem is 5: going left, then going right. The optimal cost of the Half-the-Dots
problem is 1. We see here that ℎ(𝑠) = ℎ∗𝑎𝑙𝑙 (𝑠) overestimates the the goal cost and thus is inadmissible.
(D) is false, because we want half of the total, starting number of dots. Suppose there are 𝐾 = 100 dots in the beginning,
and we have eaten 49, and the last dot is next to us. The true cost is 1, and this heuristic returns 25.5, grossly overestimating
the goal.
(E) is correct as a problem relaxation, where you assume Pacman can teleport to any dot, and he must teleport to half the
dots. It is an example of a heuristic that lower bounds the amount of steps or costs needed to reach the goal.
X: Y:
NOTE: During the exam, we posted the clarification: Q2(f): K is the only variable you can use.
𝑋 = 𝐾∕2, 𝑌 = (𝐾∕2) + 1.
This heuristic is admissible. It represents a problem relaxation, where Pacman only needs to travel to the farthest necessary
dot, and on the way he automatically collects any other necessary dots.
For example, suppose 𝐾 = 10. What this heuristic does is sort the dots in order of distance, and selects the (𝐾∕2) + 1 =
6th dot, which is actually the fifth closest dot. This means that this heuristic prints out the 𝑅th dot to go.
A trivial answer is 𝑋 = 𝐾, 𝑌 = 1, which always returns 0.
For the following subparts, Pacman has a supercomputer, ORACLE, that can instantly compute the optimal solution to a given
“All-the-Dots” search problem. Pacman is still attempting to find an optimal solution to the “Half-the-Dots” problem.
(g) [2 pts] Consider this strategy: At the beginning of the problem, Pacman selects the 𝐾∕2 closest dots by Manhattan distance
and runs ORACLE to find the optimal solution for an “All-the-Dots” problem with only the 𝐾∕2 selected dots (effectively
ignoring the existence of the farther dots).
Will this strategy return an optimal solution to the “Half-the-Dots” problem?
# Yes, because the optimal solution always uses the closest dots to the starting position.
# Yes, because planning the complete path ahead of time is always optimal.
# No, because planning the complete path from the starting position can never be optimal for this problem.
6
No, because the optimal solution does not always use the closest dots to the starting position.
The answer is (D).
It cannot be (A) or (B), because the solution is not guaranteed to be optimal. (C) is false, because it is possible for planning
the complete path from the starting position to be optimal (consider infinite depth minimax).
For why it is not optimal, consider the following counterexample: 𝑃
Here, 𝐾 = 4, and ORACLE will return a solution that goes one step left and two steps right, or one step right and two
steps left. The true optimal solution is to take two steps total, either left or right.
(h) [2 pts] Suppose Pacman uses the method in part (g), but instead as a heuristic to 𝐴∗ search. For a given state, Pacman
calculates 𝑅, the remaining number of dots he needs to eat to reach 𝐾∕2 dots eaten. Then, Pacman runs ORACLE on the
𝑅 closest dots by Manhattan distance. The length of the optimal path returned by ORACLE is used as the heuristic value.
This heuristic is not admissible. Select the counterexample that shows this.
In the grids below, 𝐾 = 4 and 𝑅 = 2. Assume that Pacman breaks ties arbitrarily. 𝑃 marks Pacman’s position.
𝑃 𝑃
#
𝑃
𝑃
# #
The correct answer is option (C), the top right grid. It is the only grid in which the ORACLE solution overestimates the
cost to reach the goal.
(A), top left: ORACLE returns 4, the true cost is 4. Example path for both: Right, Down, Up, Right.
(B), bottom left: ORACLE returns 3, true cost is 3. The path for both: Right, Right, Down.
(C), top right: ORACLE returns 8, using path: Down, Down, Up, Up, Right, Right, Right, Right. However, the true cost
is 5, which is path: Right, Right, Right, Right, Down.
(D), bottom right: ORACLE returns 5, true cost is 5. Example path for both: Right, Right, Right, Down, Down.
7
Q3. [15 pts] Logic: Pacdrone
Pacman needs your help predicting what his drone will do on Mars! Let’s do some first order logic warmup.
Suppose there are many sensors: 𝑆0 , 𝑆1 , 𝑆2 , …. Each sensor is located either on Mars, on Earth, or on the Drone.
If sensor 𝑆𝑖 is present on Mars, on Earth, or on the Drone, then OnMars(𝑆𝑖 ), OnEarth(𝑆𝑖 ), or OnDrone(𝑆𝑖 ) returns True,
respectively. Otherwise, the predicate returns False.
A sensor can disrupt another sensor. Disrupts(𝑆𝑖 , 𝑆𝑗 ) is True if 𝑆𝑖 disrupts 𝑆𝑗 . Note that if 𝑆𝑖 disrupts 𝑆𝑗 , that does not
necessarily mean that 𝑆𝑗 disrupts 𝑆𝑖 .
(a) [2 pts] All sensors on Mars disrupt some sensor that is either on Earth or on the Drone.
□ ∃𝑠𝑎 , OnMars(𝑠𝑎 ) ⟹ ∀𝑠𝑏 , Disrupts(𝑠𝑎 , 𝑠𝑏 ) ∨ OnMars(𝑠𝑏 )
□ ∀𝑠𝑎 , OnMars(𝑠𝑎 ) ⟹ ∀𝑠𝑏 , Disrupts(𝑠𝑎 , 𝑠𝑏 ) ∧ OnMars(𝑠𝑏 )
( )
□ ∃𝑠𝑎 , OnMars(𝑠𝑎 ) ⟹ ∃𝑠𝑏 , Disrupts(𝑠𝑎 , 𝑠𝑏 ) ∨ OnEarth(𝑠𝑏 ) ∨ OnDrone(𝑠𝑏 )
( )
■ ∀𝑠𝑎 , OnMars(𝑠𝑎 ) ⟹ ∃𝑠𝑏 , Disrupts(𝑠𝑎 , 𝑠𝑏 ) ∧ OnEarth(𝑠𝑏 ) ∨ OnDrone(𝑠𝑏 )
# None of the above
Half a point for every box. The correct answer is the fourth statement: For every sensor, if it is on Mars, then there is a
sensor out there that it disrupts, which is on Earth or on the Drone.
The first statement says: There is a sensor out there, that if it is on Mars, then it disrupts non-Martian sensors.
The second statement says: For every sensor, if it is on Mars, they disrupt all other sensors AND all other sensors are on
Mars.
The third statement says: There is a sensor, that if it is on Mars, then there is also another sensor out there that it disrupts,
or that sensor is on Earth or on the Drone.
[ ( ]
( ))
(b) [3 pts] ∀(𝑠𝑎 , 𝑠𝑏 ) (𝑠𝑎 ≠ 𝑠𝑏 ) ⟹ ¬Disrupts(𝑠𝑎 , 𝑠𝑏 ) ∨ OnEarth(𝑠𝑎 ) ∧ OnDrone(𝑠𝑏 )
8
The rest of the problem is independent of the previous subparts.
Pacman tells you that there are four binary environment variables on Mars: Dusty (𝐷), Cloudy (𝐶), Windy (𝑊 ), Sunny (𝑆).
However, we have no access to these values directly. Instead, we observe the truth values of the drone’s logical sensors, which
are logical expressions that consist of the environment variables. For example, if 𝐷 and 𝐶 are true, then the sensor 𝐷 ⟹ 𝐶
returns True. For the next three subparts, select the logical sentence that matches the given sensor description.
# 𝐷 ⟹ 𝑆 # 𝑆 ⟹ 𝐷 # 𝐷∧𝑆 𝐷∨𝑆
# 𝑊 ∨𝐷∨𝐶 # 𝑊 ∧ (𝐷 ∨ 𝐶) 𝑊 ⟹ (𝐷 ∨ 𝐶) # (𝐷 ∨ 𝐶) ⟹ 𝑊
The definition of an implication statement 𝐴 ⟹ 𝐵 matches the English statement "If 𝐴 then 𝐵". In this case, "Mars is
windy" is referred to by 𝑊 , and "dusty or cloudy" can be represented as 𝐷 ∨ 𝐶
# ¬𝑆 ∧ 𝑊 ∧ 𝐷 # ¬𝑆 ∨ 𝑊 ∨ 𝐷 𝑆 ∨ ¬𝑊 ∨ 𝐷 # ¬𝑆 ⟹ (𝑊 ∧𝐷)
9
Now we can help Pacman understand what his Drone will do on Mars. Pacman tells you he outfitted the Drone with three
sensors:
𝛼: ¬𝑆 ⟹ 𝑊 𝛽: 𝑊 ⟹ 𝐶 𝛾: (𝐷 ∧ 𝐶) ∨ 𝑊
Suppose that our sensors currently detect the following: 𝛼 = False, 𝛽 = True, 𝛾 = True.
(i) [2 pts] The Drone decides to land and go into hibernation whenever the following Prime Directive evaluates as True:
Which of the following is the correct Conjunctive Normal Form (CNF) of the Prime Directive?
# (Window ∨ Storm) ⟹ Solar Panel
# Window ∧¬Storm ∧ Solar Panel
# (Window ∧¬Storm) ∨ ¬Solar Panel
(Window ∨ ¬Solar Panel) ∧ (¬Storm ∨ ¬Solar Panel)
The third option is Disjunctive Normal Form, not CNF. CNF is an AND of ORs, while DNF is ORs of ANDs. Here is
the breakdown:
(¬Window ∨ Storm) ⟹ ¬Solar Panel
(¬Window ⟹ ¬Solar Panel) ∧ (Storm ⟹ ¬Solar Panel)
(Window ∨ ¬Solar Panel) ∧ (¬ Storm ∨ ¬Solar Panel)
(j) [2 pts] Pacman has learned some of the environment variables: 𝑆 = False, 𝐷 = False, 𝐶 = unknown, 𝑊 = True.
The Prime Directive evaluates as True. What is the value of 𝐶?
10
# True # False Can’t calculate
Solar Panel evaluates to False, because 𝑆 is False. Window, which is (𝐶 ∧ 𝑊 ) ∨ 𝐷, simplifies to 𝐶. Storm evaluates to 𝐶 as
well, because the left hand side is True; Storm will only be true if the right hand side is also True, which depends on 𝐶.
¬𝐶 ∨ 𝐶 ⟹ ¬𝐹 𝑎𝑙𝑠𝑒
This statement must always be True, because the left hand side is a tautology, and the right hand side is True. Thus, we have no
way to tell what value 𝐶 must be– the answer is Can’t Calculate.
11
Q4. [21 pts] Logic: Transactions
A database system has 3 disks, 𝐴, 𝐵, and 𝐶.
A transaction is a database operation (e.g. reading a file), which requires using one or more disks for one or more consecutive
time steps. At a given time step, a transaction is either running, or not running.
A disk cannot be used by two transactions at the same time. One way to enforce this is to introduce a lock for each disk. You
can think of a lock as an object that can be acquired by a transaction. When a transaction is holding a lock, all other transactions
are unable to acquire that lock (and use the lock’s corresponding disk). The transaction can hold on to the lock for as long as
needed. Once the transaction is finished using the disk, the transaction can release the corresponding lock for other transactions
to acquire.
Up to 2 transactions can run at the same time, as long as they are using different disks.
There are 5 transactions we need to run, each needing to run for a certain amount of time steps and needing to use a certain set
of disks. (See an example below.)
Note: You can every transaction uses all the needed disks and holds all the needed locks for the transaction’s entire duration.
We would like to write logical statements to find a time for each of the 5 transactions to run, while avoiding any scheduling
conflicts (e.g. ensuring transactions don’t access the same disk at the same time).
Here is an example of a set of transactions, their requirements, and an example of a valid schedule. This is just an example, and
is not needed to solve the problem. (Note: The height of the transaction boxes is just for indicating which disks are being used,
and has no other meaning.)
• 𝑎𝑡=0
1
is True if and only if Transaction 1, at time 𝑡 = 0, is holding the lock 𝑎 corresponding to disk 𝐴.
𝑎𝑡=0
2
, 𝑎𝑡=0
3
, 𝑎𝑡=0
4
, 𝑎𝑡=0
5
, 𝑏𝑡=0
1
, 𝑏𝑡=0
2
, … , 𝑐4𝑡=0 , 𝑐5𝑡=0 are defined similarly.
12
The symbol definitions, repeated for your convenience:
In the next few subparts, select the logical sentence that matches the English statement.
(a) [2 pts] If Transaction 1 is holding a lock at time 𝑡 = 0, then Transaction 1 is running at that time, and needs to access the
disk corresponding to the lock.
# 𝑎𝑡=0
1
∨ 𝑏𝑡=0
1
∨ 𝑐1𝑡=0
( )
# 𝑎𝑡=0
1
⟹ ¬𝑎𝑡=0 2
∧ ¬𝑎𝑡=0
3
∧ ¬𝑎𝑡=0
4
∧ ¬𝑎𝑡=0
5
( ) ( ) ( )
# (𝐴1 ∧ 𝑇1𝑡=0 ) ⟹ 𝑎𝑡=0
1
∧ (𝐵1 ∧ 𝑇1𝑡=0 ) ⟹ 𝑏𝑡=01
∧ (𝐶1 ∧ 𝑇1𝑡=0 ) ⟹ 𝑐1𝑡=0
( 𝑡=0 ) ( ) ( )
𝑎1 ⟹ (𝐴1 ∧ 𝑇1𝑡=0 ) ∧ 𝑏𝑡=0 1
⟹ (𝐵1 ∧ 𝑇1𝑡=0 ) ∧ 𝑐1𝑡=0 ⟹ (𝐶1 ∧ 𝑇1𝑡=0 )
𝑎𝑡=0
1
is Transaction 1 holding lock 𝑎 at time 0. If then is an implication, leading to 𝐴1 being the fact that Transaction 1
accesses Disk 𝐴 and 𝑇1𝑡=0 is Transaction 1 running at time 1. Lastly, we repeat this for locks 𝑏 and 𝑐 since we want "a
lock".
(b) [1 pt] Is the logical sentence in the previous subpart an axiom that is true of the problem we described?
In other words: Select “Yes” if the logical sentence above should be included for any possible set of 5 transactions we
want to schedule.
Note: In the problem, a transaction could possibly hold a lock without using the corresponding disk.
# Yes No
Although it’s intuitive for this is to be true in real life and this doesn’t reduce the set of solutions (schedules) that are
available because the SAT solver has the option to not give extraneous locks, this is not required by the problem statement.
(c) [2 pts] If Transaction 3 needs to use Disk 𝐴 and is running at time 𝑡 = 2, then no other transaction that uses Disk 𝐴 should
be running at the same time step.
( ) (( ) ( ) ( ) ( ))
𝐴3 ∧ 𝑇3𝑡=2 ⟹ ¬𝐴1 ∨ ¬𝑇1𝑡=2 ∧ ¬𝐴2 ∨ ¬𝑇2𝑡=2 ∧ ¬𝐴4 ∨ ¬𝑇4𝑡=2 ∧ ¬𝐴5 ∨ ¬𝑇5𝑡=2
( )
# 𝑎𝑡=2 3
⟹ ¬𝑎𝑡=2 1
∨ ¬𝑎𝑡=2
3
∨ ¬𝑎𝑡=2
4
∨ ¬𝑎𝑡=2
5
( )
# 𝐴3 ∧ 𝑇3𝑡=2 ⟹ 𝑎𝑡=2 3
( )
# 𝑎𝑡=2 3
⟹ 𝐴 3 ∧ 𝑇3
𝑡=2
( )
The left side is logically equivalent to the English "if" for all options because the 𝐴3 ∧ 𝑇3𝑡=2 implies 𝑎𝑡=2 3
. Since we
want no other transaction, the right side needs to have something for every transaction, so only options 1 and 2 remain.
The first option matches the then part and it joins the conditions for each transaction with and, which is correct because
we want all of the transaction to be prevented from using the Disk, not just at least one.
Interestingly,
( option)2 would have been logically equivalent (but not direct translation) if (it had ∧ instead
) of ∨. This is
because 𝐴1 ∧ 𝑇1𝑡=2 ⟹ 𝑎𝑡=2 1
. When we negate this implication, we get ¬𝑎𝑡=2 ⟹ ¬ 𝐴 ∧ 𝑇 𝑡=2 . This means that
1 1 1
we are able to establish a chain: option 1 left implies option 2 left (known from rest of setup), and option 2 left implies
option 2 right (via selecting it), and option 2 right implies option 1 right (known from rest of setup).
(d) [1 pt] Is the logical sentence in the previous subpart an axiom that is true of the problem we described?
13
Yes # No
Yes, the problem specifies that any actively accessed disk is exclusively accessed by only that transaction.
(e) [2 pts] We never want the database system to idle (do nothing). Select the logical sentence that matches the statement
below:
“At least one transaction is running at 𝑡 = 4.”
𝑇1𝑡=4 ∨ 𝑇2𝑡=4 ∨ 𝑇3𝑡=4 ∨ 𝑇4𝑡=4 ∨ 𝑇5𝑡=4
# 𝑇1𝑡=4 ∧ 𝑇2𝑡=4 ∧ 𝑇3𝑡=4 ∧ 𝑇4𝑡=4 ∧ 𝑇5𝑡=4
( 𝑡=4 ) ( ) ( )
# 𝑎1 ∨ 𝑎𝑡=4
2
∨ … ∨ 𝑎𝑡=4
5
∧ 𝑏𝑡=4
1
∨ 𝑏𝑡=4
2
∨ … ∨ 𝑏𝑡=4
5
∧ 𝑐1𝑡=4 ∨ 𝑐2𝑡=4 ∨ … ∨ 𝑐5𝑡=4
( 𝑡=0 ) ( ) ( )
# 𝑇1 ⟹ 𝑇1𝑡=1 ∨ 𝑇1𝑡=1 ⟹ 𝑇1𝑡=2 ∨ … ∨ 𝑇1𝑡=3 ⟹ 𝑇1𝑡=4
This is satisfied by Transaction 1 running, or 2, etc. This is also the implementation of the 𝑎𝑡𝐿𝑒𝑎𝑠𝑡𝑂𝑛𝑒 function from
Project 3.
14
The symbol definitions, repeated for your convenience:
(f) [2 pts] Select the English sentence that matches the sentence below:
(( ) ( ))
𝑇1𝑡=0 ∧ 𝑇2𝑡=0 ⟹ ¬𝑇3𝑡=0 ∧ ¬𝑇4𝑡=0 ∧ ¬𝑇5𝑡=0 ∧
(( ) ( ))
𝑇1𝑡=0 ∧ 𝑇3𝑡=0 ⟹ ¬𝑇2𝑡=0 ∧ ¬𝑇4𝑡=0 ∧ ¬𝑇5𝑡=0 ∧
(( ) ( ))
𝑇1𝑡=0 ∧ 𝑇4𝑡=0 ⟹ ¬𝑇2𝑡=0 ∧ ¬𝑇3𝑡=0 ∧ ¬𝑇5𝑡=0 ∧
(( ) ( ))
𝑇1𝑡=0 ∧ 𝑇5𝑡=0 ⟹ ¬𝑇2𝑡=0 ∧ ¬𝑇3𝑡=0 ∧ ¬𝑇4𝑡=0 ∧
(( ) ( ))
𝑇2𝑡=0 ∧ 𝑇3𝑡=0 ⟹ ¬𝑇1𝑡=0 ∧ ¬𝑇4𝑡=0 ∧ ¬𝑇5𝑡=0 ∧
…
(( ) ( 𝑡=0 ))
𝑇4𝑡=0 ∧ 𝑇5𝑡=0 ⟹ ¬𝑇1 ∧ ¬𝑇2𝑡=0 ∧ ¬𝑇3𝑡=0
(g) [3 pts] For this subpart only, suppose there are 𝑋 transactions, each accessing exactly 𝐾 disks each, 𝐷 total disks, and 𝑇
time steps. How many different propositional logic symbols are used to specify this problem?
You can answer in big-O notation, i.e. you can drop lower-order terms in the summation.
Unrelated example: 𝑂(𝑀𝑁 + 3𝑁) can be simplified to 𝑂(𝑀𝑁).
( )
𝑂
𝑂(𝐷𝑇 𝑋)
There are 𝐷𝑋 symbols of type “transaction X needs to access disk Y,” one per transaction per disk.
There are 𝐷𝑇 𝑋 symbols of type “transaction X holds lock Y at time Z”, one per transaction per disk per time step.
There are 𝑇 𝑋 symbols of type “transaction X is running at time Y”, one per transaction per time step.
In total, we have 𝐷𝑇 𝑋 + 𝐷𝑋 + 𝑇 𝑋 symbols. Dropping lower-order terms (as shown in the unrelated example) gives us
𝑂(𝐷𝑇 𝑋).
(h) [2 pts] Is it possible to represent the same problem using propositional logic, without using the lock symbols like 𝑎𝑡=0
1
?
In other words, can you write a logical problem that always outputs a solution (a set of satisfying assignments for all other
symbols) if one exists, without using the lock symbols?
# Yes, because different transactions can access different items.
Yes, because we can write a goal test that ensures that transactions running at the same time do not access the
same disk.
# No, because it is no longer possible for a transaction to acquire a lock it does not need.
# No, because the symbols encoding which transactions need which disks (e.g. 𝐴1 ) cannot specify a time when
the transaction needs the disk.
Yes, locks are redundant logically since we can express exclusivity without them, which is what they are used for here.
15
The relevant symbol definitions, repeated for your convenience:
In the rest of the question, we want to express the same problem in first-order logic. Let’s add the following constants:
(i) [2 pts] Suppose we want to convert the symbol 𝐵3 into first-order logic.
We define a new predicate named Accesses to help represent this symbol. What is the minimum set of constants that
Accesses needs in order to compute a true/false value corresponding to 𝐵3 ?
Your answer may only use constants from the list above and commas.
( )
Accesses
Accesses(T3, B)
𝐵3 is true when transaction 3 (T3) accesses disk B.
In order to represent this symbol in first-order logic, we should provide the corresponding constants, T3 and B. Any other
constants passed in would be extraneous.
• Transaction(𝑥), Lock(𝑥), Disk(𝑥), and Time(𝑥) are True if and only if the constant 𝑥 is a transaction, lock, disk, or time
step, respectively.
• Locked(𝑥, 𝑙, 𝑡) is True if and only if transaction 𝑥 is holding lock 𝑙 at time 𝑡.
• Running(𝑥, 𝑡) is True if and only if transaction 𝑥 is running at time 𝑡.
(j) [2 pts] Select the English sentence that matches the sentence below:
( ( )) ( ( ) )
∀𝑥 Transaction(𝑥) ⟹ ¬Running(𝑥, 𝑡) ⟹ ∀𝑥, 𝑙 Transaction(𝑥) ∧ Lock(𝑙) ⟹ ¬Locked(𝑥, 𝑙, 𝑡)
(k) [2 pts] Select the logical sentence that goes in the blank to match the statement below:
When a transaction is holding a lock, no other transaction can be holding the lock at that time.
(( ) )
∀𝑥, 𝑙, 𝑡 Transaction(𝑥) ∧ Lock(𝑙) ∧ Time(𝑡) ⟹ (__________)
( )
# Locked(𝑥, 𝑙, 𝑡) ⟹ ∃𝑦 Locked(𝑦, 𝑙, 𝑡) ⟹ (𝑥 ≠ 𝑦)
( )
# Locked(𝑥, 𝑙, 𝑡) ⟹ ∀𝑦 Locked(𝑦, 𝑙, 𝑡) ⟹ (𝑥 ≠ 𝑦)
16
( )
# Locked(𝑥, 𝑙, 𝑡) ⟹ ∃𝑦 Locked(𝑦, 𝑙, 𝑡) ⟹ (𝑥 = 𝑦)
( )
Locked(𝑥, 𝑙, 𝑡) ⟹ ∀𝑦 Locked(𝑦, 𝑙, 𝑡) ⟹ (𝑥 = 𝑦)
For every possible Locked output, if it is true we know that looking over all transactions for the same lock and time, the
only way that this is allowed is if it guarantees that it’s for the same transaction.
17
Q5. [17 pts] Games: Five Nights at Wheeler
You and your friend Cam are being chased by Oski, a homework-eating bear. Oski has chased you and Cam inside Wheeler Hall.
You decide that your homework is more important than Cam’s homework and intend on getting Oski to eat Cam’s homework
instead of yours.
You choose to represent Wheeler Hall as a 3-dimensional 6 × 4 × 3 grid, with stairs at each of the corners allowing agents to
move up or down one floor (into the same corner on the new floor). Shaded squares represent walls, and squares with horizontal
bars represent stairs. O is Oski, C is Cam, and Y is You.
At each time step, each agent can either move to any valid adjacent grid square or choose to stay in place. After choosing to
stay in place, an agent can choose to continue moving on the next time step.
You choose to model the situation as a depth-limited multi-agent game tree. Similar to Project 2, each depth level corresponds
to one action from You, followed by one action from Cam, followed by one action from Oski. The evaluation function is called
on a state when the maximum depth is reached.
(a) [2 pts] Which of the following is a valid and minimal state representation for the specific grid shown above?
# Three boolean values for each grid square, representing whether that square has You, Cam, or Oski, respectively.
An (𝑥, 𝑦, 𝑧) integer tuple for each agent, representing the agent’s position.
# An (𝑥, 𝑦, 𝑧) integer tuple for Oski’s position, and the Euclidean distance between You and Oski, and the Eu-
clidean distance between Cam and Oski.
# An (𝑥, 𝑦, 𝑧) integer tuple for your position only.
# None of the above.
(a) requires 216 boolean values, each can be optimally stored as a bit, which can be stored in 27 bytes.
(b) is the most minimal valid option, as it requires only 9 integers, each can be stored as a single byte (8 bits) for this
specific grid, totalling 9 bytes.
(c) is not valid as there are multiple grid locations with the same distance from Oski.
(d) is not valid as it does not contain Oski’s nor Cam’s location.
(b) [2 pts] For the specific grid shown above, what is the maximum branching factor of the game tree for any state (not
necessarily the state shown)?
5. This branching factor is achievable at the corner stairwells of floor 2. For example, at the bottom left corner of floor 2,
an agent can move north, east, up, down, or choose to stop.
18
(c) [2 pts] Suppose your goal is to get Cam’s homework eaten, Cam’s goal is to avoid Oski, and Oski’s goal is to eat either
Cam’s homework or your homework.
In this subpart, suppose all agents (You, Cam, and Oski) are playing optimally with respect to their own utility, and you
know that Cam and Oski are playing optimally.
Which of the following game trees represents your model accurately with depth 1 and You as the root node?
Note: the ellipsis (...) represents omitted nodes in the tree.
# #
#
# None of the above.
(d) All three agents are optimizing their own evaluation function separately, this can be represented as each being a
maximizer node. None of the other options can represent this scenario accurately.
19
In the next two subparts, suppose Cam and Oski are selecting actions at random from some known distribution, and you know
that Cam and Oski are doing this.
(d) [2 pts] Which of the following game trees represents your new model accurately with depth 1 and You as the root node?
Note: the ellipsis (...) represents omitted nodes in the tree.
# #
#
# None of the above.
Option (c) correctly represents You as a maximizer node, and both Oski and Cam as expectation nodes, as they are taking
random actions.
(e) [4 pts] Write an expression representing what action you should take, according to the depth-1 game tree.
Notation:
• 𝑎oski , 𝑎cam , and 𝑎you represent the actions available to Oski, Cam, and You, respectively.
• 𝑓oski , 𝑓cam , and 𝑓you represent the evaluation functions used by Oski, Cam, and You, respectively.
• 𝑠′ represents the successor state after taking action 𝑎 from state 𝑠.
Fill in the blanks to write the expression:
[ ]
[ ]
(i) (ii) (iii) [ (iv) ]
20
Since we want an expression that returns an action, (i) must be option 1.
(ii) and (iii) are both option 1, as Oski and Cam are represented as taking random actions.
(iv) is option 2 as you are the one taking the action at the root node, so you run your evaluation function.
21
The next two subparts are independent from the rest of the question.
(f) [3 pts] Consider a reflex agent who uses an evaluation function to compute a value for each successor state. However,
instead of always moving to the successor state with the highest evaluation, we want the agent to probabilistically select
a successor state to move to.
Notation:
• 𝑓 is the evaluation function.
• 𝑠 is the current state.
• 𝑠′ is the successor state being considered.
• 𝑆 ′ is the set of all successor states.
We want an expression for converting an evaluation score to a probability, satisfying the following two properties:
• The resulting probability distribution is valid, i.e. the probabilities of moving to the successor states must sum to 1.
• Successor states with higher evaluations must have a higher probability of being chosen.
Here are some graphs to help you answer this question:
8 8
4 1
6 6
3 0.5
4 4 2 0
2 2 1 −0.5
0 0 0 −1
−2 −1 0 1 2 −2 −1 0 1 2 −2 −1 0 1 2 −2 −1 0 1 2
(g) [2 pts] Select all true statements about alpha-beta pruning in game trees.
■ It is possible to prune an expectimax game tree with bounded utilities at the leaf nodes.
■ It is possible to prune a game tree with three or more agents.
□ It is always possible to prune a non-zero-sum game tree with three or more agents, all separately maximizing
their own utility, as long as the tree contains both maximizer and minimizer nodes.
□ It is only possible to prune a game tree if it contains both maximizer and minimizer nodes.
# None of the above.
(a) is correct as if we bound the utilities, we can predict what the largest/smallest values are for that node and compare
with out alpha value accordingly.
(b) we did this in Project 2.
(c) is incorrect as each maximizer could have increasing utilities left-to-right, while each minimizer could have decreasing
utilities left-to-right, thus no nodes can be pruned.
(d) see explanation for option (a)
22
Q6. [18 pts] Bayes Nets: Easter Island Elections
Matei is an elf on Easter Island who is discontent with the current leadership of Pietru the Rotund.
To model the island’s politics in preparation for the Easter Elections, Matei has decided to use
the following Bayes net. 𝐴 𝐵
Each letter represents a vote cast by members of the electoral college: Abby, Brad, Charles,
Datsu, and Ershawn. For this question, +𝑣 indicates that voter 𝑉 votes in favor of Pietru the
Rotund, while −𝑣 indicates they have voted against. All voters must vote (in other words, A, B,
𝐶 𝐷
C, D, E are binary variables).
Note (1): For the entire question, when computing the size of a factor or table, do not use the
sum-to-one constraint to optimize rows out of the table. For example, if we had a table with
the two values 𝑃 (+𝑥) = 0.7 and 𝑃 (−𝑥) = 0.3, this table has two rows (even though we could 𝐸
optimize and only store one of the rows, and derive the other row from the fact that both rows
sum to 1).
Note (2): For the entire question, when computing the size of a factor or table, assume there is one row for each setting of the
variables, i.e. one row for each probability value in the table. For example, if 𝑋 and 𝑌 are binary variables, 𝑃 (𝑋, 𝑌 ) has four
rows and 𝑃 (𝑋 ∣ 𝑌 ) also has four rows.
(a) [2 pts] Which of these probability tables can be found directly in the Bayes net, without performing any computation?
Select all that apply.
■ 𝑃 (𝐴) ■ 𝑃 (𝐶 ∣ 𝐴, 𝐵) □ 𝑃 (𝐸 ∣ 𝐶)
■ 𝑃 (𝐵) □ 𝑃 (𝐸)
In the following subparts, Matei wants to compute the probability distribution 𝑃 (𝐴 ∣ +𝑒) using variable elimination.
(b) [2 pts] How many factors must Matei consider at the beginning of this process?
(c) [2 pts] Matei joins on 𝐵 and eliminates 𝐵. Which variables are included in the new factor generated after eliminating 𝐵?
Select all that apply.
For example, if you think the factor generated is 𝑃 (𝐴, 𝐵, 𝐶) or 𝑓 (𝐴, 𝐵, 𝐶), select options 𝐴, 𝐵, and 𝐶 (and nothing else).
■ 𝐴 □ 𝐵 ■ 𝐶 ■ 𝐷 □ +𝑒
(d) [2 pts] Next, Matei joins on 𝐶 and eliminates 𝐶. Which variables are included in the new factor generated after eliminating
𝐶? Select all that apply.
■ 𝐴 □ 𝐵 □ 𝐶 ■ 𝐷 ■ +𝑒
(e) [1 pt] Which variables are included in the smaller of the two remaining factors? Select all that apply.
23
■ 𝐴 □ 𝐵 □ 𝐶 □ 𝐷 □ +𝑒
(f) [1 pt] How many rows are in the smaller of the two remaining factors?
2 rows. Following both of the above eliminations the two factors we are left with are 𝑃 (𝐴) and 𝑃 (+𝑒|𝐴, 𝐷), with the
former being the smaller. This factor represents the distribution of a binary variable, and thus would have 2 rows.
24
The Bayes Net, reproduced for your convenience:
𝐴 𝐵
𝐶 𝐷
(h) [1 pt] How many rows are in the larger of the two remaining factors?
4 rows. This factor represents the distribution of a fixed evidence variable dependent on two binary variables. As a result,
there would be 1 ∗ 2 ∗ 2 = 4 rows.
(i) [2 pts] If Matei had instead decided to use inference by enumeration to compute 𝑃 (𝐴 ∣ +𝑒), how many rows would be in
the joint probability table he generates?
Note: We are looking for the size of the table before any hidden variables are marginalized (eliminated).
Note: You can assume Matei deletes all rows inconsistent with the evidence. In other words, we are looking for the size
of a table where all rows are consistent with the evidence.
# 2 # 3 16 # 32
To perform inference by enumeration, we would create a table representing every combination of our variables. Since we
have 5 binary variables, of which one is fixed as our evidence variable (+𝑒), we compute 24 = 16.
In the rest of the question, Matei now decides to use prior sampling to estimate the probability that Brad will vote in favor given
that Ershawn has voted against, or 𝑃 (+𝑏 ∣ −𝑒). The samples he generates are in the table below:
Sample # A B C D E
1 +𝑎 −𝑏 +𝑐 −𝑑 −𝑒
2 −𝑎 +𝑏 −𝑐 +𝑑 −𝑒
3 +𝑎 +𝑏 +𝑐 −𝑑 +𝑒
4 −𝑎 −𝑏 +𝑐 −𝑑 −𝑒
5 +𝑎 −𝑏 −𝑐 +𝑑 +𝑒
(j) [2 pts] Using prior sampling, what is the estimated value of 𝑃 (+𝑏 ∣ −𝑒) that Matei computes?
Similar to rejection sampling, in prior sampling when we consider the evidence −𝑒, we estimate 𝑃 (+𝑏 ∣ −𝑒) to be the
number of samples that have both +𝑏 and −𝑒 divided by the number of samples with −𝑒.
25
(k) [2 pts] Now, Matei generates two additional samples: (+𝑎, +𝑏, −𝑑, −𝑐, +𝑒) and (−𝑎, −𝑏, +𝑐, −𝑑, −𝑒)
Using prior sampling, what is the new estimated value of 𝑃 (+𝑏 ∣ −𝑒) that Matei calculates?
The first sample does not contribute to our new estimate since it doesn’t have the right evidence observation −𝑒. The
second does, however it sampled a value of −𝑏, which is an outcome we are not interested in.
26