01Vertices, edges and three flavours
A graph G = (V, E) is a set of vertices and a set of edges, each edge joining two vertices. V also denotes the number of vertices and E the number of edges.
- Undirected: an edge u–v can be walked both ways (a friendship, a road open both ways).
- Directed: an edge u→v has a direction (following someone, “course A is required before B”).
- Weighted: every edge carries a number: a length, a price, a time.
Two more words you will need. The degree of a vertex is the number of edges touching it. A graph is sparse when E is close to V and dense when E approaches V². Most real graphs (roads, the web, friendships) are sparse. A tree is the special case you already know: connected, undirected, no cycles, E = V − 1.