Free, open courseware in graph theory and optimization

learngraphtheory.org Algorithms · Optimization · Open courseware
Practice book

Graph Theory Through Problems

300 Exercises with Hints, Worked Algorithms and Complete Solutions

By Mohammed Islam Hadjoudj, creator of Learn Graph Theory

  • 300 exercises
  • 13 chapters
  • Hints and complete solutions
  • Kindle & paperback
See it on Amazon →

Kindle and paperback. Prices are shown on Amazon.

About the Book

Graph Theory Through Problems teaches graph theory the way it sticks: by solving problems. It collects 300 exercises across 13 chapters, graded from routine checks of a definition to challenging proofs, and it gives a complete solution to every exercise.

Most textbooks end each chapter with a list of exercises and leave you alone with them. This book is built the other way around. The exercises are the main text, the harder ones come with hints so you can get unstuck without reading the whole answer, and the solutions show the full reasoning, not just the final result.

It is meant to be used next to a textbook or a course, not instead of one. Read the theory in your course notes or in a book such as West's Introduction to Graph Theory, then come here to practise it until you can do it on your own.

Who It Is For

What the Problems Look Like

Here are two exercises in the style of the book, written for this page: a short proof with a hint, and an algorithm run by hand in a step table.

Example 1 · Trees · Proof

Every tree with at least two vertices has at least two leaves.

A leaf is a vertex of degree 1. Prove the statement for every tree with n ≥ 2 vertices.

Hint. Look at a longest path in the tree. What can you say about its two ends?

Show the solution

Let P = v0 v1 … vk be a longest path in the tree T. Since T is connected and has at least two vertices, it has an edge, so k ≥ 1 and the two ends v0 and vk are different.

Suppose v0 had a neighbour w other than v1. If w is not on P, then w v0 v1 … vk is a longer path, which contradicts the choice of P. If w = vi for some i ≥ 2, then v0 v1 … vi v0 is a cycle, which a tree cannot contain. So v0 has degree 1. The same argument applies to vk.

So v0 and vk are two different leaves. ∎

Example 2 · Shortest paths · Algorithm by hand

Run Dijkstra's algorithm from A on the graph below.

4 2 1 5 8 10 2 A B C D E
An undirected weighted graph. Start at A.

Hint. At each step, settle the unsettled vertex with the smallest tentative distance, then try to improve its neighbours.

Show the solution

Each row settles one vertex (marked *) and updates the tentative distances of its neighbours.

StepSettleABCDE
0–0∞∞∞∞
1A0*42∞∞
2C32*1012
3B3*812
4D8*10
5E10*

The shortest distances from A are B = 3, C = 2, D = 8 and E = 10. Following the updates backwards, the shortest route to E is A → C → B → D → E. Notice that the direct edge A–B (4) loses to the detour through C (2 + 1 = 3), and the direct edge C–E (10) loses to C → B → D → E (1 + 5 + 2 = 8). Spotting those two places is the point of the exercise.

Want to watch it run? Build this graph in the Dijkstra visualizer and step through it, or read the Dijkstra's algorithm guide.

Free Companions on This Site

The book works on paper. This site lets you see the same ideas move. While you work through an exercise, these free pages are a click away:

New to the subject? Start with the introduction to graph theory and the study roadmap.

Which of the Two Books Is for You?

Mohammed Islam Hadjoudj has written two graph books with different jobs. Pick by what you need to do next.

Graph Theory Through ProblemsGraph Algorithms for Coding Interviews
GoalUnderstand the theory and pass a graph theory course or examSolve graph questions in technical interviews
Contents300 exercises over 13 chapters100 solved interview problems
SupportHints for the harder exercises and a complete solution to every oneA visual explanation and a Python solution for every problem
StyleProofs, and algorithms run by hand in step tablesCode you can run and adapt
FormatsKindle and paperbackKindle and paperback

About the Author

Mohammed Islam Hadjoudj

Mohammed Islam Hadjoudj holds a Master's degree in Operations Research and a Bachelor's degree in Mathematics, built Learn Graph Theory (the free interactive visualizer, lessons and article library on this site) and works on combinatorial optimization and scheduling problems.

· Try the visualizer

Frequently Asked Questions

Does every exercise have a solution?

Yes. All 300 exercises have a complete, worked solution, and the harder ones also have a hint, so you can try again before reading the answer.

Is Graph Theory Through Problems good for beginners?

It is written for a first course. The exercises start with routine checks of the definitions and build up to challenging proofs, so a beginner can start at the top of each chapter. It works best next to a textbook or course notes.

What topics does the book cover?

It runs across 13 chapters, from trees and matchings to planar graphs and Ramsey theory, and it includes algorithms such as Dijkstra, Prim and Ford-Fulkerson worked by hand in step tables.

Is it available on Kindle?

Yes. The book is available as a Kindle ebook and as a paperback on Amazon.

Who wrote Graph Theory Through Problems?

Mohammed Islam Hadjoudj, who holds a Master's degree in Operations Research and a Bachelor's degree in Mathematics and created the Learn Graph Theory website.

Disclosure: this page is written by the author of the book, who also runs this site. Example problems on this page were written for this page to show the style of the book.

Practise Graph Theory Until It Clicks

300 exercises, hints when you are stuck, and a complete solution to every one.

See it on Amazon →