
I don’t understand Graph Theory - signa11
https://medium.com/@vardanator/i-dont-understand-graph-theory-1c96572a1401
======
inputcoffee
I have a graduate degree in computer science and know some graph theory, but I
really liked this. I thought it was interesting, reminded me of a lot of
theory, and taught me some more.

I really appreciated the voice and tone. I am very surprised to see people who
did not appreciate it and took the time to write how much they didn't like it.
(Which is their right).

I am writing this only to let the original author know that there is an
audience for this kind of "breezy" explanation.

~~~
vardanator
Thank you very much! I don't really get upset for critics, it helps a lot to
produce the next good work (noting previous complains). However, hearing some
really positive feedback is always motivating to spend more time on knowledge
sharing. Thanks again!

~~~
bhrgunatha
Teaching is part skill and part craft and like so many other creative areas
there are plenty of different styles that can appeal to different
personalities and preferences. It's a constant tension and there will always
be room for imagination, creativity and even art in teaching. Prime example -
[http://poignant.guide/](http://poignant.guide/)

------
anticnstrctv
Maybe I'm alone, but I never felt the graph theory pedagogy I experienced was
very confusing or boring (I did think this about plenty of CS topics!).
There's lots of motivating examples to pull in, and better/clearer diagrams
than this in may places. This just seems like a not very lucid description of
theory that is very formalized and that many lectures and textbooks deal with.

~~~
dpwm
When I was 16 I changed sixth form[0] following a house move and I was
accidentally put onto a maths course that was basically algorithms without
computers. I think the name was something like Decision and Discrete.

This course started with Zeller's congruence as an example of an algorithm and
then moved onto some graph theory and then onto Dijkstra's algorithm. I never
got to see what the rest of the course contained, but it really looked like a
good course. Sadly I was not able to persuade the person who was in charge to
let me continue to take the course.

All the people on the course absolutely hated it from the start; thought I was
mad to want to do it; would go on to fail it and as a result this was the last
year the sixth form would run it.

[0] Sixth form is the 16-18 optional education in the UK.

~~~
beojan
You're talking about the D1 module, which was considered the easiest maths
module at my school, because it doesn't really require much understanding, you
just have to learn the material.

~~~
Gormisdomai
D-maths modules in the UK have changed a lot over the years, seems like they
started out pretty legit and got diluted over time. Depends when they took it.

~~~
beojan
I took it 6 years ago. When were they introduced?

~~~
jdietrich
At least the early 90s, possibly earlier.

------
andrepd
I'm just gonna go ahead and say: _this_ is the kind of style that makes me go
"yawn, this is boring". Endlessly meandering and circling the subject,
stopping every sentence to make an irrelevant digression or an attempt at
humour (breaking my concentration in the process), stretching on and on...
Yeah, give me a concise text, that goes straight to the subject, and that
doesn't attempt to take a conversationalist tone with me as if we were having
a beer together, give me that any day.

Yes, I understand some people have the opposite view, I'm just trying to day
that there are surely a lot of people too that find this kind of style
extremely distracting and frustrating.

In other words, my favourite textbooks of all time are Landau and Lifschitz
:^)

~~~
vardanator
Interesting notes, thanks. I was struggling with such books that compress a
complex idea in a couple of sentences, so I'm always trying to explain as
detailed as possible. Though understanding that there is a broad audience who
likes the opposite (succinct explanations), I wrote disclaimers to secure me
just in case. So, read the disclaimers one more time, that's my only excuse
for such long and boring discussions :)

~~~
titanix2
I share some of the criticisms already stated in other comments. The biggest
offender here in my opinion is that it jumps to too many subjects. Trees as
graphs, yes, but they are a whole subject of their own. This post should
broken down in at least 4 or 5 posts. Moreover, its mixes vastly different
concerns: byte level optimization is an interesting topic too, but it has
nothing to do with graph per se.

On the positive side: relevant illustrations. I also liked that the code
implementation is one that use explicit edges. Too often in books, it is
either the adjacency matrix or the linked list ones. The former is
inconvenient when you need to add a node, and the latter doesn't let you put
weight on edge. So these "academic" implementations are not well suited for
groking concept by playing with code.

I work a lot with graphs and there is a big value in having a general enough
graph implementation. Last week I implemented a trie class with it, and this
week a transducer. Both in two hours, debugging included. Other things such as
serialization came from free from the library. Of course, that not optimal
data structure, but it is fine for my use cases.

In your post, you don't use the fact that trees are graph to avoid duplicate
code explanations, instead you explain it first for a tree, then details the
graph one. It should be the reverse: how to use a graph implementation to
create a tree. And then only if this implementation does not fit the memory or
performance requirements of the app, rewrite a more specialized data
structure.

~~~
vardanator
Thanks!

------
ozim
Those disclaimers look like comments on bad code. Dear author you do not have
obligation to make such clarifications.

I take this blogpost as example how I do not want to write. It is too long and
too much information in one piece, Euler to BST with AirBnb to Twitter, and
Facebook. With stop on linked lists, arrays and trade-offs between them. Don't
even get me started on Sponge Bob. All this targeted at junior developers?

I advise author to read: "Nobody Wants to Read Your Sh*t: Why That Is And What
You Can Do About It"

~~~
felideon
And yet, it is at the top (#2 right now) of HN.

~~~
whorleater
Because the HN voting system is a clear and democratic way of expressing value

------
lkrubner
I find it strange that the folks on Hacker News sometimes have such strong
reactions to the tone of an article, or sometimes just a paragraph in the
article. I’ve gotten that too, when articles of mine become popular on HN. I
personally liked this article about graph theory, the conversational tone.

~~~
hackermailman
I didn't understand why at first until I started reading dozens of books and
papers suggested here that have precision in their writing, now I too can't
stand an overly written article or book. The Art of Computer Programming vol 1
contains an excellent introduction to graph theory where Knuth converts a
program flow chart into a graph to discover free subtrees.The dry humor there
doesn't try to be too obvious, and every sentence is carefully written for
precision.

~~~
lkrubner
I get that any kind of writing can provoke strong reactions, as some people
have strong preferences. And they have a right to those preferences. But I
hope we can agree that being vocal about one's preferences is a different kind
of activity? Everyday on Hacker News there are dozens of articles that don't
interest me, but can you imagine what people would think about me if, in every
one of those articles, I posted a note saying that I didn't like the article?

Most of us simply skip over the stuff that doesn't interest us. That is
clearly the default behavior. Therefore it is interesting why, on certain
articles, people do feel the need to comment on the style.

Personally, I've been lucky, because the most vocal people have been the
people who like my writing. But not always. I wrote a book about startups, and
some people loved that it had a lot of humor, whereas others really hated it.
At least so far, the one's who hate it write to me privately, whereas the ones
who love it have written the reviews on Amazon:

[https://www.amazon.com/Destroy-Tech-Startup-Easy-
Steps/dp/09...](https://www.amazon.com/Destroy-Tech-Startup-Easy-
Steps/dp/0998997617/#customerReviews)

I'm lucky, but I'm also curious why this is. As a purely sociological
question, why is that sometimes people feel the need to be very vocal with
their disapproval, whereas most of the time they keep such disapproval
private?

------
travisjungroth
For people who don’t understand graphs, Euler graphs seem like such a weird
place to start. There are much more relevant problems (social networks,
followers and travel distances) with approachable graphs (undirected,
directed, and weighted).

~~~
vinchuco
The place I wish I had started at:

The Nature of Computation - Moore, Mertens

What I got (graduate coursework):

Graph Theory - Reinhard Diestel

A more encyclopedic treatment (most big results, no proofs):

Handbook of Graph Theory - Gross, Yellen

~~~
adrianN
The Diestel book is great if you already know Graph Theory. The proofs are
exquisitely concise, but it's hard to read because you have to think really
hard about the definitions and why they're giving in precisely that way (hint:
to make the proofs more concise!).

------
Scea91
Some people prefer learning from examples (inductive) while other people
prefer learning the theory bottom-up (deductive). This article may be for the
first kind of people.

Everyone uses both kinds of reasoning but I know I have deeper understanding
of the areas that I studied bottom-up. Even if it might have been a bit more
difficult and time consuming, because I didn't get to the applicable stuff as
fast.

~~~
suj1th
IMO, deductive learning is limiting ( we are limited by the span of our
examples), but it has great recall value. Inductive learning is harder to
commit to long-term memory; particularly, when learning something which you
find scant use for in your day-to-day life. Again, I can see this is not
general, and could vary considerably across individuals.

~~~
randomsearch
I’ve done a few degree-level teaching courses, and what I gathered from them
is that the notion of individual learning styles is a bit of a myth.

Most people learn best from examples, which makes intuitive sense. Purely
theoretical learning does not come easy to most people - that’s why maths is
so scary to so many.

Given that the learning style myth has been mostly discredited, I also wonder
about preferences such as night owl vs morning bird - it seems to me that
people learn best in the morning, _unless_ they have poor sleep hygiene. Which
would again make totally intuitive sense.

~~~
hueving
>they have poor sleep hygiene

This just sounds like a morning person trying to imply that night owls are
unhealthy.

I consistently go to bed around 2 and wake up at ~10. I have better 'sleep
hygiene' than many people I know who are 'morning people' because they force
themselves to strict wake-up times.

Even with a good amount of sleep at consistent times each night, I am still
more intellectually productive in the evening than in the first couple of
hours after waking up.

~~~
randomsearch
> This just sounds like a morning person trying to imply that night owls are
> unhealthy.

I wondered if anyone would interpret it like that, but I decided you would
give me more credit, given I was speaking from a professional POV.

Before I did the teaching courses, I would have described myself as a night
owl. I did then (and still do now to a lesser extent) have poor sleep hygiene.
However, since I became more wary of how illogical the dichotomy is, I have
found I'm just as productive in the morning provided I've slept well.

In the morning, your brain is fresh from sleep and flushed of toxins. Your
energy levels are higher and you've been hit with blue light indicating it's
the start of the day. It makes sense that you would learn better in such a
state.

What's the argument for night owls being better learners at night?

~~~
grumdan
> What's the argument for night owls being better learners at night?

I would say that the argument is that many people report this to be the case
and there are some studies pointing to the existence of such an effect
(sometimes called chronotype). Even in the absence of rigorous studies, a
reasonable default view is to say that such an effect may or may not exist and
we just don't know for sure if it does.

I would argue that the burden of proof is on the person making the claim that
this effect doesn't exist, as that's a stronger statement about the world. It
also seems to contradict a lot of anecdotes without proper evidence that casts
doubt on their accuracy; the simplified model that you mentioned, about sleep
flushing toxins from your body may not capture all the relevant aspects here
(for example genetic components to concentration ability).

Wikipedia references a few studies, but I'm not an expert and can't tell how
conclusive or rigorous they are:
[https://en.wikipedia.org/wiki/Chronotype](https://en.wikipedia.org/wiki/Chronotype)

~~~
randomsearch
I'm not asking for evidence, just a reasonable argument as to why people might
learn better at night. Because the obvious thinking on that is, until very
recently, night time meant most humans simply went to bed.

~~~
grumdan
I would say that variability in ability to concentrate might be reasonable to
assume as a starting point, given how much people vary in other features as
well, even if there are similar connections to how humans evolved. For
example, food preferences are also in part a result of evolutionary processes,
but vary a lot between people.

------
btown
So, if you do have data in an arbitrary graph structure and want to do a
search like the Airbnb example - essentially, sort nodes by maximal total flow
from a set of starting search nodes - clearly Hopcroft-Karp isn’t appropriate,
but is there an algorithm that is good for this use case? The author punts to
building indices, but is there a way to express that from a graph theory
perspective?

------
Moodles
My MSc dissertation topic was on graph theory. I studied a lot of crazy stuff:
things like random trees, hypergraphs and partitions of graphs into other
graphs. I remember once this internet company came to campus and was trying to
encourage mathematicians to join them. This lady said: "One person has a PhD
in graph theory but originally thought she wouldn't be needed here. Yet the
internet is a graph!" I was thinking, yeah, sure, a lot of graph data
structures and algorithms are pretty useful, but it was hard for me to see how
some the niche topics I was studying would really, actually, be useful.
Luckily mathematics does tend to to surprise us like that. (Saying that, I am
now a cryptographer and don't use much graph theory, or any of the economics
and game theory I did in my undergradate :-) Game theory in particular, I am
highly skeptical of, but that's another story...)

~~~
dsacco
_> (Saying that, I am now a cryptographer and don't use much graph theory, or
any of the economics and game theory I did in my undergradate :-) Game theory
in particular, I am highly skeptical of, but that's another story...)_

You’re a cryptographer and don’t use _any_ game theory? Most cryptographic
protocols are, or can be, phrased through game semantics. Game theory is very
useful, what are you skeptical about?

~~~
Moodles
It is true that you can analyse many cryptographic schemes by modelling them
as games. In fact, my PhD was largely focused on this exact topic :-) Our
discussion really depends on what we define as “game theory” and “graph
theory” I suppose.

The game theory I studied in economics (albeit in my undergrad) I'm very
skeptical of, though. It was about exact payoffs and rational agents and loads
of assumptions that really don't work in real-life. I'd spend time literally
analysing optimal strategies in board games. It all seemed kind of pointless.
People always said you can apply game theory to political science and wars,
but it all seemed like common sense and logic, rather than the specific stuff
I was actually studying. I remember solving integral equations to calculate
Nash equilibrium bidding strategies in third price bid auctions with perfect
information and a uniform distribution of value to buyers. The solutions had a
lot of maths, but had no bearing on reality whatsoever. What I studied was
never really used to make any actual predictions in the real world. It seemed
almost as if they were trying to make this subject mathematical to give it
some legitimacy. A lot of it is common sense. One could argue that studying it
helps you think logically I guess, but so do lots of things. Ariel Rubinstein
is a famous economist and actually one of the founders of game theory and gave
an excellent critique of the whole space. He is a lot more eloquent than I.
You should listen to him and let me know what you think.

[https://rwer.wordpress.com/2012/11/05/game-theory-a-
critique...](https://rwer.wordpress.com/2012/11/05/game-theory-a-critique/)

~~~
tw1010
Isn't the (only) problem with game theory that the actor optimization function
is inappropriate? Rationality as an assumption is the problem. But everything
else, all the derived higher order structure above that seems, in my eyes, to
be pretty useful. There are other contexts, like evolutionary game theory,
where the optimization function is just darwinian fitness. And in that
situation do most professionals seem to agree that the model is perfectly
useful.

So game theory as a framework seems would be totally fine if we could only
figure out a more psycologically plausible goal function, wouldn't you agree?

~~~
Moodles
Rubinstein makes the point (which I wholeheartedly agree with) that game
theory is a lot like fables. They might help you interpret a certain situation
in a certain way, but they have no value in actually predicting anything. I'm
not sure how it will ever get there. If someone comes up with a goal function
and actually makes predictions which work in the real world then yes, I would
of course change my mind.

~~~
tw1010
I used to be just as sceptical as you. (And I still am about traditional game
theory.) But then I stumbled into evolutionary game theory, which seems much
more robust. Have you read anything about it? What's your take? Apparently ESS
has been used to model cancer very fruitfully.

------
Twisell
I just lost track at the airbnb example. What is the inherent advantage of
using a graph in the context of computing scores over 4million possibilities ?
Should’t a Modern sql database be enough?

PS : Or maybe we could use a blockchain to be even more modern?

~~~
Twisell
Hold on I get It’s because actually that example was all about binary tree
(which are often used under the hood by database engine for index scanning).

I’ll give another shot to this article later but, I’m more lost than before
because I managed to have a grasp of graph theory without knowing a lot about
binary tree (I’am more a data analyst than a developer).

PS : Thx vardanator

~~~
vardanator
Oh, thank you too, it's really great to hear a feedback.

------
enriquto
The best way to understand graph theory is in a continuos setting. When you
approximate a linear pde with finite differences, you can write the discrete
set of equations as a linear system with sparse matrices. Sparse matrices are
just graphs. And the natural matrices associated to this graph (adjacency
matrix, incidence matrix, transposed incidence matrix, etc) correspond to the
natural linear operators on your space (laplacian, gradient, divergence,
etc.).

~~~
camel_Snake
If you already understand those other things I find it surprising that you
wouldn't already understand graph theory.

------
nukeop
I don't know if this is common in USA to finish higher education in computer
science and not learn about graphs at some point? Even the basics?

In Europe most universities that teach computer science have at least one
course fully dedicated to graph theory, algorithms for traversal, shortest
path finding, cycle detection and so on. I didn't even know it was possible to
work professionally as a software developer and not already know all of this.

~~~
the_af
Another thing I noticed is the number of articles claiming that "college is
overrated" or that "CS is not useful for the real world" and in general
downplaying the importance of a formal education, and then... "I don't
understand Graph Theory". Yes, not saying the same people claim all these
things, but surely there's _some_ connection between deriding a formal CS
education and not understanding a prime example of a CS topic like Graph
Theory?

------
tayo42
There is some serious amounts of cynicism and negativity in these comments.
The article is an interesting introduction. The style is a little all over the
place, but hardly worth closing it over. No one seems to be criticizing the
correctness of the content, probably the most important part of a technical
article to discuss.

~~~
forgottenpass
>No one seems to be criticizing the correctness of the content, probably the
most important part of a technical article to discuss.

 _shug_

There's plenty of existing resources designed to learn graph theory. It's not
good enough for a new one to simply be correct. If someone doesn't think their
presentation of the content is going to be better, why bother? I'd sooner
share my discrete math textbook with someone before sending them this link.

------
diyseguy
If someone wants to present a fresh take on a subject like this, why drag out
the same examples that are always used? My eyes glazed over as I observed the
bridges of Konigsberg trotted out yet again. Sprinkling curlicues on a tired
overused cliche like this will never freshen it up.

Can all the authors out there just stop trying to dumb things down for a
general audience and just start at the intermediate level? Just skip all the
drawn out cliched intros and get on with it. Don't try to cutesify it, it just
comes out condescending. This is also why I can't bear to read documentation
from Google.

------
interdrift
Thank you for sharing this. I'm doing a master's degree in computing and I
think graphs are the most powerful modeling tool in the whole of computer
science.

------
agentultra
Graph theory is amazing. One of my favorite subjects.

If you're a liberal-arts kind of person and or have scars from prior
experiences with mathematics I recommend,
[https://www.amazon.com/Introduction-Graph-Theory-Dover-
Mathe...](https://www.amazon.com/Introduction-Graph-Theory-Dover-
Mathematics/dp/0486678709/ref=zg_bs_13938_1?_encoding=UTF8&psc=1&refRID=5B340WJFHW26XTZVXM54)

------
taeric
With the top few posts being somewhat negative, I was expecting a bad article.
It is longer than I'd care for on a quick read, but it looks solid and I would
consider a hardcopy. Especially to share with my kids to help them learn. The
added "color" really helps, I think.

------
addadi
I must recommend also Sarada Herke series of videos on graph theory. they are
excellent.

[https://www.youtube.com/playlist?list=PLGxuz-
nmYlQOiIOriTXME...](https://www.youtube.com/playlist?list=PLGxuz-
nmYlQOiIOriTXMEoGoybUC3Jmrn)

------
mathgenius
Here's a pro-tip: "I don't understand XYZ" this is the humble-brag of
academia. And the more basic XYZ is, the more points you win. Try the
following: "I don't understand 1+1=2." Sit back and enjoy your collaborators
as they stare in wonderment at your sage lack of understanding.

~~~
opportune
I don't think good mathematicians confuse rigorous understanding with
intuitive understanding as you suggest; rather, they are complements of each
other

Further reading: [https://terrytao.wordpress.com/career-advice/theres-more-
to-...](https://terrytao.wordpress.com/career-advice/theres-more-to-
mathematics-than-rigour-and-proofs/)

~~~
nazgul17
Saying that you intuitively do not understand XYZ often requires intellectual
honesty as well as understanding it rigorously, even more so in academia. So
saying that you intuitively do not understand XYZ can be used as a signal.

------
gtrubetskoy
For programmers "understanding" graph theory begins with being able to
implement a traversal and knowing how depth-first is different from breadth-
first, what is pre-order, in-order or post-order, what role the stack and the
queue play in it, and how it can be done recursively or using a loop.

------
jasonmaydie
For the longest time I couldn't understand electrical theory, until a youtuber
explained it very simply... It won't move unless it can see a path to ground,
except you make it do all the work while it's attempting to ground.

That's all it took for the theory to fall into place.

------
andybak
Small quibble:

> note that we are still dealing with pseudocode

He's got a funny idea about pseudocode!

This is very timely. I've been writing an app to draw polyhedra and it's
slowly been dawning on me that there's a lot more graph theory involved than
there is 3D geometry or vector maths.

------
blattimwind
If anyone has trouble with graph theory or other basics of discrete
mathematics, then the introductory works of Matoušek and Nešetřil will most
likely help them very much.

------
tyteen4a03
I really think what this article needs is an editor. From a quick glance I can
see quite a bit of info but the way it is presented irks me.

------
baron816
Don’t worry, it’s just a theory...

------
OldArrow
Was expecting this to be pitch for neo4j.

------
zerr
Understood but forgot. Several times.

------
vardanator
Thanks @signa11 for sharing this.

------
twic
How long did this take to write? It is rather reminiscent of War and Peace, in
that it's undoubtedly an impressive work, but there is no way i am going to
read it.

~~~
zaphar
That's a shame. Really good long form writing is often well worth your time.
Although this particular piece had some grammar issues that reduced it's
quality but the content was still enjoyable.

------
estomagordo
Nice work. I stopped reading about 2 volumes in, though.

