Join places with little lines
Picture
Draw a dot for home and a dot for the park. Join them if you can travel directly between them. Dots and links let us describe connections.
Predict
Home connects to park. Park connects to café. There is no home–café link. Can we still reach the café from home?
Let's look
Yes, through the park. A path can contain several links.
A little Python, if you want it
neighbors = {"home": ["park"], "park": ["home", "cafe"], "cafe": ["park"]}
assert "park" in neighbors["home"]
assert "cafe" in neighbors["park"]
A dot is often called a node or vertex. A link is an edge. A graph is a collection of them. A tree is a connected undirected graph with no cycle; choosing a root lets us talk about parents and children.
Change one rule
Add a direct link from café back to home. Can we now go around in a circle?
Let's try it
Yes: home → park → café → home. That round trip is a cycle.
Connect
Trees and graphs build on these dots and links. A table is another useful way to arrange places.