Question: I want to understand how to store a graph with huge data. I am designing an application which has a graph of huge railway route network. Where `vertices` are the `railway station name`. I have designed using `adjacency list` in `C++`. But now i found that it is consuming very high memory and sometime i also get `no-memory` error. I was wondering how such huge graph are stored so that `algorithm` on the graph can be used.

Graph is defined as

`std::map<std::string, std::set<std::string> > railway_graph;`

or how does google/facebook store there graph data structure.

Answer: 
Using an adjacency matrix representation instead of an adjacency list can reduce memory allocation for dense matrices.

Because you didn't mention what the size of the system is or what types of algorithms you are attempting to run, it is hard to judge whether your algorithm needs to be checked for inappropriate memory consumption, or if you actually need to make use of files as intermittent "memory" throughout your program in order to make the calculation possible.
Using map and string like that will add a lot of redundant memory use. If you store the names in one vector and the adjacency list using just integer indices it should be a lot more compact.

```
std::vector<std::string> name;
std::vector<std::vector<size_t> > adj_list;

```