D1 2.1 - Graphs and network matrices

D1 2.1 - Graphs and network matrices

Describe connections using graph language, distinguish a spanning tree from a network containing cycles, and translate between a weighted network and its matrix. These representations let you record exactly which connections exist before choosing an algorithm to use them.

Vertices edges degree paths and cycles

Can two pictures describe the same connections even when one looks completely different? Yes: the connections and their labels matter, not the positions of the dots or the lengths drawn on the page.

Graph and network

A graph consists of vertices (nodes) joined by edges (arcs). A network, or weighted graph, has a number called a weight on each edge. Weights may represent distance, time or cost; they need not match the drawn lengths.

Here the weights could be connection costs. There is an edge from BB to DD with weight 33, but no direct edge from AA to DD. A crossing of drawn edges is not an extra vertex unless a vertex is marked there.

[DIAGRAM: asset_name: Five vertices and seven weighted edges; asset_slug: graph-language-network; caption: The labels give weights; the drawing's lengths do not.; description: An undirected network has vertices A B C D E and edges AB 6, AC 7, BC 2, BD 3, CD 1, CE 8 and DE 4. No other edges are present.]
The labels give weights

The degree, or valency, of a vertex is the number of edges incident to it. At CC, four edges meet: AC,BC,CD,CEAC,BC,CD,CE, so its degree is 44. Degrees of A,B,C,D,EA,B,C,D,E are 2,3,4,3,22,3,4,3,2: B,DB,D are odd vertices and the others are even. The sum is 1414, twice the seven edges, because each edge contributes once at each end.

A walk follows a sequence of adjoining edges and may repeat vertices or edges. A path follows adjoining edges with no repeated vertex. A cycle, also called a circuit, returns to its start without repeating any other vertex. In the picture:

  • A,B,D,EA,B,D,E is a path, using AB,BD,DEAB,BD,DE.
  • A,B,C,A,BA,B,C,A,B is a walk but not a path: it repeats vertices and the edge ABAB.
  • A,B,C,AA,B,C,A is a cycle: only the first/last vertex repeats.

A tour is a walk which visits every vertex and returns to its start. For example, A,B,D,E,C,AA,B,D,E,C,A is a tour here. A cycle need not visit every vertex, and a tour is allowed to repeat vertices and edges. Keep these terms distinct.

Edges with an indicated direction produce a digraph. Follow their arrows: an arc from AA to BB does not imply one from BB to AA. Our pictured network is undirected, so either direction is allowed.

Key idea

A vertex sequence describes a valid walk only if every consecutive pair is joined by an appropriate edge. Then check repetition to decide whether it is a path, cycle or tour.

Use the supplied connections rather than guessing from the names.

Connected graphs trees and spanning trees

Keeping every vertex does not necessarily keep every connection, and a tree deliberately excludes cycles.

Two vertices are connected if a path joins them, possibly through other vertices. A graph is connected when every pair of its vertices is connected; direct edges between every pair are not needed. A complete graph does have a direct edge between every pair of distinct vertices. The five-vertex picture above is connected but not complete: for example, AA and EE connect through other vertices but have no direct edge.

Tree and spanning tree

A tree is a connected graph with no cycles. A subgraph uses vertices and edges from a larger graph. A spanning tree is a subgraph which includes all the original vertices and is itself a tree.

For the earlier network, retain only AB,BC,CD,DEAB,BC,CD,DE. These four edges join all five vertices in a chain without a cycle, so they form a spanning tree. Retaining AB,BC,ACAB,BC,AC instead would create a cycle and leave D,ED,E disconnected: it is a subgraph, but not a spanning tree.

[DIAGRAM: asset_name: A connected graph, its spanning tree and a disconnected subgraph; asset_slug: networks-and-trees; caption: A spanning tree keeps every vertex and enough edges to connect them without a cycle.; description: Three panels use vertices A B C D E. The first is the seven-edge connected network. The second retains AB BC CD DE as a spanning tree. The third retains AB AC BC DE, forming a triangle on A B C separated from D E. The last has four edges but is not a tree.]
A spanning tree keeps every vertex and enough edges to connect them without a cycle.

A tree on nn vertices has n−1n-1 edges. To see why, start with one vertex. Each new vertex needs one edge to attach it; adding an extra edge between already connected vertices creates a cycle. Connecting the other n−1n-1 vertices therefore needs n−1n-1 edges. There is exactly one path between any two vertices in a tree; two different paths would form a cycle.

Counting n−1n-1 edges alone is insufficient. The last panel also has four edges and five vertices, but it is disconnected and contains a cycle. For a proposed spanning tree, check the vertices, connectivity and absence of cycles together.

A minimum spanning tree, or minimum connector, is a spanning tree with the smallest possible total weight. Many different spanning trees may exist; “spanning” alone makes no claim about their weight.

Watch out

“Connected” does not mean “complete”. A tree can connect every vertex using indirect paths, and it must not add a final edge merely to return to its starting vertex.

Use both defining conditions in this check.

Weighted adjacency matrices

A weighted adjacency matrix records the direct connections in a table with matching vertex labels on its rows and columns.

Continue this lesson.

You’re previewing NovaLearn without an account. Create a free account to read the rest.

Create free account