Professional Documents
Culture Documents
Königsberg - Seven Small Bridges, One Giant Graph Problem - by Vaidehi Joshi - Basecs - Medium
Königsberg - Seven Small Bridges, One Giant Graph Problem - by Vaidehi Joshi - Basecs - Medium
There is perhaps no better example of this than Leonhard Euler, the mathematician,
astronomer, and engineer (just a few of his many titles), who made significant
contributions to calculus and the dude who actually created graph theory that we
depend on every single day.
Well, for one thing, he definitely didn’t do it by waking up one day and thinking: okay
you guys, I’m going to make a new branch of mathematics that’ll eventually be the
cornerstone of how the web works in like, 300 years! Nope. Instead, here’s the truth of
what happened: he was faced with a simple problem. And the story of how Euler solved
this problem centers around how he shifted his perspective, and approached it in a way
that no one else ever had before.
At the time, Königsberg was a city in Germany, and the city was built around a river
called the Pregel River. This city thrived with its merchant economy and part of the
reason that it did so well was because it was structured in a particularly interesting way.
There were two large islands in the middle of the Pregel River, and they were each
https://medium.com/basecs/königsberg-seven-small-bridges-one-giant-graph-problem-2275d1670a12 1/12
04/02/2021 Königsberg: Seven Small Bridges, One Giant Graph Problem | by Vaidehi Joshi | basecs | Medium
connected to one another, as well as to the two riverbanks on either side, which
comprised the majority of the city. And how were they connected? By bridges, of course!
Seven of them, in fact.
Here’s a beautiful print that illustrates the city of Königsberg much better than I ever
could:
The citizens of Königsberg spent their Sundays walking around town, enjoying their
beautiful city. In the process, they came up with a game — which, as it turned out,
proved to be incredibly difficult to accomplish. The goal was to walk across all of the
seven bridges crossing the islands only once, without ever repeating a single bridge in
the course of one’s walk.
At first, when people asked Euler to solve this problem, he brushed it off, thinking that it
had nothing to do with mathematics, and therefore wasn’t really worth his time. But the
more that he thought about it, the more intrigued he became. In a letter to a
mathematician friend of his, he wrote:
This question is so banal, but seemed to me worthy of attention in that [neither] geometry,
nor algebra, nor even the art of counting was sufficient to solve it.
He was hooked. Euler was so entranced, in fact, that he ended up writing a paper later
that year that would contain a solution to the bridge problem. But before we understand
how Euler solved this problem, we need to cover a few basic graph theory rules first.
https://medium.com/basecs/königsberg-seven-small-bridges-one-giant-graph-problem-2275d1670a12 2/12
04/02/2021 Königsberg: Seven Small Bridges, One Giant Graph Problem | by Vaidehi Joshi | basecs | Medium
For example, just as edges can be classified as directed or undirected, vertices (or nodes,
as they’re sometimes called) can also be categorized based upon how they link to other
nodes in a graph.
Degrees of vertices
From first glance, we can already glean a lot from this seemingly simple structure. We
know that vertex C is connected to vertex D. And we also can tell that vertex B is not
https://medium.com/basecs/königsberg-seven-small-bridges-one-giant-graph-problem-2275d1670a12 3/12
04/02/2021 Königsberg: Seven Small Bridges, One Giant Graph Problem | by Vaidehi Joshi | basecs | Medium
Well, these connections end up being important as a graph grows, and it can be helpful
to be able to easily identify which vertices are connected with other vertices. The term
we use to describe two connected vertices is adjacent. For example, vertex F and E are
adjacent because they have a common edge (the edge FE connects them).
Another useful (and important!) way of classifying vertices is by their degree. The
degree of a vertex is the total number of vertices that are adjacent to that vertex.
Okay, so we can classify edges based on whether they are directed or undirected. We can
also classify vertices based on how many other vertices they are connected to.
Cool.
But wait: there’s more! (Obviously). There’s yet another way to identify graphs, and it
has to do with how we traverse through a graph — that is to say, the way that we get
from one vertex to another.
Generally, when we use graphs to implement a data structure, we’re concerned with
how our data relates to one another. Which is to say, we care about how nodes are
connected to other nodes because we usually want to get from one node to another. This
is where graph traversal comes in. There are different algorithms that can come in
handy for traversal, depending upon what type of graph you have. But we won’t get into
those today. Instead, let’s start simple and talk about the words that we use when we talk
about walking through a graph.
Most of the time, when people refer to traversing through a graph, they use the term
“path”. A path in a graph just means the way that you can get from one vertex (the
origin) to another (the destination). In order to get from one vertex to another, we have
to traverse through some edges in the graph.
https://medium.com/basecs/königsberg-seven-small-bridges-one-giant-graph-problem-2275d1670a12 4/12
04/02/2021 Königsberg: Seven Small Bridges, One Giant Graph Problem | by Vaidehi Joshi | basecs | Medium
However, many times people mix up the term “path” with the term “simple path”.
They’re actually a little bit different, and it’s important to acknowledge what sets the two
terms apart. A path doesn’t have to follow any rules — we can start wherever you like
and traverse through the graph in whichever way we’d like, just as long as we end up at
the destination node. Simple paths have a lot more rules that must be followed.
https://medium.com/basecs/königsberg-seven-small-bridges-one-giant-graph-problem-2275d1670a12 5/12
04/02/2021 Königsberg: Seven Small Bridges, One Giant Graph Problem | by Vaidehi Joshi | basecs | Medium
If you ever find yourself in front of a graph problem, be sure to clarify and understand if
you are dealing with finding a path through the graph, or a simple path — because they
can profoundly impact the way that you deal with the data structure.
Finally, there’s also the cycle, which is a simple path, except that we must end our
traversal at the same node that we started off at. That is to say, the starting “origin” node
is the exact same as the ending “destination” node, and we have traversed all the nodes
and edges of the graph in the process.
We already know that the formal definition for a graph is an ordered pair, containing a
set of vertices and a set of edges. We can define a path (or a simple path, or a cycle) in a
similar way: as an ordered list of directed edges. The directed edges here is important
since we need to be able to show which node is the origin, which node is the destination,
and which edge we’re traversing as we cross from one node to another.
Okay, okay—we’ve covered all these terms and rules and stuff, but what I want to know
is…what happened to Euler?! Well, it’s time to (finally) find out.
https://medium.com/basecs/königsberg-seven-small-bridges-one-giant-graph-problem-2275d1670a12 6/12
04/02/2021 Königsberg: Seven Small Bridges, One Giant Graph Problem | by Vaidehi Joshi | basecs | Medium
In the process of doing this exercise, Euler realized that in order to cross seven bridges —
as was the case in the city of Königsberg — the problem needed at least eight
“landmasses”, or letter sequences in order to solve the problem.
Even though Euler solved the puzzle and proved that the walk through Königsberg
wasn’t possible, he wasn’t entirely satisfied. So he kept going and found that, given
certain situations, it is completely possible to cross the bridges of “network” only once.
https://medium.com/basecs/königsberg-seven-small-bridges-one-giant-graph-problem-2275d1670a12 7/12
04/02/2021 Königsberg: Seven Small Bridges, One Giant Graph Problem | by Vaidehi Joshi | basecs | Medium
Today, we often refer to this type of graph traversal as a graph with a Eulerian path or
with a Eulerian circuit.
https://medium.com/basecs/königsberg-seven-small-bridges-one-giant-graph-problem-2275d1670a12 8/12
04/02/2021 Königsberg: Seven Small Bridges, One Giant Graph Problem | by Vaidehi Joshi | basecs | Medium
Euler’s mathematical proof determined that there are certain conditions that a graph
must meet if we are to traverse through its edges only once.
For example, in order for an undirected graph to have a Eulerian cycle, all of the
vertices with a degree in the graph must be connected — that is to say, all of the vertices
that are connected in the graph must have a degree greater than zero — and all of the
vertices in the graph must be of an even degree.
Similarly, in order for an undirected graph to have a Eulerian path (but not a cycle), all
of the vertices with a non-zero degree must be connected, and one of these two things
must happen: 1) two vertices must have an odd degree OR 2) all of the vertices in the
connected graph must be of an even degree.
This can be a little bit confusing unless we really stop and think about it. I love the way
that professors of The NRICH Project at the University of Cambridge explain why this
bridge problem isn’t possible based on Euler’s proof:
Euler proved it couldn’t be done because he worked out that to have an odd vertex you would
have to begin or end the trip at that vertex. (Think about it). Since there can only be one
beginning and one end, there can only be two odd vertices if you’re going to be able to trace
over each arc only once. Since the bridge problem has 4 odd vertices, it just isn’t possible to
do!
Ultimately, it all came down to the degrees of the vertices in the end! (Remember I said
that was going to be important?) It isn’t possible to solve the bridge problem if there are
four vertices with an odd degree.
According to Euler’s proof, we could only solve it if either all the vertices in the graph
were even, or if only two of the vertices were odd. But four odd vertices? Nope. No way.
In the graphs below left, you’ll notice some situations where Euler’s proof holds up to
the test.
https://medium.com/basecs/königsberg-seven-small-bridges-one-giant-graph-problem-2275d1670a12 9/12
04/02/2021 Königsberg: Seven Small Bridges, One Giant Graph Problem | by Vaidehi Joshi | basecs | Medium
In Graph 1, there are two vertices (A and E) with an odd degree, and so it is possible to
traverse each edge once. However, we won’t end up at the same vertex that we started
on.
In Graph 2, all of the vertices have an even degree, so we could not just traverse each
edge only once, but we could end up at the same place that we started!
Graph 3 though — sadly, there’s just no possible way to make this work on a Eulerian
level. This graph has the exact same issue as the Königsberg problem: there are four
vertices that are odd, and since we know we can never have more than two odd degree
vertices, we can be sure that this graph isn’t Eulerian, in the slightest!
The story of what happened to Königsberg after Euler put it on the map is interesting
(and also a little bit sad!). In 1875, the city built another bridge between the nodes B
and C. This resulted in only two vertices with an odd degree, which solved the
impossible walking problem!
Euler’s original drawing (“Solutio problematis ad geometriam situs pertinenti”), MAA Euler Archive
But, unfortunately, in the case of Königsberg, all did not end that well. When Prussia
dissolved, Königsberg eventually became a part of Russia. Two of the original bridges
were bombed by Allies in 1942, during WWII. Two other bridges were later demolished
to make room for a highway. And, the city has since been renamed Kaliningrad.
You can still visit Kaliningrad today, and walk your own Eulerian path across the five
bridges that remain. Because, guess what — now, it’s possible! I like to think that Euler
would probably get a good laugh out of that.
Resources
There is a copious amount of research and writing around Euler’s approach to the Seven
Bridges problem. I couldn’t get into the details of all of it, but the details are out there! If
you want to cross all seven bridges on your own, I suggest starting with this handy
resources.
1. Early Writings on Graph Theory: Euler Circuits and The Königsberg Bridge Problem,
Professor Janet Heine Barnett
https://medium.com/basecs/königsberg-seven-small-bridges-one-giant-graph-problem-2275d1670a12 11/12