← again tap: answer good → ↑ swipe up at the end: next
Question
What is a graph $G = (V, E)$, and what do its vertices and edges store?
Answer
A graph is a pair of a set $V$ of vertices (nodes) and a collection $E$ of edges, each edge a pair of vertices. Vertices and edges can both store an element: in a flight network a vertex stores an airport code and an edge the length of the route between two airports.
* Only the connections count: where the airports sit in the picture means nothing. *
A graph models relationships: which things are connected to which. The vertices are the things, the edges the connections between them. Everything else in a drawing, the positions of the circles and the lengths of the lines, is decoration; two drawings with the same vertices and edges are the same graph. A route's length is part of the graph only because the edge stores it as its element.
$E$ is called a collection rather than a set because it may contain the same pair more than once (parallel edges, such as two different routes between the same two airports). Throughout, $n$ is the number of vertices and $m$ the number of edges: the example has $n = 8$ and $m = 11$.
Go deeper:
Graph (discrete mathematics) — the definitions, the main kinds of graph, and how they are drawn.
Question
What is the difference between a directed and an undirected edge, and when is a whole graph directed?
Answer
A directed edge is an ordered pair $(u, v)$: it leads from the origin $u$ to the destination $v$, like a flight from ORD to PVD. An undirected edge is an unordered pair $\{u, v\}$ that works both ways, like the route between ORD and PVD. A graph whose edges are all directed is a directed graph; one whose edges are all undirected is an undirected graph.
* A flight has a direction and the return flight is a second edge; a route serves both directions. *
Which kind to use follows from the relationship being modelled. Symmetric relationships are undirected: a road usable both ways, a cable between two computers, a route between two airports. Asymmetric ones are directed: one-way streets, scheduled flights, hyperlinks from one web page to another, "A depends on B". In a flight schedule the flights ORD to LGA and LGA to ORD are two separate edges, each with its own flight number.
An undirected edge can always be replaced by two directed edges pointing in opposite directions, which is how some programs store undirected graphs. For directed graphs the degree splits in two: the in-degree counts incoming edges, the out-degree outgoing ones.
Go deeper:
Directed graph — terminology for directed graphs: in- and out-degree, sources, sinks, and the special kinds.