AlgoViz

Introduction to graphs

easy 18 min

A graph is a set of vertices joined by edges, directed or undirected, weighted or not.

A Graph class: add, remove, neighbours, edge check, degrees, DFS, BFS and components

Read it, run it, change a line and run it again.

Loading editor…

An undirected graph on an adjacency list (a dictionary of lists). Every method is a handful of lines; the traversals share a visited set and run in O(V + E).