WeCodeAcademy

Graphs

A graph is a set of nodes (also called vertices) joined by edges. It models anything made of connections: roads between towns, friends on a social network, links between web pages. Edges can be one-way (directed) or two-way (undirected).

The usual way to store a graph is an adjacency list: a dictionary mapping each node to the list of its neighbours. It uses little memory and makes "who is next to X?" instant.

Examplepython
Open in editor »
Quick check

How does an adjacency list store a graph?

Your turn: write the code

Find the node with the most neighbours and print its name.

Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.

Tip: use the left and right arrow keys to move between lessons.