Graphs
Model anything made of things and connections between them, such as roads, friendships and dependencies, and store it so algorithms can walk it quickly.
After this lesson you will be able to
- Use the vocabulary of graphs: vertex, edge, directed, weighted, degree, path, cycle, connected.
- Choose between an edge list, an adjacency matrix and an adjacency list, and justify the choice by memory and speed.
- Build an adjacency list from typical contest input, for undirected, directed and weighted graphs.
- Compute degrees and answer simple structural questions (is it a tree? who is trusted by everyone?).
- Recognise when a problem hides a graph, including grids and state spaces.
Before you start. Lists, dictionaries and loops. Trees help, because a tree is a special graph.