Consider the layout as follows:

The adjacency list can be implemented as an array of [Nx4] (n in this case is 3, and 4, because you say that 4 is the maximum number of edges in your case) in the following form:
2 3 0 0 3 0 0 0 0 0 0 0
the above view assumes the number of vertices in sorted order, where the first index in the array is specified (v-1) .
The list of incidents, on the other hand, requires that you define a list of vertices, a list of edges, and elements of the connection between them ( incidence list - graph ).
Both are good in terms of space utilization compared to the adjacency matrix, as your graph is very sparse, as you said.
My suggestion would be to go to an adjacency list, which you can initialize as a continuous array [Nx4] in memory (since you say that you will have no more than 4 edges for one vertex). This view will initialize faster. ( Also, this view will work better in terms of cache efficiency. )
However, if you expect your chart to be dynamically and frequently resized, incident lists may be better since they are usually implemented as lists that are not continuous (see link above). In this case, the removal and distribution of the adjacency array may be undesirable.
meyumer
source share