How to serialize a graph structure?

How do you represent your graph in memory?
Basically you have two (good) options:

  • an adjacency list representation
  • an adjacency matrix representation

in which the adjacency list representation is best used for a sparse graph, and a matrix representation for the dense graphs.

If you used suchs representations then you could serialize those representations instead.

If it has to be human readable you could still opt for creating your own serialization algorithm. For example you could write down the matrix representation like you would do with any “normal” matrix: just print out the columns and rows, and all the data in it like so:

   1  2  3
1 #t #f #f
2 #f #f #t
3 #f #t #f

(this is a non-optimized, non weighted representation, but can be used for directed graphs)

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)