Garry
Garry

Reputation: 21

Directed graph with million of nodes, most with only a few edges but a few with hundreds of thousands

Suppose a directed graph has a million nodes, most nodes have only a few edges, but a few nodes have hundreds of thousands of edges.

To represent this graph, I used an adjacency matrix but, as it turns out, its running time is O(n2) and for adjacency matrix random access is not efficient.

How can I represent this graph in an efficient way that could solve both random access and works faster?

Upvotes: 2

Views: 525

Answers (1)

Leo
Leo

Reputation: 1919

use the adjacency list, see a description here

Upvotes: 1

Related Questions