Courses / Computer Science I
Discrete Mathematics

Graphs and Trees

Computer Science I 317 words Free to read

Modeling Connections

A graph is a set of vertices (nodes) joined by edges — a mathematical model of connections, from road maps to social networks to program control flow. Graphs are one of the most useful structures in all of computing, and this discrete-math view is exactly what the data-structures unit implements.

Core terminology:

A beautiful early result is the handshaking lemma: the sum of all vertex degrees equals twice the number of edges, deg(v)=2E\sum \deg(v) = 2|E|, because every edge contributes to exactly two vertices' degrees. An immediate corollary: the number of odd-degree vertices is always even.

A tree is a special graph: connected and acyclic (no cycles). Trees have elegant properties — a tree with nn vertices has exactly n1n - 1 edges, and there is a unique path between any two vertices. Rooted trees (with a designated root) model hierarchies and are the backbone of the data-structures unit (binary trees, heaps, tries). The whole discrete-math toolkit — sets, relations, induction, counting — comes together in graph theory, which is why it closes the unit.

Common pitfall: miscounting with the handshaking lemma, or forgetting a tree's defining constraints. The sum of degrees is 2E2|E|, twice the edge count, not the edge count itself — every edge is counted at both its endpoints. And a tree must be both connected and acyclic; a graph that is acyclic but disconnected is a forest, not a single tree, and a tree on nn vertices always has exactly n1n-1 edges (no more, no fewer).

Practise this lesson

The explanation above is free to read. The graded practice for this lesson lives in the Tryals app.

9practice questions
2interactive scenes
Start Computer Science I free

Discrete Mathematics