Skip to content

graphs and their words

shapes of data

what it is

A map here is places joined by roads. This page names its parts, counts its roads, and finds how few roads hold it together.

Books call a map a graph: a place is a vertex or a node, and a road is an edge. Here two places have at most one road between them. No road runs from a place to itself. The map below has 6 places and 7 roads.

ABCDEF
A map of 6 places, A to F, and 7 roads. Every road runs both ways.

A road runs both ways unless it is drawn with a head. Then it runs one way only, toward its head. Roads that run one way make a directed graph. There, two places may have one road each way.

A place's degree is the number of roads that end at it. Above, B has degree 3: roads to A, D and E. On one-way roads, count the roads in and the roads out apart. Question 1 below adds the degrees up.

K2G1H2J0
Five one-way roads, each running toward its head. Above each place, its roads out. They add to 5.
K0G2H1J2
The same map, its roads in written above each place. G has 2, from K and from H. These add to 5 too, one for each road.

A path is places one after another, each joined to the next by a road, with no place twice. Its length is its roads, not its places. When roads carry lengths, numbers such as kilometres written on them, a path's length is those numbers added up instead. A cycle comes back to its first place at the end, with no other place twice and no road twice. A, B, A is no cycle: it takes the road A to B twice.

4235216ABCDEF
The path A, B, D, F, drawn heavy. It is 3 roads long, or 4 + 3 + 2 = 9 by the lengths. A, C, E, F is 3 roads too, but its lengths add to 8.
ABCDEF
The cycle B, D, F, E and back to B, drawn heavy. It is 4 roads long.

On two-way roads, a piece is all the places you can travel between, so no road leads out of it. A map in one piece is connected. Books call a piece a connected component. Question 3 below finds how few roads one piece needs.

ABCDEFG
A map in two pieces. A, B, C and D, filled, reach one another. E, F and G reach one another. No road joins the two.

A map is dense when it holds nearly every road it could, and sparse when it has only a few times as many roads as places. Question 2 below counts the most it could hold. On small maps the two words overlap: 5 places with every road have 10 roads, only 2 times the places. They tell big maps apart, as the table below shows.

A4B4C4D4E4
Every road. 5 places, every two joined, 10 roads, the most they can hold. Each place has degree 4.
A2B2C2D2E2
Few roads. The same 5 places in a ring, 5 roads, as many as places. Each place has degree 2.
placesmost roads3 times the places
51015
72121
501,225150
1,000499,5003,000
The most roads a map can hold, every two places joined, against 3 times as many roads as places, 3 standing for a few. They meet at 7 places. Below that, 3 times the places is more roads than the map can hold. Above it, the two grow far apart.

where the formulas come from

Each question is worked out one numbered line at a time. A line shows the move it makes, the line itself, and why the move is allowed. A line either follows from the lines above it, or brings in something the question needs, such as how the method works, a small fact about nn, or a result from another page, with its own reason. Press 'hide the lines, then guess each one' to cover the lines and uncover them one by one, guessing each before you see it.

question 1A map has mm roads. What do the degrees of its places add to?
  1. the move: count each road at both ends

    the line:
    S=2+2+⋯+2S = 2 + 2 + \dots + 2
    A2B3C2D2E3F2
    The map of 6 places, each place's degree written above it.

    why it is allowed: Let SS be the degrees added up. Every road has two ends, and it counts once at the place on each end, 2 in all. So mm roads give mm twos, the dots standing for the twos not written. For 7 roads, 7 twos.

  2. the move: add the twos

    the line:
    S=2mS = 2m

    why it is allowed: mm twos make twice mm.

  3. the move: read it

    the line:
    7 roads:degrees add to 14\begin{gathered} 7 \text{ roads:} \\ \text{degrees add to 14} \end{gathered}
    placedegree
    A2
    B3
    C2
    D2
    E3
    F2
    all14
    The degrees of the 6 places, added. 14 is twice the 7 roads.

    why it is allowed: The map has 7 roads, and its degrees add to 14, twice 7.

  4. the move: odd degrees come in pairs

    the line:
    places of odd degree:an even number of them\begin{gathered} \text{places of odd degree:} \\ \text{an even number of them} \end{gathered}

    why it is allowed: Line 2's total is twice mm, so it is even. In line 3's table, 14 is 8 from the even degrees and 6 from the odd ones, B's and E's. 14 and 8 are even, so 6 is too. Odd numbers add to an even number only in pairs. 3 + 3 is 6, but 3 + 3 + 1 is 7.

try it with a small mm: at m=7m = 7, line 1 gives S=14S = 14, which you can work out by hand

question 2nn places, every two joined by a road. How many roads?
  1. the move: count place by place

    the line:
    R=(n−1)+⋯+2+1R = (n - 1) + \dots + 2 + 1
    ABCDE
    Every two of 5 places joined. A has 4 roads, B 3 more, C 2 more, D 1 more, E none new. 4 + 3 + 2 + 1 = 10.

    why it is allowed: Let RR be the roads, for 2 places or more. List the places. The first has roads to the n−1n - 1 after it. The next adds one fewer new road, as its road to the first is counted already. Each adds one fewer, and the last adds none.

  2. the move: use adding up 1 to n

    the line:
    R=n(n−1)2R = \frac{n(n - 1)}{2}
    placenew roads
    A4
    B3
    C2
    D1
    E0
    all10
    The new roads each place adds on line 1's map, in turn. 4 + 3 + 2 + 1 + 0 = 10.
    where does this come from?
    question 1 of the page adding up 1+2+⋯+n1 + 2 + \dots + nFit two staircases of squares together. What shape do they make?
    1. the move: draw the sum as a staircase

      the line:
      S=1+2+⋯+nS = 1 + 2 + \dots + n

      why it is allowed: Let SS be the sum of the whole numbers from 1 to nn. Draw it as a staircase, a column for each number: 1 square, then 2, and so on up to nn. For 5, columns of 1, 2, 3, 4 and 5 hold 15 squares.

    2. the move: take two staircases

      the line:
      2S=2(1+2+⋯+n)2S = 2(1 + 2 + \dots + n)

      why it is allowed: Two staircases hold twice the squares. Doubling both sides of line 1 keeps it true.

    3. the move: fit them into a rectangle

      the line:
      2S=n(n+1)2S = n(n + 1)
      Blue stands, yellow hangs. Two staircases of 1 to 5 squares fill a rectangle 5 wide and 6 tall, 30 squares. So 1 + 2 + 3 + 4 + 5 is 5 times 6, halved, which is 15.

      why it is allowed: Stand one staircase with its tallest column on the left. Hang the other upside down from the top, its tallest column on the right, as in the picture. The first column holds nn standing and 1 hanging. Each column to the right, the standing one loses a square and the hanging one gains one. So every column holds n+1n + 1, and the nn columns fill a rectangle nn wide and n+1n + 1 tall.

    4. the move: halve both sides

      the line:
      S=n(n+1)2S = \frac{n(n + 1)}{2}

      why it is allowed: Halving both sides of line 3 keeps it true and leaves one SS. For 5, half of 30 is 15.

    the whole page: adding up 1+2+⋯+n1 + 2 + \dots + n

    why it is allowed: Read from right to left, line 1 is 1 + 2 + up to n−1n - 1. The box under this line adds 1 up to a last number with two staircases, that number times one more, halved. Here the last number is n−1n - 1. One more than it is nn, so RR is n−1n - 1 times nn, halved. For 5, 1 + 2 + 3 + 4 is 4 times 5, halved, which is 10.

  3. the move: one way, each pair holds two

    the line:
    one way:U is twice R\begin{gathered} \text{one way:} \\ U \text{ is twice } R \end{gathered}

    why it is allowed: Let UU be the most one-way roads. A to B and B to A are two roads, one each way, so each pair holds two.

  4. the move: double line 2

    the line:
    U=2R=n(n−1)U = 2R = n(n - 1)

    why it is allowed: Line 3 says UU is 2R2R, and twice line 2 is n(n−1)n(n - 1). For 5 places, 20.

  5. the move: read it

    the line:
    5 places: 10 roads, or 20 one way1,000 places: 499,500 roads\begin{gathered} 5 \text{ places: 10 roads, or 20 one way} \\ 1{,}000 \text{ places: } 499{,}500 \text{ roads} \end{gathered}

    why it is allowed: 1,000 times 999, halved, is 499,500. A map of 1,000 places with 3,000 roads has 3 times as many roads as places, a few, so it is sparse. It holds 3,000 of the 499,500 it could.

try it with a small nn: at n=5n = 5, line 1 gives R=10R = 10, which you can work out by hand

question 3nn places in one piece, on two-way roads. How few roads can join them?
  1. the move: start with no roads

    the line:
    no roads:n pieces\begin{gathered} \text{no roads:} \\ n \text{ pieces} \end{gathered}

    why it is allowed: With no roads, each place is a piece on its own.

  2. the move: a road joins two pieces at most

    the line:
    each road:at most one piece fewer\begin{gathered} \text{each road:} \\ \text{at most one piece fewer} \end{gathered}
    ABCDEFG
    7 places and 6 roads, yet two pieces. Laid after A to B, A to C and B to D, the road C to D joins two places already in one piece, so it joins nothing new.

    why it is allowed: A road between two pieces makes them one. A road inside one piece joins nothing new.

  3. the move: count the pieces left

    the line:
    after k roads:at least n−k pieces\begin{gathered} \text{after } k \text{ roads:} \\ \text{at least } n - k \text{ pieces} \end{gathered}
    roads laidroadpieces
    0none yet7
    1A to B6
    2A to C5
    3B to D4
    4C to D4
    5E to F3
    6E to G2
    The 7 places above, their 6 roads laid one at a time. The fourth, C to D, takes no piece away. 6 roads leave 2 pieces.

    why it is allowed: Lay the roads one at a time, and let kk be how many are laid. Start at nn pieces and take off at most 1 for each road.

  4. the move: ask for one piece

    the line:
    one piece:n−k is at most 1\begin{gathered} \text{one piece:} \\ n - k \text{ is at most 1} \end{gathered}

    why it is allowed: Line 3's pieces can be 1 only if n−kn - k is 1 or less.

  5. the move: turn it round

    the line:
    k is at least n−1\begin{gathered} k \text{ is at least } n - 1 \end{gathered}

    why it is allowed: When n−kn - k is at most 1, kk falls short of nn by at most 1. So fewer than n−1n - 1 roads always leave two pieces or more. For 6 places, 4 roads take off at most 4 of the 6 pieces, so at least 2 are left.

  6. the move: a line of places is enough

    the line:
    join each place to the next:n−1 roads, one piece\begin{gathered} \text{join each place to the next:} \\ n - 1 \text{ roads, one piece} \end{gathered}
    ABCDEF
    6 places, each joined to the next, drawn heavy. 5 roads hold them in one piece.

    why it is allowed: Each place after the first has one road back to the one before it. That is n−1n - 1 roads, and every place reaches the first.

  7. the move: the fewest

    the line:
    R=n−1R = n - 1

    why it is allowed: Let RR be the fewest roads. Line 5 says no fewer than n−1n - 1 will do, and line 6 that n−1n - 1 do.

try it with a small nn: at n=6n = 6, line 7 gives R=5R = 5, which you can work out by hand

a worked example

Read a map of 5 places.

  1. Its roads: V to X, V to Y, V to Z, W to X, W to Y and W to Z. That is 6 roads.
  2. Degrees: V 3, W 3, X 2, Y 2, Z 2. They add to 12, twice 6, as question 1 says.
  3. V and W have odd degree: two places, an even number.
  4. A path from V to W: V, X, W. It is 2 roads long.
  5. A cycle: V, X, W, Y and back to V. It is 4 roads long.
  6. Every place reaches every other, so the map is one piece. It has 6 roads, more than the 4 one piece needs.
V3W3X2Y2Z2
The map of 5 places, each degree written above it, and the cycle V, X, W, Y drawn heavy.

the trap

check yourself

  1. A map has 8 places, every two joined by a road. How many roads does it have?

    the answer

    By question 2, 8 times 7, halved, which is 28. Each place has degree 7, and the 8 degrees add to 56, twice 28.

  2. Can a map have places of degrees 3, 3, 2, 2 and 1?

    the answer

    No. They add to 11, which is odd. By question 1, the degrees always add to twice the roads, an even number.

  3. A map has 9 places and 7 roads. Can it be in one piece?

    the answer

    No. By question 3, one piece of 9 places needs at least 8 roads. With 7, at least two pieces are left.