Currently I am learning graph implementation. I found 2 implementation namely matrix and adjacency list using vector in cpp. But the problems I face are following
With matrix
- Passing to function is hard
- Adding new nodes is not possible
- memory inefficient
Vector implementation of adjacency list
// Code taken from geeksforgeeks
vector<int> adj[V];
// adding edge from u to v
adj[u].push_back(v);
- adding new node is not possible
- and also passing to function is hard
So I want a solution in cpp which can solve above 2 problems.