Just like title, Is it better to open the memory pool or a vector to save a graph?
I personally like using Vector to save a graph...
I just learned graph theory, so I don't know how to use it. :(
memory pool:
struct Edge{
int next;
int to;
int w;
};
void add(int u,int v,int w) {
edge[cnt].w = w;
edge[cnt].to = v;
edge[cnt].next = head[u];
head[u] = cnt++;
}
I think the "memory pool“ (probably should be called linked list?) method should mainly be used for network flow (when you need to quickly access an edge's reverse edge) and when performance and constant factors are critical.
The "memory pool" method is probably faster than vector, since vector dynamically allocates memory for its data which incurs overhead. However, it is easier to use a vector, since you can directly iterate over all of its contents with a for-each loop (
for(auto& v:elist[u])
and the like)Well, I think use vector is easy to use, But now, I want to try linked list XD
And thank you!
Assume vertices are 1..n. I like to use
Its inspired by https://cses.fi/book/book.pdf which is where I learned (am still learning) graphs.