Menu
Sign up Sign in

AI HL · AHL 1

Graph Theory

AHL 1.6

Weighted graphs and shortest routes

AHL 1.6

Weighted graphs and shortest routes

Target: I can write the weighted adjacency table of a weighted graph, undirected or directed. (+4 more)

By the end of this section

Key points

Weighted graphs and tables

  • A weighted graph has a number on each edge. The weight can be a distance, a time or a cost.
  • In a weighted adjacency table the entry in row X, column Y is the weight of the edge from X to Y. A dash means there is no edge.
  • An undirected graph gives a symmetric table: each edge appears twice, once above and once below the diagonal.
  • A directed graph gives a table that is not symmetric. Row = the vertex the arrow leaves, column = the vertex it reaches.

Drawing a graph from a table

  • Draw one vertex for each row. For an undirected graph, read each edge once from the entries above the diagonal.
  • For a directed graph, every number in the table is one arrow, so read the whole table.
  • Check your drawing: add up the weights, or count the edges at one vertex, and compare with the table.

Shortest and cheapest routes

  • A route does not visit a vertex twice. Its length is the sum of the weights along it.
  • List every route from the start to the finish, add the weights, and choose the smallest total.
  • The route with the fewest edges is not always the shortest.
  • If an edge is closed, cross out every route that uses it. Your list shows the new shortest route.
  • A table of costs is a weighted graph. Read it as a graph, then find the cheapest route in the same way.

Worked examples

Problems like the ones in class. Pick one, try it, then open the working.
A table from a weighted graph

The graph shows the distances in km along the roads between five villages. Write down the weighted adjacency table.

75689411ABCDE
Working
  1. Set up

    Rows and columns A, B, C, D, E

    Row = the vertex you leave, column = the vertex you reach. Put a dash on the diagonal: no road joins a village to itself.

  2. Fill in each road twice

    AB = 7 goes in row A, column B and in row B, column A

    The graph is undirected, so the table is symmetric. Use a dash where there is no road, such as A–C.

  3. ABCDEA–7–6–B7–5811C–5––4D68––9E–1149–
    The table

    Table below

    Check: each row's non-dash entries match the weights on the edges at that vertex.

  4. Check the sum

    50 × 2 = 100

    The roads add to 50. Every road is in the table twice.

Video walkthrough coming
A weighted directed graph from a table

The table shows the weighted adjacency table of a directed graph. Each entry is the weight of the arrow from the row vertex to the column vertex. A dash means there is no arrow. Draw the graph.

ABCDA–58–B–––3C–6––D7–4–
Working
  1. Read row A

    A → B (5), A → C (8)

    Each row lists the arrows leaving that vertex. Row A has two numbers, so two arrows leave A.

  2. Read the other rows

    B → D (3); C → B (6); D → A (7), D → C (4)

    Go along each row. Every number is one arrow from the row vertex to the column vertex.

  3. 583674ABCD
    Draw it

    Draw A, B, C, D, then each arrow with its weight

    The table is not symmetric, so the arrows have a direction. Put the head at the column vertex.

  4. Add the weights

    5 + 8 + 3 + 6 + 7 + 4 = 33

    There are 6 arrows, one for each number in the table.

Video walkthrough coming
The shortest route

The graph shows the times, in minutes, along the roads between a depot S and a shop T. Find the shortest route from S to T and its length.

914812101464SABCDT
Working
  1. List every route

    S–B–D–T = 20; S–C–T = 23; S–C–D–T = 25

    Start at S and never visit a vertex twice. Add the weights along each route.

  2. Keep going

    S–A–C–T = 36; S–A–C–D–T = 38; S–B–D–C–T = 42

    There are 6 routes in all. Writing them in a list stops you missing one.

  3. Compare

    Smallest total: 20 (route S–B–D–T); the next is 23

    Choose the smallest total. Here it is unique.

  4. 914812101464SABCDT
    Answer

    Shortest route S–B–D–T, length 20 minutes

    The route is in bold.

Video walkthrough coming
A road is closed

The graph shows the distances, in km, along the roads between a farm S and a market T. (a) Find the shortest route from S to T. (b) The road S–A is closed. Find the new shortest route and its length.

121110824138SABCDT
Working
  1. All routes

    S–A–D–T = 14; S–B–T = 22; S–A–D–C–T = 33; S–B–C–D–T = 33 | S–B–C–T = 36; S–A–D–C–B–T = 41

    List every route and add the weights.

  2. 121110824138SABCDT
    Part (a)

    S–A–D–T, length 14 km

    The smallest total. It uses the road that will close.

  3. Remove the closed road

    Cross out S–A. Routes left: S–B–T = 22; S–B–C–D–T = 33; S–B–C–T = 36

    Delete every route that uses the closed road. Do not search again from nothing.

  4. 12111082138SABCDT
    Part (b)

    New shortest route S–B–T, length 22 km

    The journey is 8 km longer than before.

Video walkthrough coming
The cheapest route from a table

The table shows the cost, in £, of the direct flight between six airports. A dash means there is no direct flight. Find the cheapest way to travel from A to F, and its cost.

ABCDEFA––––45–B––51502836C–51––1621D–50––3911E45281639––F–362111––
Working
  1. Read the table as a graph

    Each number is a weighted edge

    A has only one direct flight, to E. Every route from A starts A–E.

  2. List the routes

    A–E–C–F = 82; A–E–D–F = 95; A–E–B–F = 109; A–E–B–D–F = 134; A–E–B–C–F = 145 | A–E–C–B–F = 148; A–E–D–B–F = 170; A–E–C–B–D–F = 173; A–E–D–B–C–F = 206

    Follow the numbers along rows and columns. Do not visit an airport twice.

  3. Cheapest

    A–E–C–F costs £82

    Take the smallest total.

Video walkthrough coming