Artificial Intelligence (AI)

Computer Science A2 · Artificial Intelligence (AI). The idea in plain words, the rules to remember, the mistake to avoid and a worked example, written and checked by Mega Lecture.

Test this topic freeAll Computer Science A2 topics

The idea

A graph is a set of vertices (nodes) joined by edges. Edges can have a direction and a weight, such as a distance or a cost. AI uses graphs to model routes, game positions and links between ideas, then searches them for the best path. Dijkstra's algorithm and the A* algorithm both find the shortest path.

In machine learning a program improves from data instead of following fixed rules written by a programmer. An artificial neural network has an input layer, one or more hidden layers and an output layer. Each connection has a weight, and training adjusts the weights.

Deep learning uses networks with many hidden layers and very large data sets.

In simpler words

A graph is a set of points joined by lines. The lines can have weights, like distances. AI uses graphs to find the best route. Dijkstra's algorithm and A* both find the shortest path. In machine learning, a program gets better by learning from data instead of fixed rules. A neural network has layers of nodes. Training changes the weights between them.

An everyday comparison

A* is like using a map app. It counts how far you have travelled and adds a guess of how far is left, then follows the most promising road. Dijkstra is like checking every nearby road before going further. The comparison stops working because A* only gives the shortest path if its guess never overestimates the true distance left.

Rules to remember

Common mistake

In Dijkstra's algorithm students stop at the first route that reaches the target. A route with more edges can have a smaller total, so keep updating distances until the target is the vertex with the smallest distance still unvisited.

In the exam

For Dijkstra, show a table of vertices with current shortest distance and previous vertex. At each step visit the unvisited vertex with the smallest distance and update its neighbours. Keep going until the target is chosen, then give the path and total. For A*, write f(n) = g(n) + h(n) and show the values. For learning methods, define supervised, unsupervised and reinforcement learning. For back propagation, describe comparing output with expected output and adjusting weights to reduce the error.

Worked example

A weighted undirected graph has edges A–B 3, A–C 1, B–C 1, B–D 4, C–D 6. Use Dijkstra's algorithm to find the shortest distance from A to D.

  1. Start: A = 0. From A: B = 3, C = 1. Smallest unvisited is C (1).
  2. Visit C: B = 1 + 1 = 2, which is less than 3, so B becomes 2. D = 1 + 6 = 7.
  3. Smallest unvisited is B (2). Visit B: D = 2 + 4 = 6, which is less than 7, so D becomes 6.
  4. D is now the only unvisited vertex, so its distance is final.

Answer: 6, along the path A, C, B, D.

Ask about this

Type what you are stuck on. The helper finds the explanation, worked examples and the notes to read, free and instant.

Keep going

← Encryption, Encryption Protocols and Digital CertificatesAlgorithms →Take a Computer Science A2 test