liveBook · Manning

Distance matrix

As explained in Modern C

A distance matrix is a matrix whose entry for a pair of points records the distance from the first point to the second.

A distance matrix D extends an adjacency matrix: entry D[i][j] records the distance from point i to point j. Because argument order matters, D[i][j] may differ from D[j][i]. section 6.1.5

Representing absent connections

For a graph G, store the distance between every pair of points in D. Represent the absence of a direct arc with a very large value such as SIZE_MAX; use the matrix to seek a shortest path between input nodes x and y. section 6.1.5

TAKEAWAY

  • Treat each ordered pair as a matrix entry. section 6.1.5
  • Use a sentinel value such as SIZE_MAX when no direct arc exists. section 6.1.5

How Modern C covers it

How deep it goes
Defines the representation and sentinel convention, then asks for shortest-path work without supplying an algorithm.
Examples
Uses graph G, ordered points i and j, nodes x and y, and SIZE_MAX for absent direct arcs.
What it assumes
Assumes familiarity with adjacency matrices and graph terms while deferring pointer and void-type details elsewhere.
What you can do after
Evaluate a graph representation and formulate a shortest-path search between two specified nodes.
How it connects
Connects distance matrices to adjacency matrices, graphs, arcs, breadth-first search, connected components, spanning trees, and shortest paths.

Also explained in

Compare how 3 books explain distance matrix →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Modern C. The section links point to the parts of the book it draws on.