COMP338 · Quiz #1 & Answers

Quiz #1: Worked Solutions

Problem formulation & uninformed search · Section 3 · Second Semester 2025/2026
Back to COMP338

About this Quiz

Below is every question reproduced as it appeared on the paper, with the model answer and the marking criteria for each part. Work each question on paper first, then click Show solution. Conventions follow the course lecture notes (Jarrar, Ch.3 Uninformed Search): children are expanded in alphabetical order, and the goal test is applied when a node is removed for expansion (not when it is first generated).

Course
Artificial Intelligence (COMP 338)
Section
3
Semester
Second Semester 2025/2026
Covers
Problem formulation, DFS, UCS
Questions
2 (Q1: 40 pts, Q2: 60 pts)
Total
100 pts
Q1
Problem formulation for Map Colouring
[ 40 marks ]
Write the problem formulation for the Map Colouring problem. The objective is to assign one colour from the set {Red, Blue, Green} to each region of the map below, so that no two regions sharing a border have the same colour. Figure (a) shows the uncoloured map with five regions A, B, C, D, E; Figure (b) shows one valid 3-colouring. Specify the five components: State Space, Initial State, Actions / Transition Model, Goal Test, and Path Cost.
AB CDE
(a) uncoloured
A · RB · B C · BD · RE · G
(b) one valid 3-colouring

Adjacency (shared border): A–B, A–C, B–D, B–E, C–D, D–E. The pairs A–D and B–C touch only at a corner, so they are not adjacent.

State Space
8 pts
Model answer

The set of all assignments of colours to the five regions. A state is a tuple (colour(A), colour(B), colour(C), colour(D), colour(E)), where each entry is in {R, B, G} or "uncoloured".

Counting partial colourings (each region R/B/G/uncoloured) gives 4⁵ = 1024 states; counting only fully-coloured maps gives 3⁵ = 243. Either is accepted, as is "the set of all colourings of the map".

Marking (8 pts): full marks for describing states as colour-assignments of the regions. Half credit for "the regions / the map" with no notion of assignment. The course defines a state loosely (e.g. "a state is a city"), so a reasonable description earns most marks.
Initial State
8 pts
Model answer

All five regions are uncoloured: the empty assignment (–, –, –, –, –).

Marking (8 pts): full marks for "all regions uncoloured / empty assignment". Marked down for "start at region A" or for giving a coloured state.
Actions / Transition Model
8 pts
Model answer

ACTIONS(s): choose an uncoloured region and assign it a colour from {R, B, G} that no already-coloured neighbour uses.

RESULT(s, a): the same state with that region now holding the chosen colour.

The relaxed version (assign any colour and let the goal test reject conflicts) is also accepted.

Marking (8 pts): name the action (assign a colour to a region) and the result. 4 pts if only ACTIONS or only RESULT is given.
Goal Test
8 pts
Model answer

A state is a goal iff (i) all five regions are coloured and (ii) no two adjacent regions share a colour (adjacency: A–B, A–C, B–D, B–E, C–D, D–E).

Marking (8 pts): both conditions for full marks; 4 pts if only one is stated. Stating "colour the map" with no constraint is the task, not the goal test.
Path Cost
8 pts
Model answer

1 per assignment (each colouring step costs 1), so a solution that colours all five regions has path cost 5. Map colouring is a CSP and we only care about reaching a goal state, so "uniform", "0", or "irrelevant for a CSP" are all accepted.

Marking (8 pts): any consistent cost statement (1 per step / uniform / irrelevant). Marked down for giving an unexplained number or a path of nodes instead of a cost.
Q2
Search on a weighted graph
[ 60 marks ]
For the graph below, the start node is S and the goal is G. Assume the order of expansion is alphabetical.
2 5 3 1 5 4 2 1 SAC DBEG

Edges (undirected): S–A 2, S–B 5, A–C 3, A–D 1, C–G 5, D–G 4, B–E 2, E–G 1.

Q2.a · Search tree
15 pts
Draw the search tree generated when expanding nodes from S.
Model answer

Expanding from S, with children listed alphabetically (using a reached set so each state appears once):

S ├─ A │ ├─ C ── G │ └─ D ── G └─ B ── E ── G

The tree-search version (no reached set), in which G appears as a separate leaf on each of the three root-to-goal paths (via C, via D, via E), is equally accepted; it matches the "traversing a graph as a tree" figure in the lecture notes.

Marking (15 pts): 7 pts for the correct branching from S (A and B as children); 8 pts for correctly ordered children at each level.
Q2.b · Depth-First Search
15 pts
Give the order in which nodes are expanded and the path returned to the goal.
Model answer

DFS uses a stack (LIFO) and expands children alphabetically. From S push A, B; expand A first; from A push C, D; expand C; C leads to G; goal found.

Order of expansion:

S → A → C → G

Path to goal:

S → A → C → G

DFS ignores edge weights, so it returns this path even though its cost (2+3+5 = 10) is not optimal. (The question asks only for the order and the path, not a cost.)

Marking (15 pts): 7 pts for the expansion order S, A, C, G (taking the B branch first, e.g. S-B-E-G, is the common error); 8 pts for the path S → A → C → G. Listing the full traversal is fine as long as the A-branch is taken first.
Q2.c · Uniform-Cost Search
30 pts
Give the order of expansion, the path to the goal, and the total path cost.
Model answer

UCS expands the frontier node with the least path cost g(n) first, breaking ties alphabetically, and applies the goal test when a node is removed for expansion (not when generated). Trace of the priority queue:

Expand (g)Frontier afterwards (node : g)
S (0)A:2, B:5
A (2)D:3, B:5, C:5
D (3)B:5, C:5, G:7
B (5)C:5, E:7, G:7
C (5)E:7, G:7, G:10  (G via C = 10, not better)
E (7)G:7, G:8, G:10  (G via E = 8, not better)
G (7)goal test passes, path returned

Order of expansion:

S → A → D → B → C → E → G

Path to goal:

S → A → D → G

Total path cost:

2 + 1 + 4 = 7
Marking (30 pts):
  • 15 pts for the expansion order S, A, D, B, C, E, G. A tie handled in the wrong order (B/C at g=5, or E/G at g=7) loses only a little; 0 if UCS is stopped the moment G is first generated rather than expanded.
  • 10 pts for the path S → A → D → G.
  • 5 pts for the total cost 7.
Summary of marks. Q1 Problem formulation (40): State Space (8) · Initial State (8) · Actions/Transition (8) · Goal Test (8) · Path Cost (8). Q2 Search (60): Search tree (15) · DFS order + path (15) · UCS order + path + cost (30). Total: 100 pts.