Professional Documents
Culture Documents
Semesters 1 & 2
Computer Science
School of Computing
CONTENTS
Assignments 01 and 02, and the self-assessment assignment for both semesters
BAR CODE
university
Define Tomorrow. of south africa
We remind you that the purpose of these assignments are for you to have a genuine attempt
at solving some sample problems. It is thus a matter of personal learning, and growth. Please don’t
leave them to the last minute, and above all: please put in honest, own effort when completing
them.
ASSIGNMENT 1
Due Date: 12 May 2021
Total Marks: 150
Unique Assignment Number: 848630/772589
Study material: Chapters 1 through 4. You may skip sections 4.2 and 4.5.
Important: When we use the phrase ‘define’ (particularly in Question 2), we are looking
for a formal definition using some form of formal notation, and not simply an English description
or definition. For example: ‘Define the initial state for an agent in Johannesburg’. Answer:
In(Johannesburg). ‘Define the actions available to this agent given that the agent simply moves
between major metropolitan areas’. Answer: Actions(In(Johannesburg)) = {Go(Bloemontein),
Go(Durban), . . . }. When we want an English definition we will explicitly ask for it.
Question 1: 13 Marks
(1.1) Explain the difference between a single and multi-agent environment. (6)
(1.2) Explain the difference between a Deterministic and Stochastic environment. (4)
(1.3) Consider a game of chess. Is this a fully observable, partially observable, or unobservable (3)
environment? Clearly explain your answer.
Question 2: 22 Marks
(2.1) List the 5 components that can be used to define a problem. (5)
(2.4) List and discuss three types of queues that may be employed in a search. (6)
(2.5) List and explain the measures used to determine problem solving performance. (8)
2
COS3751/102/3/2021
Question 3: 23 Marks
Three (3) hikers (Andile, Barbara, and Ché) have just descended down a valley to find themselves
confronted by a river they cannot get across. After walking downstream for a while they find two
young boys with a boat and ask them if they would help them get across the river. The boys agree,
but inform the hikers that since their boat is so small, it can only hold only the two boys or one of
the hikers at a time. We can assume that everyone knows how to row the boat.
(3.1) Define a state using a mathematical notation (pictures or any form of graphical notation (7)
will not be accepted). Discuss the appropriateness of your choice, and provide an example
to show that it will be suitable to be employed during a search.
(3.2) Define the start and goal states using your representation. (6)
(3.3) Define an appropriate cost function or functions for this problem. (2)
(3.4) Provide a formal definition of a valid action function for this problem – you need not (8)
provide a formal definition for the operation of the function. Discuss the operation of the
function and provide an example to illustrate its use.
Question 4: 12 Marks
(4.1) Highlight the differences between a tree and graph search. (3)
(4.2) How does a Breadth First Search (BFS) differ from the general tree seach algorithm? (5)
What is the major reason for implementing the algorithm in this way? Provide an
example to aid your discussion.
(4.3) Consider an example of a sliding-block puzzle game state provided below (Figure 1). How (4)
many distinct states are there for puzzles of this sort? How many search nodes? Explain
how you reached your answer.
I N L D
E C K
B H J O
A F G M
3
Question 5: 6 Marks
M E
D C L B
K I J H F G N A
(5.1) Show the order in which the nodes will be expanded (from limit 0 to limit 4) given that (6)
IDS is used. Assume the goal node is F , and that nodes are expanded from left to right.
Question 6: 16 Marks
(6.1) Explain the concept of Uniform Cost Search (UCS). Provide an example to aid your (4)
discussion
(6.2) Suppose we start at C and the goal is G. Write down the nodes in the order they are (12)
expanded. Show your steps and calculations. The step cost between nodes is provided
next to the edges in the graph.
Question 7: 4 Marks
Question 8: 31 Marks
Consider Figure 4 and Table 1 and answer the questions that follow. Table 1 provides the estimated
distances from each node to H (thus ĥ for each node). The label next to each edge provides the cost
between nodes (thus ĝ).
4
COS3751/102/3/2021
11
B 20
15
C
D 4
24
14
22 F
G E
9
12
(8.1) Supose the start node is A, and the goal node is N . List the nodes in the order in which (10)
they are expanded (not generated). Show your steps (don’t just list the nodes, explain
the reason for each choice).
(8.2) When adding nodes to the frontier (during the search), is it enough to simply add nodes (4)
from the state space to the frontier? Justify your answer.
(8.3) Provide the content of the frontier at the time the search terminates. (10)
(8.4) Is the heuristic being applied consistent? Justify your answer by providing proof from (7)
the graph.
Question 9: 23 Marks
A magic square is a square of n × n cells, and which has some very interesting properties: all the
5
A
7
3
8
B D 10
10 C 4
7
F K
8
6 5
10 3 2
5 I
E
G M
5 4 L
1
H 3
Figure 4: A∗ Search
rows, columns, and diagonals, when summed, adds up to the magic constant. The magic constant is
calculated as follows:
n(n2 + 1)
M=
2
3(32 +1)
Thus, for n = 3, M = 2
= 15. The entries in the square are limited to the integers between 1
6
COS3751/102/3/2021
8 1 6
3 5 7
4 9 2
It is easy to verify that every row, column, and diagonal in the above example adds up to 15.
(9.2) One way of solving a magic square is to randomly populate the entries, and then swap val- (4)
ues until a solution is found. Define an appropriate objective function for this approach.
Explain its function and provide and example to illustrate its use.
(9.3) Differentiate between a standard hill-climb search and a simulated annealing search. (5)
Would simulated annealing fit the approach in the previous question? Explain your
answer. (Hint: think about what simulated annealing is supposed to do with respect to
local/global maxima, also think about shoulders and plateaux.)
(9.4) Using the approach suggested above, show the first 5 states in the search as well as (10)
the value of your objective function for each state. (Start off with a randomly populated
magic square, and show 4 subsequent “moves”. In each case, show the value the objective
function would take for each “move”.)
7
ASSIGNMENT 2
Due Date: 7 July 2021
Total Marks: 150
Unique Assignment Number: 738958/763908
Study material: Chapters 5 and 6. You may skip sections 5.5, 5.6, and 5.7.
Question 1: 13 Marks
(1.1) Clearly explain what a utility function is, and why it is used during adversarial searches. (3)
(1.2) Is the ideal strategy only available if we have perfect information? Explain your answer. (4)
(1.3) Explain how forward pruning works. Provide at least one approach to forward pruning in (3)
your explanation, as well as a problem that may be encountered with forward pruning.
(1.4) Does the order in which nodes are examined in minimax matter? Explain your answer. (3)
Question 2: 31 Marks
Consider Figure 6 and answer the questions that follow. (The utility value of the leaf nodes are
provided in brackets in the leaf node.)
B C
D E F G H I
J K L M N O Q R
P
-7 0 -4 3 -4
5 -8 -12 -3
8
COS3751/102/3/2021
(2.1) Provide the minimax values for all the nodes. (9)
(2.2) Which move should MAX make? Explain your answer. (2)
(2.3) Write down the α/β values for all the nodes (except the leaf nodes) if alpha/beta pruning (14)
is applied to the tree.
(2.4) Write down which nodes were cut and what type of cut was made in each case (alpha, (6)
or beta).
Question 3: 23 Marks
(3.1) Consider a simplified version of Nim: Two players (A and B) take turns removing items
from a heap (just one heap). Each player may remove either one or two items from the
heap. The heap starts off with five items, and player A moves first. The objective of the
game is to be the last player to remove items from the heap. That is, if it is your turn
to move, and the heap is empty, you’ve lost the game.
A partial game tree for the game is shown in Figure 7 on page 10. The state
represented in each node is (P, n) where P ∈ {A, B} (the player whose turn it is to move
next) and 0 ≤ n ≤ 5 (the number of items remaining in the heap). Thus (A, 5) would
mean that player A will move next, and there are five items left in the heap. The label
next to each edge indicates the number of items removed by the player whose turn it was
to move.
Terminal states are shown in rectangles. The utility value for a win uw for player
A is +1, and a loss ul is −1 (draws are not possible in this game). Players are greedy,
and if a win is possible, they will take it.
Suppose you are trying to build a minimal tree for the game using expected utility
values for different states (since you have access to the entire search tree you are able to
use statistics based on the number of occurrences of events – or the maximum likelihood
estimator). You want to limit the depth of the tree to 2 (the root node and one level
below).
(a) Differentiate between utility and expected utility, provide an example to illus- (5)
trate.
(b) What is the expected utility value for state (B, 4) (E(B,4) ) for player A? Show (9)
your calculations. Should A play to state (B, 4) by taking just 1 item from the heap?
Why/why not (refer to the expected utility value you calculated when answering this
part of the question)?
(c) (9)
Now calculate the expected utility value for (B, 3). Show your calculations.
Will A benefit from making this move instead of moving to (B, 4)? Justify your
answer.
9
...
2
(B,2) (A,0)
1
(B,3)
(A,3)
2
1
(B,1) (A,0)
2
(A,5) 1
(B,4)
2
2
(A,2) (B,0)
Question 4: 11 Marks
(4.4) If no legal assignments for a variable remain during a solution to a CSP, does it mean (2)
that the algorithm will be able to find a solution by simply backtracking? Explain your
answer.
Question 5: 43 Marks
10
COS3751/102/3/2021
Cryparithmetic puzzles can be represented as CSPs if properly reformulated. Answer the ques-
tions that follow.
(5.1) Define the variables for this cryptarithmetic puzzle. (Include any carry variables that (11)
may be required).
(5.4) Provide the solution to this crypt-arithmetic puzzle, show all the steps you took to arrive (10)
at the answer (also show which heuristic you employed, and your backtracking strategy
(if used)).
Question 6: 29 Marks
Consider the problem of assigning registers on a central processing unit (CPU) to the variables in a
program. Since a program may have many variables and there are a limited number of registers on
the CPU, assigning registers to variables is an important problem.
Since only certain variables are in use at different times during the execution of the program
(variables that are being used at a particular time are called alive), the real task is merely to figure
out which alive variables to assign to the limited number of registers.
This is a classic graph-colouring problem. For a certain program the following holds:
2. Program variables A,B, and D are alive together. Program variables C,D,E, and F are alive
together, and program variables A,E, and G are alive together.
(6.2) Define the domain for each variable in the CSP. (4)
(6.3) Define the constraints for the variables in the CSP. (11)
(6.4) Provide the constraint graph for this problem. Does a solution exist? If no solution (5)
exists, explain what parameters from the problem would have to change in order to get
to a solution.
11
SELF ASSESSMENT ASSIGNMENT
ALL STUDENTS
Study material: Chapters 7, 8, 9, and 18. You may skip sections 6.6, 8.4, 9.3, 9.4. You
only need to study 18.1, 18.2, and 18.3
Question 1
Question 2
Question 3
Question 4
Question 5
Anyone passing his history exam and winning the lottery is happy.
John is lucky.
(5.1) Translate the above English sentences to First-order Logic (FOL) statements.
12
COS3751/102/3/2021
(5.2) Convert the FOL statements obtained in 5.1 into clause form.
Question 6
x1 x2 x3 f(x1 , x2 , x3 )
0 0 0 1
0 0 1 0
0 1 0 1
0 1 1 1
1 0 0 1
1 0 1 0
1 1 0 0
1 1 1 1
(6.2) When we construct a decision tree without the benefit of gain values, the order in which
we evaluate the variables is important. Why?
Question 7
The National Credit Act introduced in South Africa in 2007 places more responsibility on a bank to
determine whether the loan applicant will be able to afford it. Blue Bank has a table of information
on 14 loan applications they have received in the past.
(7.1) Use the information in this table to construct a decision tree that will assist the bank in
determining the RISK associated with a new loan application.
13
No. Credit history Debt Collateral Income RISK
1 Bad High No < R15k High
2 unknown High No R15k - R35k High
3 unknown Low No R15k - R35k Medium
4 unknown Low No < R15k High
5 unknown Low No > R35k Low
6 unknown Low Yes > R35k Low
7 Bad Low No < R15k High
8 Bad Low Yes > R35k Medium
9 Good Low No > R35k Low
10 Good High Yes > R35k Low
11 Good High No < R15k High
12 Good High No R15k - R35k Medium
13 Good High No > R35k Low
14 Bad High No R15k - R35k High
14