Skip to main content
Examonaut

Topic 1

Algorithms and graph theory

An algorithm is a finite set of precise instructions that solves a problem: follow the steps exactly and you get the answer, with no judgement needed. Computers run on algorithms, and so does all of Decision Mathematics. This topic teaches you to read and carry out algorithms in any format, to sort lists and pack bins efficiently, to measure how an algorithm's running time grows, and to speak the language of graphs that the rest of the unit is built on.

What you need to know

  • Understand and implement algorithms given in words (or pseudo code) and as flow charts, recording the steps in a trace table.
  • Carry out a bubble sort and a quick sort, into ascending or descending order.
  • Use the bin packing algorithms: first-fit, first-fit decreasing and full bins; find a lower bound for the number of bins.
  • Understand the order of an algorithm (linear, quadratic, cubic) and use it to estimate run times.
  • Use the language of graphs: vertices, arcs, weights, degree, paths, walks, trails, cycles, Hamiltonian cycles, connected graphs, trees, spanning trees, digraphs, simple graphs, complete graphs, subgraphs and isomorphic graphs.
  • Know and use the handshaking lemma; identify Eulerian and semi-Eulerian graphs.
  • Represent graphs with adjacency matrices and networks with distance matrices.
  • Know what a planar graph is and use the planarity algorithm for graphs with a Hamiltonian cycle.

Key points

  • Follow algorithms in words or flow charts with a trace table; then say what the algorithm does.
  • Bubble sort: compare neighbours, swap, repeat passes until a pass makes no swaps; at most 12n(n−1)\frac{1}{2}n(n - 1) comparisons.
  • Quick sort: the middle item (right of middle if even) is the pivot; smaller items before it in their original order.
  • Bin packing: lower bound = total ÷ capacity, rounded up; first-fit, first-fit decreasing, full bins. Meeting the lower bound proves optimality.
  • Order: time scales with n2n^2 for quadratic, n3n^3 for cubic algorithms.
  • Sum of degrees = 2 × arcs; all even degrees: Eulerian; exactly two odd: semi-Eulerian. Planarity algorithm: chords that cross must go on opposite sides.

Practise this topic

Both are part of Premium.

Next lesson1. Algorithms, flow charts and sorting