![]() If the entropy is significantly greater than 2, and in particular if it's close to the size of a pointer, the graph is sparse. This is useful when the edges represent interactions between the vertices because it is easy to see how groups of vertices relate to other groups. This is useful for larger networks when the vertices can be organized (clustered) into several groups. two bits per edge in the optimal representation), and the graph is dense. The graph family argues that one of the best ways to represent them into a matrix is by counting the number of edge between. Make a heatmap image of the adjacency matrix. How many bits do you actually need, though?Īssuming that edges are independent, the number of graphs with $N$ nodes and $E$ edges is $$, the entropy is 2 (i.e. Ignoring low-order terms, a bit matrix for a graph uses $N^2$ bits no matter how many edges there are. When the graph is directed, complete, with self-loops thenĪdjacency list: $O(n n^2)$ is $O(n^2)$ (no difference)Īnd finally, when you implement using matrix, checking if there is an edge between two nodes takes $O(1)$ times, while with an adjacency list, it may take linear time in $n$.Ĭonsider a graph with $N$ nodes and $E$ edges. Where $n$ is the number nodes, $m$ is the number of edges.Īdjacency list: $O(n n)$ is $O(n)$ (better than $n^2$) ![]() Then there is no advantage of using adjacency list over matrix. We prefer adjacency list.īut if the graph is dense then the number of edges is close to (the complete) $n(n-1)/2$, or to $n^2$ if the graph is directed with self-loops. Thus we usually don't use matrix representation for sparse graphs. In other words, you need to consider walks such that some vertices/edges are repeated (which do exist). Now if a graph is sparse and we use matrix representation then most of the matrix cells remain unused which leads to the waste of memory. The powers of the adjacency matrix don't give you the number of paths but the number of walks between any two vertices. Now, when we use matrix representation we allocate $n\times n$ matrix to store node-connectivity information, e.g., $M = 1$ if there is edge between nodes $i$ and $j$, otherwise $M = 0$.īut if we use adjacency list then we have an array of nodes and each node points to its adjacency list containing ONLY its neighboring nodes. In a complete graph you have $n(n-1)/2$ edges, where $n$ is the number of nodes. First of all note that sparse means that you have very few edges, and dense means many edges, or almost complete graph.
0 Comments
Leave a Reply. |