📘 CodingMarble Learn

Graph Theory: Dots, Lines and Networks

A graph is a set of vertices (dots) joined by edges (lines). The degree of a vertex is how many edges touch it, and the sum of all degrees is twice the number of edges. An Euler trail uses every edge once and exists only when 0 or 2 vertices have odd degree. A tree is a connected graph with no cycles and n − 1 edges. Weighted graphs model roads and networks; Kruskal’s and Prim’s algorithms find a minimum spanning tree.

🎬 Step-by-step story

  1. A graph is dots (vertices) joined by lines (edges). Here are 5 towns and 6 roads.
  2. Count the edges at each vertex: that is its degree. All degrees add to twice the number of edges.
  3. An Euler trail uses every edge exactly once. It needs 0 or 2 odd vertices; watch the green trail from A to C.
  4. A tree joins all vertices with no cycles. 5 vertices need just 4 edges.
  5. Give each edge a cost. Kruskal picks the cheapest edges that make no cycle: a minimum spanning tree.
  6. Free play: switch edges on and off and watch the degrees and the Euler rule update.

Tip: drag the 3D scene to turn it. Use two fingers to zoom.

🤔 Common doubts, cleared

Does it matter how long or bent the edges are?

No. In a plain graph only which vertices are joined matters. Lengths matter only in a weighted graph, where we write the number on the edge.

Why is the total degree always twice the edges?

Each edge has two ends and each end adds 1 to some vertex’s degree, so each edge adds exactly 2.

Why does an Euler trail need 0 or 2 odd vertices?

Each time the trail passes through a vertex it uses one edge in and one out, a pair. Only the start and end can have a spare edge, so only they can be odd.

Why does a tree with n vertices have n − 1 edges?

Start with one vertex. Each new edge brings in exactly one new vertex without making a cycle. To bring in n − 1 more vertices you need n − 1 edges.

Why does Kruskal skip an edge that makes a cycle?

Both ends are already connected, so the edge adds cost but no new vertex. Skipping it keeps the total as small as possible.

What happens if I switch off edges until the graph splits?

Then it is not connected and no Euler trail can cover both pieces, even if the degree rule looks fine. Try it in free play.

Graph words you need

A graph G has a set of vertices (also called nodes) and a set of edges (lines joining two vertices). Only connections matter, not how the picture is drawn.

Degree and the handshake lemma

The degree of a vertex, deg(v), is the number of edge-ends at it (a loop counts 2).

Handshake lemma: sum of all degrees = 2 × number of edges. Each edge has two ends, so it adds 2 to the total.

So the total degree is always even, and the number of vertices with odd degree is always even. You can never draw a graph with exactly one odd vertex.

Example: in a party of 6 people, if everyone shakes hands with everyone else, each has degree 5. Total = 30, so there are 15 handshakes.

Walks, paths, cycles, Euler and Hamilton

A walk moves along edges. A trail never repeats an edge. A path never repeats a vertex. A cycle is a path that returns to its start. A graph is connected if you can walk from any vertex to any other.

Euler (1736) solved the bridges of Königsberg puzzle: can you cross 7 bridges once each? He showed a connected graph has:

A Hamiltonian cycle visits every vertex once and returns. There is no simple rule to test for it; you must search.

A random walk moves to a neighbour chosen by chance at each step. Its long-run behaviour is studied with matrices (Markov chains), which is how early web search ranked pages.

Special graphs, trees, planarity and spanning trees

Isomorphic graphs are the same graph drawn differently: same vertices, same connections, after renaming. Quick checks: same number of vertices, edges and the same list of degrees.

A planar graph can be drawn with no edges crossing. For a connected planar graph, Euler’s formula: V − E + F = 2 (F counts regions, including the outside). K₅ and K₃,₃ are not planar.

A spanning tree uses all vertices with no cycles. The minimum spanning tree has the least total weight. Kruskal: sort edges by weight, add the cheapest that makes no cycle. Prim: grow from one vertex, always adding the cheapest edge to a new vertex. Dijkstra’s algorithm finds shortest paths from one vertex.

Key formulas and definitions

Worked examples

1. A graph has degrees 3, 3, 2, 2, 2. How many edges does it have?

Sum = 3 + 3 + 2 + 2 + 2 = 12. Edges = 12 ÷ 2 = 6.

2. How many edges does K₇ have?

n(n − 1)/2 = 7 × 6 ÷ 2 = 21 edges.

3. Can a graph have degrees 3, 3, 3, 2? Why?

Sum = 11, which is odd. The sum must equal 2E, an even number, so no such graph exists.

4. A connected graph has degrees A 2, B 4, C 3, D 2, E 3. Does it have an Euler circuit or trail?

Odd vertices: C and E, exactly 2. So it has an Euler trail starting at C and ending at E (or the reverse), but no Euler circuit.

5. A connected planar graph has 8 vertices and 12 edges. How many regions (faces) does it have?

V − E + F = 2 → 8 − 12 + F = 2 → F = 6.

6. Edges: AB 4, BC 3, CD 5, DE 2, EA 6, AC 7, BD 4, BE 8. Find the minimum spanning tree with Kruskal.

Sorted: DE 2, BC 3, AB 4, BD 4, CD 5 … Take DE (2), BC (3), AB (4), BD (4); now all 5 vertices are joined with 4 edges. CD would make a cycle. Total = 13 km.

Common mistakes

Practice quiz

1. In a graph the sum of all degrees is 18. How many edges?
2. A connected graph has an Euler circuit when:
3. A tree with 10 vertices has how many edges?
4. How many edges does K₅ have?
5. Which visits every vertex exactly once and returns to start?

Practice: answer these yourself

Type or choose your answer, then press Check. Use a hint if you are stuck; the full solution appears after you answer.

Frequently asked questions

What is graph theory in simple words?

It is the maths of networks: dots (vertices) joined by lines (edges). It studies how things connect, such as roads, friends, computers or atoms.

What is the difference between an Euler path and a Hamiltonian path?

An Euler path uses every edge exactly once. A Hamiltonian path visits every vertex exactly once. Euler has a simple degree test; Hamilton does not.

Try it at home: can you draw an envelope without lifting your pen?

Draw a house shape: a square with a cross inside and a triangle roof. Count degrees. Exactly two corners at the bottom are odd, so start at one bottom corner and you can trace every line once, ending at the other.

Where this is taught

RomaniaClasa a XI-aGraphs
RomaniaClasa a XI-aData structures
RomaniaClasa a XI-aGraphs
England (GCSE, A level)Year 12Optional application 3 Discrete (part 1)
England (GCSE, A level)Year 13Optional application 3 Discrete (part 2)
Japan高校(専門学科)1〜3年Special Topics in Advanced Mathematics
FranceTerminaleGraphs and matrices
FranceTerminaleData structures
Russia7 классGraphs
Russia8 классTrees
Russia9 классTheoretical foundations
Russia9 классTheoretical foundations
Russia10 классGraphs
Russia11 классTheoretical foundations
Russia11 классTheoretical foundations

Learn first

Learn next

Related lessons

All Maths lessons