10:27:45 2019-08-31
Learning began to realize map
FIG two representations (of course, a wide variety of other representations) in the program
① adjacency matrix $ G [N] [N] $ $ N $ vertices from $ 0 to $ $ N-1 $ Number
$ G [i] [j] = \ begin {cases} 1 & \ text if \ langle v_i, v_j \ rangle G is the edge \\ 0 & \ text or \ end {cases} $
Features:. Ⅰ diagonal matrix must be coded as all 0 does not allow self-loops
Ⅱ. No symmetrically along a diagonal to FIG.
For a free with a two-dimensional array to store the map is too wasted space
It may take the stored half practices (including diagonal) by using a length of $ \ frac {N (N + 1)} {2} $ one-dimensional array to store $ A $
Calculating space required: $ \ frac {N * NN} {2} + N = \ frac {N (N + 1)} {2} $
The $ G_ {ij} $ $ A $ corresponding to the next objective is to: $ \ frac {i (i + 1)} {2} + j $
For \ langle v_i, j_i \ rangle weighting network as long as the $ G [i] [j] $ value can be defined as the edge
② adjacency table: $ G [N] $ array of pointers, each row of the matrix corresponds to a linked list, only non-zero elements exist