AS & A Level Computer Science (9618)
Artificial intelligence
7 questions · about 2% of the marks we indexed · examined in 7 of 9 sessions.
Practice questions
Original questions written by HomiLabs in the style of the exam, with answers and mark schemes. They are not
Cambridge past paper questions and have not been reviewed by Cambridge. Try each one before opening the answer.
Q1Graphs, Dijkstra & A* · Core · Paper 3 style · 5 marks- (a) Describe the structure of a graph as used in artificial intelligence. [3]
- (b) Explain how a graph can be used by a delivery robot in a hospital to plan its route. [2]
Show answer
- (a) A graph is a set of nodes (vertices) joined by edges (arcs). Edges can be directed (one way) or undirected, and can be weighted with a value such as distance, time or cost.
1 mark nodes/vertices representing objects or states; 1 mark edges/arcs representing connections/relationships; 1 mark edges may be weighted and/or directed.
- (b) Each room or corridor junction is a node, and each corridor is an edge weighted with its length or travel time; a shortest-path algorithm such as Dijkstra or A* searches the graph to find the fastest route between two rooms.
1 mark mapping locations to nodes and corridors to weighted edges; 1 mark algorithm finds the shortest/lowest-cost path.
Q2Graphs, Dijkstra & A* · Core · Paper 3 style · 5 marksRoads between five villages in the Swat valley are shown as an undirected weighted graph (distances in km):A – B: 4A – C: 2B – C: 1B – D: 5C – D: 8C – E: 10D – E: 2
- (a) Use Dijkstra's algorithm to find the shortest distance from village A to each of the other villages. Show the final distance of every node. [4]
- (b) State the shortest route from A to E. [1]
Show answer
- (a) A 0, B 3, C 2, D 8, E 10
Working: A permanent (0); C = 2 (from A); B = min(4, 2 + 1) = 3; D = min(3 + 5, 2 + 8) = 8; E = min(2 + 10, 8 + 2) = 10. 1 mark each for B, C/D, E correct with working; 1 mark distances updated when a shorter route is found (B from 4 to 3).
- (b) A → C → B → D → E (10 km)
B1.
Q3Graphs, Dijkstra & A* · Core · Paper 3 style · 5 marksAn undirected weighted graph of five computer-lab buildings is stored in an adjacency matrix (0 means no edge). Rows and columns are in the order K, L, M, N, O:K: 0 6 2 0 0L: 6 0 3 4 0M: 2 3 0 9 8N: 0 4 9 0 2O: 0 0 8 2 0
- (a) List the edges of the graph with their weights. [2]
- (b) State which node has the most edges, and how many. [1]
- (c) Find the shortest distance from K to O and the route. [2]
Show answer
- (a) K–L 6, K–M 2, L–M 3, L–N 4, M–N 9, M–O 8, N–O 2
2 marks all seven edges; 1 mark for five or six.
- (b) M, with 4 edges
B1.
- (c) 10, by K → M → O
1 mark 10; 1 mark route (K → M → L → N → O is 11).
Q4Graphs, Dijkstra & A* · Core · Paper 3 style · 5 marks- (a) State what g, h and f represent in the A* algorithm. [3]
- (b) Three nodes are on the open list: X (g = 12, h = 9), Y (g = 15, h = 4), Z (g = 8, h = 14). Calculate f for each and state which node A* expands next. [2]
Show answer
- (a) g: the actual cost of the path from the start node to the current node. h: the heuristic – an estimate of the cost from the current node to the goal. f = g + h: the estimated total cost of a path to the goal through that node.
1 mark each.
- (b) X 21, Y 19, Z 22; Y is expanded next.
1 mark all three f values; 1 mark Y.
Q5Graphs, Dijkstra & A* · Standard · Paper 3 style · 7 marksA courier company in Karachi models roads between its warehouse W and depots P, Q, R, S and T (distances in km, roads are two-way):W – P: 6W – Q: 3P – Q: 2P – R: 5Q – R: 9Q – S: 9R – S: 1R – T: 4S – T: 8
- (a) Use Dijkstra's algorithm to complete a table showing, for each depot, the shortest distance from the warehouse W and the previous node on the shortest route. [5]
- (b) State the shortest route from W to T. [1]
- (c) The road between R and S is closed. State the new shortest distance from W to S. [1]
Show answer
- (a) Node | Distance | PreviousW | 0 | –Q | 3 | WP | 5 | QR | 10 | PS | 11 | RT | 14 | R
Nodes become permanent in the order W, Q, P, R, S, T. 1 mark each for P (5 via Q), R (10 via P), S (11 via R, not 12 via Q), T (14 via R); 1 mark previous-node column fully correct.
- (b) W → Q → P → R → T (14 km)
B1.
- (c) 12 km (W → Q → S)
B1.
Q6Graphs, Dijkstra & A* · Standard · Paper 3 style · 6 marksA robot in a factory in Sialkot plans a route. The undirected weighted graph (costs in metres) is:S – A: 4S – B: 3A – C: 5B – C: 7B – D: 6C – G: 4D – G: 8A – D: 3The heuristic h (estimated straight-line distance to G) is: S 10, A 6, B 8, C 3, D 8, G 0.
- (a) Use the A* algorithm to find the shortest path from S to G. For each node you visit, show g (cost from S), h and f = g + h, and give the order in which nodes are expanded. [5]
- (b) Explain why node D was never expanded. [1]
Show answer
- (a) Expand S (g 0, h 10, f 10): A f = 4 + 6 = 10, B f = 3 + 8 = 11.Expand A (f 10): C g 9, f 12; D g 7, f 15.Expand B (f 11): via B, C would be 10 and D 9 – no improvement.Expand C (f 12): G g 13, f 13.Expand G (f 13) – goal reached.Order: S, A, B, C, G. Path S → A → C → G, cost 13.
1 mark f values for A and B; 1 mark A expanded before B (lower f); 1 mark f for C and D; 1 mark correct expansion order with D never expanded; 1 mark path and cost 13.
- (b) Its f value (15) was greater than the f value of the goal (13) when the goal was reached.
B1.
Q7Graphs, Dijkstra & A* · Standard · Paper 3 style · 5 marksAn A* search for a delivery van uses these values (true cost = actual shortest distance to the goal E):Node | h | True costA | 10 | 12B | 8 | 7C | 6 | 9D | 4 | 4E | 0 | 0
- (a) State what is meant by an admissible heuristic. [1]
- (b) Using the table, decide whether the heuristic is admissible. Identify any node that breaks the rule. [2]
- (c) Explain why using a heuristic that overestimates can make A* return a route that is not the shortest. [2]
Show answer
- (a) A heuristic that never overestimates the true cost from a node to the goal.
B1.
- (b) Not admissible: node B has h = 8 but the true cost is 7, so it overestimates.
1 mark not admissible; 1 mark B identified with reason.
- (c) A* may give a node on the true shortest route a falsely high f value, so it reaches the goal through another route (with lower f) before expanding that node, and stops.
1 mark f of nodes on the best path inflated; 1 mark goal reached/selected via a worse path first.
Q8Graphs, Dijkstra & A* · Standard · Paper 3 style · 6 marksTravel times (minutes) between junctions in Rawalpindi, roads two-way:A – B: 3A – C: 6B – C: 2B – D: 7C – D: 3C – E: 8D – E: 2D – F: 6E – F: 3
- (a) Use Dijkstra's algorithm to find the shortest time from A to F and the route. [3]
- (b) Road works increase the time on edge C–D from 3 to 9 minutes. Find the new shortest time from A to F and the route. [2]
- (c) Explain why a navigation app must re-run the algorithm when traffic conditions change. [1]
Show answer
- (a) 13 minutes: A → B → C → D → E → F
Distances: B 3, C 5, D 8, E 10, F 13. 1 mark C 5 via B; 1 mark D 8, E 10; 1 mark F 13 with route.
- (b) 15 minutes: A → B → D → E → F
1 mark 15; 1 mark route (D now 10 via B).
- (c) Edge weights (travel times) have changed, so the previously calculated shortest route may no longer be the shortest.
B1.
Q9Graphs, Dijkstra & A* · Standard · Paper 3 style · 6 marks- (a) Describe two differences between Dijkstra's algorithm and the A* algorithm. [4]
- (b) Suggest a suitable heuristic for A* in a road-navigation app and explain why it is suitable. [2]
Show answer
- (a) Dijkstra chooses the next node using only the distance from the start (g); A* uses f = g + h, adding a heuristic estimate of the distance to the goal. Dijkstra explores in all directions and can find shortest paths from the start to every node; A* is directed towards one goal and usually expands fewer nodes, so it is faster for a single destination. A* needs a heuristic (e.g. straight-line distance) to be available; Dijkstra does not.
2 marks per difference (both sides stated), any two.
- (b) Straight-line (as-the-crow-flies) distance from the node to the destination, calculated from GPS coordinates; a road can never be shorter than the straight line, so it never overestimates (admissible).
1 mark straight-line/Euclidean distance; 1 mark never overestimates / easy to calculate.
Q10Graphs, Dijkstra & A* · Standard · Paper 3 style · 5 marks- (a) A puzzle game has a 3 × 3 sliding-tile board. Explain how the possible positions of the board can be represented as a graph so that an AI can solve the puzzle. [3]
- (b) Explain why A* with a good heuristic is more suitable than Dijkstra's algorithm for this puzzle. [2]
Show answer
- (a) Each board position (state) is a node; an edge joins two nodes if one legal move changes one position into the other; edges have weight 1 (one move). The AI searches the graph from the start state to the goal state.
1 mark states as nodes; 1 mark legal moves as edges; 1 mark search from start to goal node (each edge cost 1).
- (b) The graph is very large (hundreds of thousands of states); A* uses a heuristic (e.g. number of misplaced tiles) to expand only promising states, so it finds the solution much faster and uses less memory.
1 mark very large search space; 1 mark heuristic reduces nodes expanded / time / memory.
Q11Graphs, Dijkstra & A* · Challenge · Paper 3 style · 8 marksA route planner for a hiking trail network in the Margalla Hills uses this undirected graph (times in minutes):S – A: 5S – B: 7S – C: 4A – D: 6B – D: 3B – E: 6C – E: 9C – F: 7D – G: 8E – G: 6F – E: 4F – T: 14G – T: 3E – T: 9Heuristic h (estimated minutes to T): S 19, A 14, B 13, C 18, D 10, E 9, F 11, G 3, T 0.
- (a) Use the A* algorithm to find the shortest path from S to T. Show g, h and f for every node added to the open list, any updated values, and the order in which nodes are expanded. [6]
- (b) Dijkstra's algorithm makes the nodes permanent in the order S, C, A, B, D, F, E, G, T. Compare this with your answer to part (a) and explain why A* needed to expand fewer nodes. [2]
Show answer
- (a) Expand S: A (5, 14, 19), B (7, 13, 20), C (4, 18, 22).Expand A (f 19): D (11, 10, 21).Expand B (f 20): D improved to (10, 10, 20); E (13, 9, 22).Expand D (f 20): G (18, 3, 21).Expand G (f 21): T (21, 0, 21).Expand T – goal.Order: S, A, B, D, G, T. Path S → B → D → G → T, cost 21.
1 mark f values from S; 1 mark A expanded first; 1 mark D first given f 21 then updated to 20 via B; 1 mark E and G values; 1 mark expansion order; 1 mark path and cost 21.
- (b) A* expanded 6 nodes, Dijkstra 9. The heuristic told A* that C (and F, E) are far from T, so their high f values kept them from being expanded; Dijkstra expands nodes only by distance from S in every direction.
1 mark comparison (6 against 9 nodes, C/E/F not expanded by A*); 1 mark heuristic guides search towards the goal.
Q12Graphs, Dijkstra & A* · Challenge · Paper 3 style · 8 marksA one-way road system in a new housing scheme near Lahore is modelled as a directed weighted graph (travel times in minutes; X → Y means you can only drive from X to Y):P → Q: 4P → R: 6Q → R: 3Q → S: 8R → S: 2R → T: 7S → T: 1S → U: 6T → U: 3U → V: 2T → V: 8R → Q: 1V → S: 1
- (a) Use Dijkstra's algorithm to find the shortest distance from P to every other junction. Show the order in which junctions are made permanent. [5]
- (b) State the shortest route from P to V. [1]
- (c) Explain why there is no route from V back to P. [2]
Show answer
- (a) Order: P (0), Q (4), R (6), S (8), T (9), U (12), V (14).
1 mark Q 4 and R 6 (direct P → R 6 beats P → Q → R 7); 1 mark S 8 via R; 1 mark T 9 via S (not 13 via R); 1 mark U 12 via T and V 14 via U; 1 mark correct order.
- (b) P → R → S → T → U → V (14)
B1.
- (c) The roads are one-way; the only road leaving V goes to S, and no road anywhere leads into P, so P cannot be reached.
1 mark directed edges/one-way; 1 mark no edge enters P.
Q13Graphs, Dijkstra & A* · Challenge · Paper 3 style · 8 marksA water pipeline network between pumping stations near Faisalabad (undirected, lengths in km):A – B: 7A – C: 3A – D: 9B – C: 2B – E: 4C – D: 5C – F: 11D – F: 4E – F: 4E – G: 8F – G: 2
- (a) Apply Dijkstra's algorithm from A. Write the order in which the nodes become permanent and the final distance of each node. [5]
- (b) State the shortest route from A to G. [1]
- (c) Each time a node becomes permanent, the algorithm updates its neighbours. State how many times in total a tentative distance is improved (replaced by a smaller value) during the algorithm. [2]
Show answer
- (a) A 0, C 3, B 5, D 8, E 9, F 12, G 14 (order A, C, B, D, E, F, G).
1 mark C 3 then B 5 (B improved from 7); 1 mark D 8 (improved from 9 via C); 1 mark E 9 via B; 1 mark F 12 via D (14 via C and 13 via E are larger) and G 14 via F; 1 mark correct order.
- (b) A → C → D → F → G (14)
B1.
- (c) 4 times: B (7 → 5), D (9 → 8), F (14 → 12) and G (17 → 14).
Working: from A: B 7, C 3, D 9. From C: B 5 (improved), D 8 (improved), F 14. From B: E 9. From D: F 12 (improved). From E: F 9 + 4 = 13 (not smaller), G 17. From F: G 14 (improved). So 4 improvements: B, D, F, G. 1 mark for listing improvements; 1 mark correct total 4.
Q14Graphs, Dijkstra & A* · Challenge · Paper 4 style · 12 marksThe five-building network from the adjacency matrix below is used to test a shortest-path program. Rows/columns are K, L, M, N, O:K: 0 6 2 0 0L: 6 0 3 4 0M: 2 3 0 9 8N: 0 4 9 0 2O: 0 0 8 2 0
- (a) Write a program that stores the graph in a 2D list Graph (0 = no edge), a function Dijkstra(Start) that returns a list of shortest distances and a list of previous nodes, and a function Route(Previous, Target) that returns the route as a string such as "K-M-L". The main program must output, for every node, its name, its shortest distance from K and its route. Give the test output. (Python shown; Java or VB.NET solutions are equally acceptable.) [12]
Show answer
- (a) INF = 9999Names = ["K", "L", "M", "N", "O"]Graph = [[0, 6, 2, 0, 0], [6, 0, 3, 4, 0], [2, 3, 0, 9, 8], [0, 4, 9, 0, 2], [0, 0, 8, 2, 0]]def Dijkstra(Start): Count = len(Graph) Distance = [INF] * Count Previous = [-1] * Count Visited = [False] * Count Distance[Start] = 0 for Step in range(Count): Current = -1 for Node in range(Count): if not Visited[Node] and (Current == -1 or Distance[Node] < Distance[Current]): Current = Node if Distance[Current] == INF: break Visited[Current] = True for Node in range(Count): Weight = Graph[Current][Node] if Weight > 0 and not Visited[Node]: if Distance[Current] + Weight < Distance[Node]: Distance[Node] = Distance[Current] + Weight Previous[Node] = Current return Distance, Previousdef Route(Previous, Target): Path = Names[Target] while Previous[Target] != -1: Target = Previous[Target] Path = Names[Target] + "-" + Path return PathDistance, Previous = Dijkstra(0)for Node in range(len(Names)): print(Names[Node], Distance[Node], Route(Previous, Node))Test output:K 0 KL 5 K-M-LM 2 K-MN 9 K-M-L-NO 10 K-M-O
Graph stored as 2D list (1); distance list initialised to a large value and start set to 0 (1); previous and visited lists (1); outer loop runs once per node (1); select the unvisited node with the smallest distance (2); mark it visited (1); relax each neighbour with weight > 0, updating distance and previous (2); Route builds the path back from target using previous (1); main loop outputs every node (1); evidence of correct output (1).
Q15Graphs, Dijkstra & A* · Challenge · Paper 3 style · 7 marksA drone in a crop-spraying project in Punjab plans a flight between waypoints (undirected, costs in units of battery):H – J: 2H – K: 6J – K: 3J – L: 8K – M: 4L – M: 2L – N: 3M – N: 7K – P: 9P – N: 5Heuristic h: H 10, J 10, K 9, L 3, M 5, N 0, P 4.
- (a) Use A* to find the shortest path from H to N. Show g, h and f for each node you add to the open list and state the order of expansion. [5]
- (b) Dijkstra's algorithm would make H, J, K, M and L permanent before N. Explain, with reference to the heuristic values, why A* reached N after expanding fewer nodes. [2]
Show answer
- (a) Expand H: J (2, 10, 12), K (6, 9, 15).Expand J (12): K improved to (5, 9, 14); L (10, 3, 13).Expand L (13): M (12, 5, 17); N (13, 0, 13).Expand N (13) – goal.Order H, J, L, N. Path H → J → L → N, cost 13.
1 mark J and K from H; 1 mark K improved to g 5 via J; 1 mark L f 13 chosen before K f 14; 1 mark M and N values; 1 mark order and path/cost 13.
- (b) K and M have large h values (9 and 5) because they lead away from N, giving them f values of 14 and 17, higher than N's 13; A* never expands them, while Dijkstra expands every node closer to H than N.
1 mark K/M high f because of h; 1 mark Dijkstra uses only g (distance from start).
Q16Machine learning & neural networks · Core · Paper 3 style · 4 marks- (a) Explain the difference between artificial intelligence (AI) and machine learning. [2]
- (b) State what is meant by deep learning. [2]
Show answer
- (a) AI is the general ability of a computer system to perform tasks that normally need human intelligence; machine learning is a type of AI in which the system learns from data and improves its performance without being explicitly programmed with rules.
1 mark AI definition; 1 mark ML learns from data / improves with experience without explicit programming.
- (b) A form of machine learning that uses artificial neural networks with many hidden layers to learn complex patterns from large amounts of data (e.g. images, speech).
1 mark neural networks with many (hidden) layers; 1 mark learns features/patterns from large amounts of (unstructured) data.
Q17Machine learning & neural networks · Core · Paper 3 style · 4 marksAn agricultural research institute in Faisalabad uses machine learning to help wheat farmers.
- (a) Describe supervised learning, using an example from this scenario. [2]
- (b) Describe unsupervised learning, using an example from this scenario. [2]
Show answer
- (a) The model is trained on labelled data where the correct output is known, e.g. thousands of leaf photos each labelled 'healthy' or 'rust disease'; it learns to predict the label for new photos.
1 mark labelled training data / known outputs; 1 mark example (labelled leaf photos).
- (b) The model is given unlabelled data and finds patterns or groups (clusters) by itself, e.g. grouping farms into clusters with similar soil readings and yields.
1 mark unlabelled data, finds its own patterns/clusters; 1 mark example.
Q18Machine learning & neural networks · Core · Paper 3 style · 4 marksA bank in Nairobi is building a machine-learning system to detect fraudulent card payments.
- (a) Explain the difference between labelled and unlabelled data. [2]
- (b) Explain why the available data is split into a training set and a test set. [2]
Show answer
- (a) Labelled data includes the correct output/answer for each item (e.g. an email marked 'spam'); unlabelled data has only the inputs, with no known output.
1 mark labelled has known output/tag; 1 mark unlabelled has none.
- (b) The model learns from the training set; the separate test set, which the model has never seen, is used to check how accurately it works on new data (that it has not just memorised the training data).
1 mark training set used to learn/adjust model; 1 mark test set of unseen data measures real accuracy.
Q19Machine learning & neural networks · Core · Paper 3 style · 4 marks- (a) For each task, state whether supervised, unsupervised or reinforcement learning is most suitable: (i) an email filter trained on messages marked 'spam' or 'not spam'; (ii) a program that learns to play a racing game by being given points for finishing laps quickly; (iii) grouping news articles into topics without any topic labels; (iv) predicting house prices in Islamabad from past sales. [4]
Show answer
- (a) (i) supervised (ii) reinforcement (iii) unsupervised (iv) supervised (regression)
1 mark each.
Q20Machine learning & neural networks · Standard · Paper 3 style · 5 marks- (a) Describe how reinforcement learning could be used to train a robot vacuum cleaner to clean a room efficiently. Use the terms agent, environment, action, reward and policy. [5]
Show answer
- (a) The robot is the agent and the room is the environment. In each state the agent chooses an action (move forward, turn, etc.). It receives a reward for cleaning new floor and a penalty (negative reward) for bumping into furniture or re-cleaning. By trial and error it updates its policy – the rule for choosing actions in each state – to maximise the total reward over time.
1 mark each correct use of: agent; environment; action; reward/penalty; policy updated to maximise cumulative reward.
Q21Machine learning & neural networks · Standard · Paper 3 style · 6 marks- (a) Describe the structure of an artificial neural network. [4]
- (b) Explain how artificial neural networks have helped machine learning. [2]
Show answer
- (a) Made of artificial neurons (nodes) arranged in layers: an input layer, one or more hidden layers and an output layer. Each connection between neurons has a weight. Each neuron adds its weighted inputs (plus a bias) and applies an activation function to produce its output, which passes to the next layer.
1 mark each to max 4: input layer; hidden layer(s); output layer; weighted connections; neuron sums weighted inputs + bias; activation function.
- (b) They can learn complex, non-linear patterns directly from large amounts of raw data, such as images or speech, without a programmer defining the rules or features; this has made tasks like face and speech recognition far more accurate.
1 mark learn complex/non-linear relationships or features automatically; 1 mark example/improved accuracy in recognition tasks.
Q22Machine learning & neural networks · Standard · Paper 3 style · 5 marksA single artificial neuron in a fire-alarm system has three inputs x₁, x₂, x₃ (each 0 or 1) with weights 0.6, −0.4 and 0.3, and a bias of −0.5. It outputs 1 if the weighted sum (including the bias) is ≥ 0, and 0 otherwise.
- (a) Calculate the weighted sum and the output of the neuron for the inputs x₁ = 1, x₂ = 0, x₃ = 1. [2]
- (b) Calculate the weighted sum and the output for x₁ = 0, x₂ = 1, x₃ = 1. [2]
- (c) State what happens to the weights during training when the output is wrong. [1]
Show answer
- (a) Sum = 0.4, output 1
M1: 1 × 0.6 + 0 × (−0.4) + 1 × 0.3 − 0.5 = 0.4; A1: 0.4 ≥ 0 so output 1.
- (b) Sum = −0.6, output 0
M1: 0 − 0.4 + 0.3 − 0.5 = −0.6; A1: < 0 so output 0.
- (c) The weights (and bias) are adjusted to reduce the error.
B1.
Q23Machine learning & neural networks · Standard · Paper 3 style · 4 marks- (a) Describe how back propagation of errors is used to train an artificial neural network. [4]
Show answer
- (a) Training data is passed forward through the network to give an output. The output is compared with the expected (labelled) output to find the error. The error is passed backwards through the network, layer by layer, to work out how much each weight contributed to it. Each weight is adjusted (e.g. by gradient descent) to reduce the error, and the process is repeated over many examples/epochs until the error is acceptably small.
1 mark each to max 4: forward pass; compare with expected output to calculate error; error sent backwards from output layer through hidden layers; weights adjusted in proportion to their contribution; repeated many times until error minimised.
Q24Machine learning & neural networks · Standard · Paper 3 style · 4 marksAn online clothing store in Lahore has data about 200 000 customers.
- (a) Describe how unsupervised learning could be used by the store to group its customers, and give one way the store could use the results. [3]
- (b) Explain why supervised learning could not be used for this task at first. [1]
Show answer
- (a) Customer data (purchases, spending, frequency, location) is given to a clustering algorithm without labels; it finds groups of customers with similar behaviour, e.g. 'students buying on discount days'. The store can then send targeted offers or adverts to each group.
1 mark unlabelled customer data; 1 mark algorithm finds clusters of similar customers itself; 1 mark use: targeted marketing/stock planning.
- (b) There are no labels – the groups are not known in advance, so there are no correct answers to train with.
B1.
Q25Machine learning & neural networks · Standard · Paper 3 style · 4 marks- (a) Explain the difference between machine learning and deep learning in the way features are identified. [2]
- (b) Give two reasons why deep learning needs more computing resources than simpler machine-learning methods. [2]
Show answer
- (a) In traditional machine learning a human usually chooses the features to use (e.g. size, colour); in deep learning the many layers of the neural network learn the relevant features automatically from raw data.
1 mark ML: features selected/engineered by people; 1 mark DL: network learns features itself from raw data.
- (b) It has millions of weights to adjust; it needs very large training datasets; training needs many repeated passes (epochs) and powerful GPUs.
1 mark each for any two.
Q26Machine learning & neural networks · Challenge · Paper 3 style · 6 marksA small neural network has inputs A and B (0 or 1). Each neuron outputs 1 if its weighted sum (including bias) is ≥ 0, otherwise 0.Hidden neuron h₁: weights 1 (from A), 1 (from B), bias −0.5Hidden neuron h₂: weights 1 (from A), 1 (from B), bias −1.5Output neuron: weights 1 (from h₁), −2 (from h₂), bias −0.5
- (a) Complete a table showing h₁, h₂ and the output for all four combinations of inputs A and B. [4]
- (b) Identify the logic function that the network carries out, and explain why a network with a hidden layer is needed for it. [2]
Show answer
- (a) A B | h₁ h₂ | Output0 0 | 0 0 | 00 1 | 1 0 | 11 0 | 1 0 | 11 1 | 1 1 | 0
1 mark h₁ column; 1 mark h₂ column; 2 marks output column (1 mark for three correct).
- (b) XOR. The outputs cannot be separated by a single straight line (not linearly separable), so a single neuron cannot do it; the hidden layer combines OR and AND results.
1 mark XOR; 1 mark not linearly separable / needs combination of hidden neurons.
Q27Machine learning & neural networks · Challenge · Paper 3 style · 6 marksAn agricultural extension service in Punjab wants to help farmers who cannot easily reach an expert.
- (a) Explain how deep learning could be used to build a system that identifies crop diseases from photographs taken by farmers' phones. Refer to the data needed, training, testing and use of the system. [6]
Show answer
- (a) Collect a large set of leaf photos labelled by experts with the disease (or healthy). Split into training and test sets. Train a deep neural network with many hidden layers: the images are input as pixel values; early layers learn simple features (edges, colours), deeper layers learn complex features (lesion shapes); back propagation adjusts weights to reduce errors. Test on unseen photos to measure accuracy, and retrain/tune if poor. Deploy in an app: a farmer's photo is fed through the network and the most probable disease is output, with advice. New labelled photos can be used to keep improving it.
1 mark each to max 6: large labelled dataset; training/test split; deep network with many layers learning features automatically; back propagation/weight adjustment; testing on unseen data for accuracy; using the trained model to classify new photos; continued learning / retraining.
Q28Machine learning & neural networks · Challenge · Paper 3 style · 6 marksA tutoring centre in Dubai trained a linear regression model to predict test score (y) from hours of study (x): y = 6x + 38. The data used to test it is:Hours | Actual score2 | 494 | 635 | 667 | 82
- (a) Explain what is meant by regression in machine learning. [2]
- (b) Use the model to predict the score of a student who studies for 6 hours. [1]
- (c) Calculate the mean squared error of the model on the four data points. [3]
Show answer
- (a) A supervised learning method that models the relationship between input variables and a continuous numerical output, so it can predict a value (e.g. a score) for new inputs.
1 mark predicts a continuous/numeric value; 1 mark learned from the relationship in (labelled) training data.
- (b) 74
B1: 6 × 6 + 38 = 74.
- (c) 2.5
M1: predictions 50, 62, 68, 80; M1: errors −1, 1, −2, 2 and squares 1, 1, 4, 4; A1: 10 ÷ 4 = 2.5.
Q29Machine learning & neural networks · Challenge · Paper 3 style · 6 marksA perceptron has two inputs with weights w₁ = 0.2 and w₂ = −0.5, and a bias of 0.1 (treated as a weight on a constant input of 1). It outputs 1 if the weighted sum ≥ 0, otherwise 0. The training rule is: new weight = old weight + η × (target − output) × input, with learning rate η = 0.1. A training example has inputs (1, 1) and target output 1.
- (a) Calculate the output of the perceptron before training for the input (1, 1). [2]
- (b) Use the training rule to calculate the new values of w₁, w₂ and the bias. [3]
- (c) Show that the perceptron now gives the target output for this input. [1]
Show answer
- (a) Output 0
M1: 0.2 × 1 + (−0.5) × 1 + 0.1 = −0.2; A1: < 0 so output 0.
- (b) w₁ = 0.3, w₂ = −0.4, bias = 0.2
Error = 1 − 0 = 1. M1: change = 0.1 × 1 × input. A1: w₁ = 0.2 + 0.1 = 0.3, w₂ = −0.5 + 0.1 = −0.4; A1: bias = 0.1 + 0.1 = 0.2.
- (c) 0.3 − 0.4 + 0.2 = 0.1 ≥ 0, so output 1 = target.
B1.
Q30Machine learning & neural networks · Challenge · Paper 3 style · 6 marksA warehouse robot in Port Qasim is trained by reinforcement learning. Each move costs a reward of −1, reaching the loading bay gives +10, and hitting a shelf gives −10 and ends the episode.Episode 1: 3 moves then reaches the loading bay (rewards −1, −1, −1, +10)Episode 2: 5 moves then reaches the loading bay (rewards −1, −1, −1, −1, −1, +10)Episode 3: 2 moves then hits a shelf (rewards −1, −1, −10)
- (a) Calculate the total reward for each episode and state which episode the agent should learn to repeat. [3]
- (b) Explain the difference between exploration and exploitation in reinforcement learning, and why the agent needs both. [3]
Show answer
- (a) Episode 1: 7; Episode 2: 5; Episode 3: −12. Episode 1 (highest total reward).
1 mark episodes 1 and 2; 1 mark episode 3; 1 mark episode 1 chosen.
- (b) Exploitation: choosing the action currently believed to give the highest reward (e.g. repeating episode 1's route). Exploration: trying new or less-tried actions to discover whether they give more reward. Without exploration the agent may never find a better route; without exploitation it never benefits from what it has learned, so a balance is needed.
1 mark exploitation; 1 mark exploration; 1 mark reason for balance.