Module 24 of 47Lesson 1 of 8 · HL · Graphs & algorithms 1 · Graphs, vertices & degree
1
Graphs & algorithms · Essential understanding 1

Graphs, vertices & degree

IB AI AHL 3.14with Prof. Kitso
💻 Using the TI-Nspire CX Student Software on a laptop
  • The screens in these notes are drawn exactly as the Student Software shows them. The keypad on the left of the software works like the handheld — click its keys with the mouse.
  • menu: click menu on the on-screen keypad (or Documents Toolbox ▸ 🔧). The menu numbers and letters are the same as in these notes.
  • enter = Enter  ·  tab = Tab (next box)  ·  esc = Esc  ·  del = Backspace.
  • Powers: type ^ (Shift+6), the power, then press → to come back down before typing more. x² = ^2 then →.
  • Fraction: type /  ·  √: type sqrt(  ·  π: type pi  ·  eˣ: type exp(  ·  store: type :=. For EE (×10ⁿ) and i, click them on the keypad.
  • New page: Ctrl+I (or the Insert menu)  ·  change page: Ctrl+← / Ctrl+→  ·  graph entry line: Ctrl+G  ·  var: Ctrl+L.
  • Radian / Degree: click Settings in the status bar at the bottom of the window. The mode (RAD or DEG) shows in the top bar.
  • IB exam mode (Press-to-Test): everything in these notes works on the non-CAS TI-Nspire with the IB exam settings. In exam mode there are no dot-product, cross-product, unit-vector or eigenvalue keys and no Diff Eq graphs — the notes show the allowed way (type the components, use polyRoots on the characteristic equation, do Euler steps on a Calculator page).
  • If you type nDeriv(, the software shows it as centralDiff( — it is the same command.
The big idea: A graph is a picture of connections: dots called vertices joined by lines called edges. The degree of a vertex is how many edges meet there, and the degrees of any graph always add up to twice the number of edges.
By the end of this lesson you can:
  • name the parts of a graph: vertices, edges, adjacent vertices, degree, loops and multiple edges
  • recognise a simple, complete, connected and weighted graph, a subgraph and a tree
  • use sum of degrees = 2 × number of edges and the edge count of a complete graph
  • work with directed graphs: in-degree, out-degree and strongly connected
  • turn a real situation (roads, flights, matches) into a graph
🧑🏾 Imagine this…
Look at a bus map of Botswana. You do not care how bendy the road from Gaborone to Francistown is, or where the trees are. You only care which towns are joined. Rub out everything else and you are left with dots (towns) and lines (roads). That stripped-down picture is a graph. Graph theory is the maths of such pictures, and it powers satnav routes, delivery planning and even internet search.
Graph
a set of vertices (dots, also called nodes) joined by edges (lines). Only the connections matter, not how you draw them.
Adjacent
two vertices are adjacent if an edge joins them directly. In the graph below, A and B are adjacent but B and F are not.
Degree of a vertex
the number of edges that meet at the vertex. A loop (an edge from a vertex to itself) counts twice.
Simple graph
no loops and no two edges joining the same pair of vertices.
Complete graph
a simple graph on vertices where every pair of vertices is joined by an edge.
Connected graph
you can get from any vertex to any other by following edges. If not, the graph is in separate pieces.
Subgraph
a graph made from some of the vertices and some of the edges of a bigger graph.
Tree
a connected graph with no cycles (no closed loop of edges that returns to its start without repeating a vertex).
Weighted graph
each edge carries a number (the weight): a distance, a cost or a time.
Directed graph (digraph)
each edge has a direction (an arrow), such as a one-way street. Out-degree = arrows leaving a vertex, in-degree = arrows arriving.
Strongly connected
a directed graph where you can get from any vertex to any other by following the arrows.
Adeg 3Ddeg 2Edeg 3Cdeg 3Bdeg 2Fdeg 1
A simple connected graph with 6 vertices and 7 edges. The degree of each vertex is written beside it. The degrees add up to 3 + 2 + 3 + 2 + 3 + 1 = 14, which is 2 × 7.
ABCDcomplete (K4)ABCDEa treeABCnot simpleABCdirected
Four kinds of graph. The complete graph K4 has every pair joined. The tree is connected with no cycle. The third graph has a double edge and a loop, so it is not simple. The last graph is directed: each edge is an arrow.
★ Facts you must know
  • Handshaking lemma: the sum of all the degrees (number of edges). Every edge has two ends, so it is counted twice.
  • So the sum of degrees is always even, and the number of vertices with odd degree is always even.
  • Complete graph: has edges, and every vertex has degree .
  • Tree: a tree with vertices has exactly edges.
  • Directed graph: (sum of in-degrees) (sum of out-degrees) number of edges.
⚠️ Watch out
  • A graph is not a function graph. There are no axes. Two drawings that look different can be the same graph if the same vertices are joined.
  • A loop adds 2 to the degree, not 1.
  • Connected and complete are different words. A path A–B–C is connected but not complete (A and C are not joined).
  • In a directed graph, strongly connected needs a route in both directions between every pair, following the arrows.
🧪 Try it yourselfTree or not a tree?
A tree is connected with no cycle, and with vertices it has exactly edges. Count the vertices and edges, then decide.

Worked examples

Example 1.1Degrees and the handshaking lemma
The graph shows six villages A–F and seven roads.
Adeg 3Ddeg 2Edeg 3Cdeg 3Bdeg 2Fdeg 1
  1. (a) Write down the degree of each vertex.
  2. (b) Show that the sum of the degrees equals twice the number of edges.
  3. (c) List the vertices of odd degree and the vertices adjacent to E.
🧠 Think it through
  1. Degree = how many edges touch the vertex. Go vertex by vertex and count the lines.
  2. Add all six degrees. Then count the edges on the picture and double it.
  3. Odd degree means 1, 3, 5 … Adjacent to E means joined directly to E.
✍️ By hand
A: AB, AC, AD .   B: AB, BC .   C: AC, BC, CE .   D: AD, DE .   E: CE, DE, EF .   F: EF .
Sum and ✓
✅ Answer (a) A 3, B 2, C 3, D 2, E 3, F 1. (b) The degrees add to 14 and there are 7 edges, so 14 = 2 × 7. (c) Odd degree: A, C, E, F (four of them, an even number, as it must be). Adjacent to E: C, D and F.
Command term show that: write both sides of the equation and finish with “so they are equal”.
Example 1.2Is this graph possible?
Decide, with a reason, whether each simple graph can exist, and answer the last two parts.
  1. (a) A graph with six vertices of degrees 3, 3, 2, 2, 2, 1.
  2. (b) A graph with 7 vertices, each of degree 4: how many edges does it have?
  3. (c) A complete graph has 45 edges. How many vertices does it have?
  4. (d) What is the degree of every vertex of that complete graph?
🧠 Think it through
  1. Add the degrees. The total must be even, because it equals 2 × edges.
  2. Edges .
  3. A complete graph has edges. Set that equal to 45 and solve for .
✍️ By hand
(a) , which is odd.
(b) , so edges .
(c) (a vertex count cannot be negative).
🔢 On your TI-Nspire CX II
  1. For (c) you can also solve with the calculator. Type nSolve(n*(n-1)/2=45,n=8) and press enter ↵💻 Enter. The guess n = 8 steers it to the positive answer.
    📍 Where to find it on the TI-Nspire
    nSolve( is in menu💻 click menu on keypad▸3: Algebra▸1: Numerical Solve
    1.1*DocRADnSolven·(n−1)2=45,n=810.
✅ Answer (a) Impossible: the degrees add to 13, which is odd, but the sum of degrees must be even. (b) 14 edges. (c) 10 vertices. (d) Each vertex has degree 9.
Never leave a quadratic answer as “n = 10 or n = −9”. A number of vertices must be a positive whole number, so say which root you reject and why.
Example 1.3Naming a graph and its parts
Graph H has five vertices P, Q, R, S, T. There is one edge each for PQ, RS, SP and ST, and two edges between Q and R.
PQRST
  1. (a) Is H simple? Is it connected? Is it complete?
  2. (b) Find the degree of each vertex and check the handshaking lemma.
  3. (c) Draw a subgraph of H that is a tree containing all five vertices.
🧠 Think it through
  1. Simple means no loop and no repeated edge. Look for the double edge.
  2. Connected: can you get from every vertex to every other? Complete needs every pair joined (10 pairs for 5 vertices).
  3. A tree on 5 vertices needs 4 edges and no cycle. Keep the graph connected but break every cycle.
✍️ By hand
P: PQ, SP .   Q: PQ and two QR .   R: two QR and RS .   S: RS, SP, ST .   T: ST .
Sum ✓ (there are 6 edges).
Tree: keep PQ, QR (just one of the two), RS and ST. This path P–Q–R–S–T has 4 edges and no cycle.
✅ Answer (a) Not simple (double edge QR). Connected: yes. Complete: no (for example P and R are not joined, and a simple complete graph on 5 vertices needs 10 edges). (b) P 2, Q 3, R 3, S 3, T 1; the sum is 12 = 2 × 6 edges. (c) A path such as PQ, QR, RS, ST is a spanning tree (a subgraph with 5 vertices, 4 edges, no cycle).
A tree that contains all the vertices of the graph is called a spanning tree. Lesson 5 is all about finding the cheapest one.
Example 1.4Directed graphs: in-degree, out-degree
The directed graph shows one-way bus routes between four stops A, B, C, D: A→B, B→C, C→A, C→D and D→B.
ABCD
  1. (a) Make a table of the in-degree and out-degree of each vertex and check the totals.
  2. (b) Show that the graph is strongly connected.
  3. (c) The route D→B is cancelled. Explain why the graph is no longer strongly connected, and suggest one new route that makes it strongly connected again.
🧠 Think it through
  1. Out-degree: arrows leaving. In-degree: arrows arriving. Both totals must equal the number of edges, 5.
  2. Find a route that follows the arrows and visits every stop, then back to the start. If one exists, every stop can reach every other.
  3. Without D→B, what leaves D? Nothing. Once you reach D you are stuck.
✍️ By hand
  Both rows add to 5 ✓
Closed route: A→B→C→D→B→C→A. It visits all four stops and returns to A, so each stop can reach each other stop.
✅ Answer (a) Out-degrees A1, B1, C2, D1 (total 5); in-degrees A1, B2, C1, D1 (total 5). (b) The route A→B→C→D→B→C→A passes through every vertex and returns to A, so the graph is strongly connected. (c) D then has out-degree 0: you can reach D but never leave it. Adding a route D→A (or D→B again, or D→C) means D can be left again, and every stop can again reach every other.
To disprove strong connectivity you only need one pair of vertices with no route between them (here C to D works, but D to anything fails).
Example 1.5Modelling a league as a graph
Six school netball teams form a league. Draw each team as a vertex and join two teams by an edge if they play each other.
  1. (a) In a round robin every team plays every other team once. How many matches are played? What is each team's degree?
  2. (b) Instead, each team plays exactly 3 matches. How many matches are there in total?
  3. (c) Could 5 teams each play exactly 3 matches? Explain.
🧠 Think it through
  1. A round robin on 6 teams is the complete graph .
  2. If every vertex has degree 3, the degree sum is the number of teams × 3. Then halve.
  3. Check that the degree sum would be even.
✍️ By hand
(a) : edges . Each team plays the other 5.
(b) Sum of degrees , so matches .
(c) is odd, but a degree sum must be even.
✅ Answer (a) 15 matches, every team has degree 5. (b) 9 matches. (c) No: 5 teams × 3 matches = 15 is odd, so the degrees could never add to 2 × (number of matches).
“Show that it is impossible” questions almost always use the handshaking lemma: find the degree sum and show it is odd.

Challenge questions

⭐ Challenge 1.6A missing degreePaper 1 style
A simple connected graph has five vertices with degrees 4, 3, 3, , 1 and has exactly 7 edges.
  1. (a) Find .
  2. (b) Explain why the vertex of degree 4 must be adjacent to every other vertex.
  3. (c) State, with a reason, whether the graph is a tree.
✏️ Try it on paper and on your calculator first. Then check.
Show the full solution
🧠 Think it through
  1. Sum of degrees = 2 × 7.
  2. Degree 4 with only 4 other vertices means every other vertex is a neighbour.
  3. A tree on 5 vertices has how many edges?
✍️ By hand
✅ Answer (a) . (b) The graph is simple, so a vertex has at most one edge to each of the 4 other vertices. Degree 4 therefore uses one edge to each of them. (c) Not a tree: a tree with 5 vertices has 4 edges but this graph has 7 (so it contains cycles).
⭐ Challenge 1.7Ferries on the OkavangoPaper 2 style
Five landing stations P, Q, R, S, T on the Okavango are linked by one-way ferry routes: P→Q, P→R, Q→S, R→Q, R→S, S→T and T→P.
PQRST
  1. (a) Complete a table of in-degree and out-degree for each station and show that each row adds to the number of routes.
  2. (b) Which stations have the greatest in-degree?
  3. (c) Show that the network is strongly connected.
  4. (d) The route T→P is withdrawn. Explain why the network is no longer strongly connected.
  5. (e) Write down the only single new one-way route that restores strong connectivity, and justify your answer.
✏️ Try it on paper and on your calculator first. Then check.
Show the full solution
🧠 Think it through
  1. Count arrows out of and into each vertex. There are 7 routes.
  2. For (c) find a closed route through all five stations that follows the arrows.
  3. After T→P goes, look at what leaves T and what arrives at P.
  4. A fix must give T a way out and give P a way in.
✍️ By hand
  Each row adds to 7.
Closed route: P→R→Q→S→T→P visits all five stations.
✅ Answer (a) Out: P2, Q1, R2, S1, T1 (sum 7). In: P1, Q2, R1, S2, T1 (sum 7). (b) Q and S, in-degree 2. (c) P→R→Q→S→T→P goes through every station and returns, so every station can reach every other. (d) T→P was the only route leaving T and the only route entering P, so after it is withdrawn nobody can leave T and nobody can reach P. (e) The route T→P itself: any new route must give T an exit and give P an entrance, and only an arrow from T to P does both.
Next: Lesson 2 · Walks, trails, Euler & Hamilton