Everyone knows everyone
Graphs as Friendship Maps
The analogy
A friendship map is messier than an org chart: friendship goes both ways, circles loop back on each other, and there is no single person at the top. A graph is just dots (people) joined by lines (relationships).
Visualizer
Dots, lines and loops
step 1 / 6Eight dots, ten lines. No root, no hierarchy — just relationships.V = 8, E = 10
adj = {
"A": ["B", "C"],
"B": ["A", "D", "E"],
"C": ["A", "F", "G"],
}
len(adj["B"]) # degree of B
"C" in adj["A"] # is there an edge?
# space O(V + E) — right for sparse graphsCheck yourself
A tree is…