If you want to keep exactly the edges, use the weight matrix: int** M; , where M[i][t] is the length of the edge between i and t vertices.
If your graph graphs have a weight of 1, you can save the graph in the adjacency matrix, where M[i][t] is:
- 0 if there are no edges between i and t vertices
- 1 if there is an edge from i to t
- alpha if i == t and there is a loop at i (or t) vertex
If you request a structure critical to memory usage, save your graph in a linked list, where each vertex has a structure:
struct Vertex { int N; Vertex* next; };
So, you will have an array of Vertex structures, each of which contains a pointer to the next one to which it is connected. For example, here is a list of linked lists:
- 1 → 3 → 4
- 2 → 5
- 3 → 4
- 4 → 3
- 5 → 2
source share