3.5.1 · D3Graphs

Worked examples — Graph definitions — directed, undirected, weighted, unweighted, simple, multigraph

2,637 words12 min readBack to topic

You have met the four switches (Direction, Weight, Self-loop, Parallel) in the parent note. Knowing the definitions is not the same as being able to classify and count in every situation. This page hunts down every case — every switch combination, the degenerate graphs (no edges, one vertex, everything self-loops), the limiting sizes, a word problem, and an exam twist — and works each one out from zero.


The scenario matrix

Before working examples, let us list every case class this topic can throw at you. Each row is a "type of situation"; the last column names the worked example that lands in that cell.

# Case class What makes it tricky Covered by
1 Undirected + simple, counting divide-by-2 handshake Ex 1
2 Directed + simple, counting do not divide by 2 Ex 2
3 Multigraph (parallel edges) classify + degree duplicates count separately Ex 3
4 Self-loops present a loop adds +2 to degree Ex 4
5 Directed in-degree / out-degree split two degrees per vertex Ex 5
6 Weighted, real-world shortest path picking BFS vs Dijkstra Ex 6
7 Degenerate: empty edge set / single vertex / self-loops only , , limiting behaviour Ex 7
8 Limiting size: densest possible (complete graph) hits its maximum Ex 8
9 Word problem mixing switches translate English → Ex 9
10 Exam twist: "is this degree sequence possible?" Handshaking parity check Ex 10

Every switch combination (directed?, weighted?, self-loop?, parallel?) and every degenerate/limiting input appears in at least one row. Now we clear the grid.


First, the tools we will reuse

WHY these three and not others? Almost every counting question reduces to one of them. "How dense can it get?" → the max-edge formulas. "Do these degrees add up?" → the handshake. If you internalise why the 2 appears (an edge touches two endpoints; an unordered pair is one handshake between two people) you never memorise — you re-derive. The link Complete graph $K_n$ and dense vs sparse graphs pushes the first formula further; Handshaking lemma and degree sequences pushes the third.

Look at the figure above: the left panel is one undirected edge — one handshake, touched at two dots (blue). The right panel splits it into two directed arcs (orange). Same picture, but the edge count differs: 1 vs 2. Hold this image; it explains every divide-by-2 below.


Cell 1 — Undirected + simple, counting max edges


Cell 2 — Directed + simple, counting


Cell 3 — Multigraph (parallel edges), classify + degree


Cell 4 — Self-loops present


Cell 5 — Directed: in-degree vs out-degree


Cell 6 — Weighted, real-world: which algorithm?


Cell 7 — Degenerate inputs (the cases people forget)


Cell 8 — Limiting size: the densest graph


Cell 9 — Word problem mixing switches


Cell 10 — Exam twist: is a degree sequence possible?


Recall Quick self-test (reveal after guessing)

Max edges of simple undirected on ? ::: . Same but directed, no self-loops, ? ::: . A self-loop adds how much to a vertex's degree? ::: (both endpoints land on it). Why is impossible on 5 vertices? ::: Sum is odd, but must be even. Weighted non-negative shortest path — which algorithm? ::: Dijkstra (BFS ignores weights).

Back to the parent topic. See also Trees as special graphs for the sparsest connected case ().