Open links in new tab
  1. Adjacency list - Wikipedia

    For use as a data structure, the main alternative to the adjacency list is the adjacency matrix. Because each entry in the adjacency matrix requires only one bit, it can be represented in a very compact way, occupying only |V| /8 bytes of contiguous space, where |V| is the number of vertices of the graph. Besides avoiding wasted space, this compactness encourages locality of reference.

    For use as a data structure, the main alternative to the adjacency list is the adjacency matrix. Because each entry in the adjacency matrix requires only one bit, it can be represented in a very compact way, occupying only |V| /8 bytes of contiguous space, where |V| is the number of vertices of the graph. Besides avoiding wasted space, this compactness encourages locality of reference.

    However, for a sparse graph, adjacency lists require less space, because they do not waste any space to represent edges that are not present. Using a naïve array implementation on a 32-bit computer, an adjacency list for an undirected graph requires about 2⋅(32/8)|E| = 8|E| bytes of space, where |E| is the number of edges of the graph.

    Noting that an undirected simple graph can have at most (|V| −|V|)/2 ≈ V edges, allowing loops, we can let d = |E|/|V| denote the density of the graph. Then, 8|E| > |V| /8 when |E|/|V| > 1/64, that is the adjacency list representation occupies more space than the adjacency matrix representation when d > 1/64. Thus a graph must be sparse enough to justify an adjacency list representation.

    Besides the space trade-off, the different data structures also facilitate different operations. Finding all vertices adjacent to a given vertex in an adjacency list …

    Read more on Wikipedia

    Wikipedia

    In graph theory and computer science, an adjacency list is a collection of unordered lists used to represent a finite graph. Each unordered list within an adjacency list describes the set of neighbors of a particular vertex in the graph. This is one of several commonly used representations of graphs for use in computer programs.

    Continue reading

    An adjacency list representation for a graph associates each vertex in the graph with the collection of its neighbouring vertices or edges. There are many variations of this basic idea, differing in the details of how they implement the association between vertices and collections, in how they implement the collections, in whether they include both vertices and edges or only vertices as first class objects, and in what kinds of objects are used to represent the vertices and edges.
    • An implementation suggested by Guido van Rossum uses a hash table to associate each vertex in a graph with an array of adjacent vertices. In this representation, a vertex may be represented by any hashable object. There is no explicit representation of edges as objects.
    • Cormen et al. suggest an implementation in which the vertices are represented by index numbers. Their representation uses an array indexed by vertex number, in which the array cell for each vertex points to a singly linked list of the neighboring vertices of that vertex. In this representation, the nodes of the singly linked list may be interpreted as edge objects; however, they do not store the full information about each edge (they only store one of the two endpoints of the edge) and in undirected graphs there will be two different linked list nodes for each edge (one within the lists for each of the two endpoints of the edge).
    • The object oriented incidence list structure suggested by Goodrich and Tamassia has special classes of vertex objects and edge objects. Each vertex object has an instance variable pointing to a collection object that lists the neighboring edge objects. In turn, each edge object points to the two vertex objects at its endpoints. This version of the adjacency list uses more memory than the version in which adjacent vertices are listed directly, but the existence of explicit edge objects allows it extra flexibility in storing additional information about edges.

    Continue reading

    The main operation performed by the adjacency list data structure is to report a list of the neighbors of a given vertex. Using any of the implementations detailed above, this can be performed in constant time per neighbor. In other words, the total time to report all of the neighbors of a vertex v is proportional to the degree of v.

    It is also possible, but not as efficient, to use adjacency lists to test whether an edge exists or does not exist between two specified vertices. In an adjacency list in which the neighbors of each vertex are unsorted, testing for the existence of an edge may be performed in time proportional to the minimum degree of the two given vertices, by using a sequential search through the neighbors of this vertex. If the neighbors are represented as a sorted array, binary search may be used instead, taking time proportional to the logarithm of the degree.

    Continue reading

    The main alternative to the adjacency list is the adjacency matrix, a matrix whose rows and columns are indexed by vertices and whose cells contain a Boolean value that indicates whether an edge is present between the vertices corresponding to the row and column of the cell. For a sparse graph (one in which most pairs of vertices are not connected by edges) an adjacency list is significantly more space-efficient than an adjacency matrix (stored as a two-dimensional array): the space usage of the adjacency list is proportional to the number of edges and vertices in the graph, while for an adjacency matrix stored in this way the space is proportional to the square of the number of vertices. However, it is possible to store adjacency matrices more space-efficiently, matching the linear space usage of an adjacency list, by using a hash table indexed by pairs of vertices rather than an array.

    The other significant difference between adjacency lists and adjacency matrices is in the efficiency of the operations they perform. In an adjacency list, the neighbors of each vertex may be listed efficiently, in time proportional to the degree of the vertex. In an adjacency matrix, this operation takes time proportional to the number of vertices in the graph, which may be significantly higher than the degree. On the other hand, the adjacency matrix allows testing whether two vertices are adjacent to each other in constant time; the adjacency list is slower to support this operation.

    Continue reading
    Feedback
     
  1. 123

    An adjacency list is a data structure used to represent a graph. In this structure, each vertex in the graph maintains a list of its neighboring vertices. This representation is particularly efficient for sparse graphs, where the number of edges is much less than the number of vertices squared.

    Key Principles

    In an adjacency list, the graph is represented as an array of lists. Each index of the array corresponds to a vertex, and the list at that index contains the vertices that are adjacent to it. For example, if vertex A is connected to vertices B and C, the list at index A will contain B and C1.

    Example in Python

    Here is a simple implementation of an adjacency list in Python:

    Was this helpful?

    See results from:

  2. Adjacency List (With Code in C, C++, Java and Python) - Programiz

    1. An adjacency list is efficient in terms of storage because we only need to store the values for the edges. For a sparse graph with millions of vertices and edges, this can mean a lot of saved space.
    2. It also helps to find all the vertices adjacent to a vertex easily.
    See more on programiz.com
  3. Java Program to Implement Adjacency List - GeeksforGeeks

    May 15, 2024 · Adjacency List is the data structure used to represent graphs which can consist of the vertices (nodes) and the edges (connections between the nodes). In the adjacency list, …

  4. C Program to Implement Adjacency List - GeeksforGeeks

    Jul 3, 2024 · An adjacency list is a data structure used to represent a graph in the form of an array of linked lists. The index of the array represents a vertex and each element in its linked list …

  5. Graph Representation: Adjacency Matrix and Adjacency …

    Now, A Adjacency Matrix is a N*N binary matrix in which value of [i,j]th cell is 1 if there exists an edge originating from ith vertex and terminating to jth vertex, otherwise the value is 0. Given below are Adjacency matrices for both …

  6. People also ask
  7. Graph Representations - Adjacency Matrix and List

    Nov 8, 2020 · This tutorial covers Graph data structure representations, namely Adjacency Matrix and Adjacency List along with their code implementation for beginners.

  8. Graph Data Structures (Adjacency Matrix, Adjacency …

    There are many ways to store graph information into a graph data structure. In this visualization, we show three graph data structures: Adjacency Matrix, Adjacency List, and Edge List — each with its own strengths and weaknesses.

  9. Adjacency lists in Data Structures - Online Tutorials Library

    Aug 27, 2019 · Here we will see the adjacency list representation −. This representation is called the adjacency List. This representation is based on Linked Lists. In this approach, each Node …

  10. Introduction to Adjacency List for Graph - codedamn

    Jan 13, 2023 · Adjacency lists are a data structure that stores the relationship between vertices in a graph. The nodes in an adjacency list are referred to as vertices, and their neighbours are …

  11. Some results have been removed