Adjacency matrix1/31/2024 ![]() 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. two bits per edge in the optimal representation), and the graph is dense. 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. Adjacency Matrix contains rows and columns that represent a labeled. 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. Adjacency Matrix is a square matrix used to describe the directed and undirected graph. We can associate a matrix with each graph storing some of the information about the graph in. 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. 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. 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. The adjacency matrix of a simple undirected graph is a real symmetric matrix and is therefore orthogonally diagonalizable its eigenvalues are real algebraic integers. 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.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |