Exercises — Graph definitions — directed, undirected, weighted, unweighted, simple, multigraph
Throughout, remember the four switches from the parent note: Direction, Weight, Self-loop, Parallel — "DWSP". And the two edge-count facts:
Level 1 — Recognition
Exercise 1.1
Look at the drawing below (left panel). Every connection is a plain line with no arrowhead. Is this graph directed or undirected? Give the one-word reason.

Recall Solution 1.1
WHAT we check: are the lines arrows or plain lines? WHY: an arrow encodes a direction — an ordered pair that goes one way only; a plain line is an unordered pair that goes both ways. The lines have no arrowheads, so each is symmetric. Answer: undirected.
Exercise 1.2
In the right panel of the figure above, one edge starts and ends at the same dot, and one pair of dots ( and ) is joined by two separate lines. Name each of these two features, and decide: is the graph simple or a multigraph?
Recall Solution 1.2
- The edge from a vertex to itself is a self-loop, written .
- The two lines between the same pair are parallel edges. WHY this forces the classification: a simple graph is defined by forbidding both of those. This graph has both, so it breaks the rule. Answer: it is a multigraph (it fails "simple" on two counts — either one alone is enough).
Exercise 1.3
A road map has numbers written on each road showing kilometres. Which switch is turned "on"? Give the name of the graph property.
Recall Solution 1.3
A number attached to each edge is a weight. WHY: the number distinguishes edges from one another (a long road vs a short road), which is exactly what "weighted" means. Answer: it is a weighted graph. (An unweighted graph would only record whether a road exists, weight for all.)
Level 2 — Application
Exercise 2.1
A simple undirected graph has vertices. What is the maximum possible number of edges?
Recall Solution 2.1
WHY this formula: every edge is an unordered pair of two distinct vertices (distinct because no self-loops; at most one because simple). Counting max edges = counting how many pairs we can choose. Why divide by 2: picking and picking are the same line, so the ordered picks double-count. Answer: 28.
Exercise 2.2
Same 8 vertices, but now the graph is directed (self-loops still forbidden). Maximum number of arcs (directed edges)?
Recall Solution 2.2
WHY no division now: and are different arrows — a one-way street each direction is its own arc. So we keep both. Answer: 56 — exactly double the undirected answer, which matches "each undirected edge = two opposite arcs".
Exercise 2.3
An undirected graph has edges. What is the sum of all vertex degrees?
Recall Solution 2.3
WHY: by the Handshaking Lemma, adding up every vertex's degree counts each edge twice — once at each of its two endpoints. Answer: 22.
Level 3 — Analysis
Exercise 3.1
Someone claims: "I built a simple undirected graph on vertices with edges." Prove they are wrong.
Recall Solution 3.1
WHAT we do: compare the claim against the maximum allowed. WHY: simple + undirected caps the edges at ; exceeding the cap is impossible. Since , no simple undirected graph on 6 vertices can hold 16 edges. The claim is impossible. (To reach 16 you'd need either a parallel edge or a self-loop — i.e. a multigraph.)
Exercise 3.2
An undirected graph is reported to have degrees (four vertices). Is this possible? Use the Handshaking Lemma and its parity corollary.
Recall Solution 3.2
Step 1 — sum test. . For a valid graph this must equal , so . That's an integer, so the sum test passes. Step 2 — parity corollary. The number of odd-degree vertices must be even (because odd degrees can only pair up to make the total even). Here the odd degrees are — that's four odd-degree vertices. Four is even, so this test also passes. Conclusion: the degree sequence is not ruled out by these lemmas; such a graph can exist. (See Handshaking lemma and degree sequences for a full realizability check.)
Exercise 3.3
A degree sequence is proposed for an undirected graph. Show it is impossible.
Recall Solution 3.3
Sum: , which is odd. But must always be even. is odd ⇒ contradiction. Impossible. Why the sum must be even: each edge contributes exactly to two endpoints, i.e. total, so the grand total is always a multiple of 2. An odd total can never occur.
Level 4 — Synthesis
Exercise 4.1
A flight network has 4 airports. Between every ordered pair of distinct airports there is exactly one directed flight, each with its own fare. Additionally, one airport offers a "sightseeing loop" flight that departs and returns to itself. Classify the graph on all four DWSP switches, and count the total number of edges.
Recall Solution 4.1
- Direction: directed — a flight differs from .
- Weight: weighted — each fare is a number on the arc.
- Self-loop: yes — the sightseeing loop is .
- Parallel: the problem says exactly one flight per ordered pair, so no parallel arcs. But the self-loop breaks "simple" anyway, so this is a multigraph (directed weighted multigraph).
- Count: ordered distinct pairs , plus the one self-loop . Answer: directed, weighted, multigraph; total edges .
Exercise 4.2
You are told an undirected graph is simple and connected on vertices, and it happens to be a tree. How many edges does it have, and what is the sum of its degrees?
Recall Solution 4.2
Key fact about trees: a tree on vertices has exactly edges (it's connected with no cycles — the minimum to connect dots). Degree sum by Handshaking: Answer: 4 edges, degree sum 8.
Exercise 4.3
A complete graph is the simple undirected graph where every pair of vertices is joined. For : (a) how many edges? (b) what is the degree of each vertex, and (c) verify Handshaking.
Recall Solution 4.3
(a) Every pair connected ⇒ . (b) Each vertex connects to the other vertices, so for all 7 vertices. (c) and . ✓ They match, so Handshaking holds. Answer: 21 edges; every degree = 6; sum = 42 = 2m.
Level 5 — Mastery
Exercise 5.1
A social platform models 1000 users. Friendships are mutual; follows are one-way. Suppose there are friendships and follow-relations. You store the whole thing as a single directed adjacency structure (see Graph representations — adjacency list vs matrix), representing each undirected friendship as two opposite arcs. Write a formula for the total number of stored directed arcs, and evaluate it for , .
Recall Solution 5.1
WHY two arcs per friendship: an undirected edge has no direction; to store it in a directed structure you record both and so traversal works either way. Each friendship therefore contributes 2 stored arcs; each follow contributes 1. For : Answer: arcs.
Exercise 5.2
For a shortest-path task on this network: (a) if you only care about "fewest hops" between two users, which algorithm and why? (b) if each connection has a positive latency (a weight) and you want the least-latency path, which algorithm and why?
Recall Solution 5.2
(a) Fewest hops = treat every edge as cost = unweighted shortest path. Use BFS — breadth first search. WHY: BFS explores in layers of equal distance, so the first time it reaches a target it has used the fewest edges — and it's faster than a weighted method because it never needs a priority queue. (b) Distinct positive weights ⇒ use Dijkstra's algorithm. WHY: BFS's "count hops" logic is wrong when edges cost different amounts; Dijkstra always expands the currently-cheapest frontier node, which is correct precisely when weights are non-negative. Answer: (a) BFS; (b) Dijkstra.
Exercise 5.3
A project has tasks with "must-finish-before" dependencies (task X must complete before task Y). (a) What kind of graph models this — which two switches are on? (b) Which algorithm produces a valid ordering, and what structural property must the graph have for it to exist at all?
Recall Solution 5.3
(a) A dependency "X before Y" is an ordered relation ⇒ directed. Weights are irrelevant to ordering, so unweighted is fine; self-loops/parallel edges aren't meaningful here (a task can't depend on itself), so it's a simple directed graph. Switch on: Direction. (b) Use Topological sort. WHY it needs direction: topological order only makes sense along arrows. Required property: the graph must be a DAG — a directed acyclic graph (no directed cycle). WHY: a cycle would demand X before Y and Y before X — an impossible order, so no topological sort exists. Answer: (a) simple directed (unweighted) graph; (b) topological sort, needs no directed cycle (a DAG).
Recall Self-test summary (cloze)
Max edges of a simple undirected graph on vertices ::: Max edges (arcs) of a simple directed graph on vertices ::: Sum of all degrees in an undirected graph ::: (Handshaking Lemma) A degree sequence with an odd sum is ::: impossible — the sum must be even () Storing an undirected edge in a directed structure needs ::: two opposite arcs Tool for fewest-hops (unweighted) shortest path ::: BFS Tool for least-cost (non-negative weights) shortest path ::: Dijkstra Tool for ordering tasks along dependency arrows ::: topological sort (requires a DAG)