Graph serialization
graph LR
A --> B --> C --> D
B --> D --> A --> C
G = (V, E), or directly E
Straightforward Vertices / Edges iteration,
as the mathematical notation. The Vertices are
not needed, they can be recovered in O(1)
E = ((A, B), (B, C), (C, D),
(B, D), (D, A), (A, C))
Adjacency Matrix
Good for dense graphs.
Slow to remove vertices and edges, because it needs to find them,
and to add or remove vertices and edges because the matrix must be resized, copied.
M = [[0, 1, 1, 0],
[0, 0, 1, 1],
[0, 0, 0, 1],
[1, 0, 0, 0]]
Adjacency List
Fast access by indices, easy implementation,
low memory requirement, efficient for dense small graphs.
L = [[A, B, C, D], [B, D, A, C]]
Tree serialization
graph LR
A --> B --> C --> D
B --> E --> F
Tree DAG/Root properties provide alternatives,
in addition to the universal Graph serialization schemes.
Nested
Represented recursively a mapping syntax,
from branch IDs, to either leaves, or another level.
For example, XML, JSON, YAML, etc.
A/ { B/ { C/ { D }, E/ { F }}}
Paths
Flat version of the Nested representation,
where all keys list branch ID separated by a marker, to the leaves.
Easier to process for some tasks,
less efficient since there is repetition in each path.
A/B/C/D
A/B/E/F