A graph is a set of vertices (also called nodes) joined by edges. That's the whole definition. A vertex is a thing; an edge says two things are connected.
Cities joined by roads, people joined by friendships, web pages joined by links — the picture is always the same: dots joined by lines.
Arrays and trees describe data with a fixed shape. A graph describes relationships, and most real problems are about relationships:
That's why graph questions fill so many interviews: they test whether you can see the graph inside a problem. Once you do, the answer is usually one of a dozen standard moves — and this course teaches all of them.
Members only · free account
The rest of this lesson, with 4 more sections, 1 drawing and code in JavaScript, Python, Java and C++, opens with a free account.
Was this helpful?
Not ready yet? The Arrays course is free to read, no account needed.
In the rest of this lesson