Introduction to graphs
easy 18 minA graph is a set of vertices joined by edges, directed or undirected, weighted or not.
Where it shows up
The same pattern appears across everyday software.
Social networks
Facebook friendships are an undirected graph and Twitter or Instagram follows a directed one. Friend suggestions come from shared neighbours, and degrees of separation are BFS distances.
Maps and navigation
Road networks are weighted graphs: junctions as vertices, road segments as edges, travel time as weights. One-way streets are directed edges. Routing apps run Dijkstra or A* over them.
Computer networks and the internet
Routers and devices are vertices, links are edges. Routing protocols compute shortest paths, and finding bridges shows which single link failure would split the network.
The web and search
Pages are vertices and hyperlinks are directed edges. Crawlers traverse it with a visited set, and PageRank scores a page by the links pointing in, an in-degree idea refined.
Build systems and schedulers
Packages, modules or tasks with "must run before" relations form a DAG. Tools like make, npm and workflow engines topologically sort it and refuse to run when they find a cycle.
Recommendations and fraud detection
Users, products and transactions form large graphs. "Customers who bought this also bought" walks neighbours of neighbours, and tight clusters of accounts sharing cards or devices flag fraud rings.