简体   繁体   中英

add_edge(v1, v2, graph)- time complexity

I need to build a graph and trying to decide how (for minimum time complexity).

From my understanding, there are two popular ways to store the graph's data: adjacency_list and adjacency_matrix .

The declaration of the graph is (undirected for example):

typedef adjacency_list <vecS, vecS, undirectedS> UGraph; // In case of adjacency_list

typedef adjacency_matrix<undirectedS> UGraph; // In case of adjacency_matrix

Both cases are using the function add_edge(v1,v2,UGraph) to add an edge between two vertices.

So my question is which model will make add_edge be less expensive — in time complexity manner and why?

I tried to read this explanation about time complexity of add_edge but this explanation is about OutEdgeList . So it got me confused.

Which model is less expensive for add_edge and why?

so my question is which data base will make add_edge be less expensive- in time complexity manner and why?

It's faster ( O(1) ) in matrix in comparison to adjacency list in which you need to traverse the whole list attached to particular vertex to add an edge.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM