Networks of connected nodes
Day 91 of 149
π Full deep-dive with code examples
The Road Map Analogy
A road map shows cities connected by roads:
- Cities = Nodes (vertices)
- Roads = Edges (connections)
- Some roads are one-way (directed)
- Some have distances (weighted)
Graphs represent any connected network!
Graphs in Real Life
- Social networks: People connected by friendships
- Maps: Locations connected by roads
- Web pages: Pages connected by links
- Dependencies: Packages that depend on each other
How to Represent Graphs
# Adjacency List (most common)
graph = {
'A': ['B', 'C'],
'B': ['A', 'D'],
'C': ['A', 'D'],
'D': ['B', 'C']
}
# "A connects to B and C"
# "B connects to A and D"
Graph Types
| Type | Example |
|---|---|
| Undirected | Facebook friends (mutual) |
| Directed | Twitter follows (one-way) |
| Weighted | Roads with distances |
| Cyclic | Can loop back to start |
Common Operations
- BFS: Explore neighbors first (shortest path)
- DFS: Explore deeply before backtracking
- Shortest Path: Find quickest route (Dijkstra)
In One Sentence
Graphs represent networks of nodes connected by edges, modeling relationships, roads, and dependencies.
π Enjoying these? Follow for daily ELI5 explanations!
Making complex tech concepts simple, one day at a time.
Top comments (0)