Leaving Certificate Applied Mathematics

All books

Chapter 2: Review

The chapter problem, solved

Wiring the new building. Seven rooms, a list of possible cable runs each with a length, and a van that has to travel between two of them by the shortest route. Two questions, one diagram.

The cheapest cabling. A set of cables that reaches every room with no redundant loop is a spanning tree, and every spanning tree on 7 rooms has 7−1=67 - 1 = 6 cables. The question is which 6, and that is Kruskal's or Prim's algorithm.

Run Kruskal: sort the cable runs by length, take each one unless it would close a loop, and stop at 6. The total length is the least possible. Run Prim from any room and you should get the same total — if the two disagree, one run has an arithmetic mistake in it, and finding it is worth the two minutes.

The shortest van route. This is a different question. Use Dijkstra's algorithm from the room the van leaves. Settle the nearest unsettled room, update its neighbours' tentative distances, and repeat until the destination is settled. Trace the route back by following the updates.

Why the two answers differ. The spanning tree connects every room for the least total; the shortest path connects two rooms for the least total. The cheapest set of cables need not contain the shortest route between any particular pair of rooms, and the shortest route is not a set of cables at all — it is a single chain of them. The two totals may happen to be equal on a small network, and that is a coincidence, not a rule.

And if the building were laid out in zones, with the van visiting one room in each zone in turn, that would be a third question. It is a staged network, and backward recursion answers it: start at the last zone, write the cost from each room to the finish, and work back one zone at a time. Dijkstra would give the same answer; backward recursion does less work because it uses the zones.

Mixed practice — choose the method first

Work through these without notes. For each one, decide which kind of problem it is and say why, before you calculate anything. Two of them are deliberately questions you should refuse to answer with the algorithm that first comes to mind.

  1. A network has vertices A,B,C,DA, B, C, D and edges AB=3AB = 3, AC=7AC = 7, BC=2BC = 2, BD=5BD = 5, CD=4CD = 4. Find the minimum spanning tree and its total weight.
  2. For the same network, find the shortest distance from AA to DD and name the route.
  3. For the same network, how many walks of length 2 are there from AA to DD? Write the adjacency matrix first.
  4. A network has degrees 4,4,3,3,2,24, 4, 3, 3, 2, 2. How many edges has it, and how many odd-degree vertices? Does it have an Eulerian trail?
  5. A network has 9 vertices and 12 edges. How many edges must be removed to leave a spanning tree, and what must be true of each edge removed?
  6. A staged network has stages AA; B,CB, C; D,ED, E; FF with edges AB=6AB = 6, AC=3AC = 3, BD=1BD = 1, BE=9BE = 9, CD=4CD = 4, CE=2CE = 2, DF=5DF = 5, EF=7EF = 7. Find the least total cost from AA to FF by backward recursion, and write down the route.
  7. A network has a directed edge of weight −2-2 and a question asks for the shortest path. State which algorithm you would normally use, and why you cannot use it here.
  8. A complete network has 6 vertices. How many edges has it, and how many spanning trees?
  9. A network is stored as an adjacency matrix. Explain how to find the out-degree of a vertex, the in-degree, and whether the network is directed.
  10. A council must connect 12 villages by road for the least total length, and separately must find the shortest route from the depot to the hospital. Explain why these are two different problems and name the algorithm for each.

Answers and concise solutions

1. Show the answer

1. The minimum spanning tree and its total weight

Answer: Sort the edges by weight: BC=2BC = 2, AB=3AB = 3, CD=4CD = 4, BD=5BD = 5, AC=7AC = 7. Kruskal takes BCBC and ABAB, which join AA, BB and CC. It takes CDCD next, which brings in DD, and stops with three edges. The tree is BCBC, ABAB, CDCD, and its total weight is 2+3+4=92 + 3 + 4 = 9. It is minimal because each edge left out is at least as heavy as every edge on the cycle it would close: AC=7AC = 7 closes AA–BB–CC, whose heaviest edge is 33, and BD=5BD = 5 closes BB–CC–DD, whose heaviest edge is 44. No swap can lower the total.

2. Show the answer

2. The shortest distance and the route

Answer: The simple routes from AA to DD are AA–BB–DD, which is 3+5=83 + 5 = 8; AA–CC–DD, which is 7+4=117 + 4 = 11; and AA–BB–CC–DD, which is 3+2+4=93 + 2 + 4 = 9. The least is 88, along AA–BB–DD. Dijkstra settles AA, then BB at 33 and CC at 77, and the update from BB gives D=8D = 8; the route is read back from that update.

3. Show the answer

3. The number of walks of length 2

Answer: With the order A,B,C,DA, B, C, D the adjacency matrix has a 11 wherever an edge joins two vertices. Row AA is (0,1,1,0)(0, 1, 1, 0) and column DD is (0,1,1,0)(0, 1, 1, 0). The entry of A2A^2 in row AA, column DD is the dot product of those two: 0×0+1×1+1×1+0×0=20 \times 0 + 1 \times 1 + 1 \times 1 + 0 \times 0 = 2. The two walks are AA–BB–DD and AA–CC–DD.

4. Show the answer

4. The edges, the odd vertices and the trail

Answer: The handshake lemma says the degree sum is twice the number of edges, so the network has (4+4+3+3+2+2)÷2=18÷2=9(4 + 4 + 3 + 3 + 2 + 2) \div 2 = 18 \div 2 = 9 edges. Two of the vertices have odd degree. A connected network has an Eulerian trail when it has exactly 0 or 2 odd-degree vertices, so this one has a trail, and it must start at one degree-3 vertex and finish at the other.

5. Show the answer

5. How many edges to remove, and which

Answer: A spanning tree on 9 vertices has 9−1=89 - 1 = 8 edges, so 12−8=412 - 8 = 4 edges must be removed. Each removed edge must lie on a cycle: removing an edge that carries the only route between two parts would disconnect the network and leave no spanning tree.

6. Show the answer

6. The least total cost and the route

Answer: Work back one stage at a time. From DD the cost to FF is 55, and from EE it is 77. From BB the cheaper way on is through DD: min⁡(1+5, 9+7)=6\min(1 + 5,\ 9 + 7) = 6. From CC both ways cost 99: min⁡(4+5, 2+7)=9\min(4 + 5,\ 2 + 7) = 9. From AA the cost is min⁡(6+6, 3+9)=12\min(6 + 6,\ 3 + 9) = 12. The least total cost is 1212, and one route that achieves it is AA–BB–DD–FF.

7. Show the answer

7. The algorithm and why it fails

Answer: You would normally use Dijkstra's algorithm. It settles the nearest unsettled vertex and never reopens it, which is safe only when adding another edge cannot make a route cheaper. With an edge of weight −2-2, a route with more edges can cost less, so a settled distance can be wrong. The algorithm would return a number, and that number would not be the shortest path.

8. Show the answer

8. The edges and the spanning trees

Answer: Every pair of vertices is joined, so the number of edges is 6×52=15\dfrac{6 \times 5}{2} = 15. Cayley's formula says a complete network on nn vertices has nn−2n^{n-2} spanning trees, so here it is 64=12966^{4} = 1296. The divide by 2 in the edge count is there because each edge is counted once from each end.

9. Show the answer

9. How to read the three facts

Answer: The out-degree of a vertex is the sum of its row, because the row holds the edges that leave it. The in-degree is the sum of its column, because the column holds the edges that arrive. The network is undirected exactly when the matrix is symmetric: every entry above the diagonal equals its mirror below it. If any pair of mirror entries differs, the network is directed.

10. Show the answer

10. The two problems and their algorithms

Answer: The first problem connects every village for the least total length, so its answer is a spanning tree: 11 roads, with no loop. Kruskal's algorithm or Prim's algorithm finds it. The second connects two named places, so its answer is one path, and the roads elsewhere do not matter. Dijkstra's algorithm finds it. The cheapest set of roads need not contain the shortest route between any particular pair, so one answer does not give the other.

What you can now do

Thinking back

Look at the route you chose at the start of the chapter — the bus that takes a particular way, the delivery that reaches your area on a particular day, the signal that reaches your house by one cable rather than another.

You can now model it. Draw the places as vertices and the connections as edges, and put a number on each edge — distance, or time, or cost, whichever the question is really about. Then decide which question you are asking. Is it "how do I connect everything cheaply", or "how do I get from here to there cheaply"? They are different, and the answer to one is not the answer to the other.

Write down which algorithm you would use and why. If your model is rough — you are not sure of the numbers, or of which connections exist — that is worth writing down too. Deciding what to leave out is what makes a model useful, and saying what you left out is part of the applied mathematics, not an apology for it. It is also exactly what the modelling project asks you to do.

Settings

Colour scheme

Light or dark pages. Your colour and layout stay the same.

Colour

The paper, ink and lettering. Your layout stays the same.

Quiet colours
Bold colours
Layout

How pages are arranged. Your colours stay the same.

Reading offline

Keep this book on this device and read it offline.