There are three ways to store a graph in memory:
Take a look at comparison table on wikipedia. It gives a pretty good understanding of when to use each representation of graphs.