Operations
The basic operations provided by a graph data structure ''G'' usually include:See, e.g. , Section 13.1.2: Operations on graphs, p. 360. For a more detailed set of operations, see * : tests whether there is an edge from the vertex ''x'' to the vertex ''y''; * : lists all vertices ''y'' such that there is an edge from the vertex ''x'' to the vertex ''y''; * : adds the vertex ''x'', if it is not there; * : removes the vertex ''x'', if it is there; * : adds the edge ''z'' from the vertex ''x'' to the vertex ''y'', if it is not there; * : removes the edge from the vertex ''x'' to the vertex ''y'', if it is there; * : returns the value associated with the vertex ''x''; * : sets the value associated with the vertex ''x'' to ''v''. Structures that associate values to the edges usually also provide: * : returns the value associated with the edge (''x'', ''y''); * : sets the value associated with the edge (''x'', ''y'') to ''v''.Common data structures for graph representation
; Adjacency list : Vertices are stored as records or objects, and every vertex stores a list of adjacent vertices. This data structure allows the storage of additional data on the vertices. Additional data can be stored if edges are also stored as objects, in which case each vertex stores its incident edges and each edge stores its incident vertices. ; Adjacency matrix : A two-dimensional matrix, in which the rows represent source vertices and columns represent destination vertices. Data on edges and vertices must be stored externally. Only the cost for one edge can be stored between each pair of vertices. ; Incidence matrix : A two-dimensional matrix, in which the rows represent the vertices and columns represent the edges. The entries indicate the incidence relation between the vertex at a row and edge at a column. The following table gives the time complexity cost of performing various operations on graphs, for each of these representations, with , ''V'', the number of vertices and , ''E'', the number of edges. In the matrix representations, the entries encode the cost of following an edge. The cost of edges that are not present are assumed to be ∞. Adjacency lists are generally preferred for the representation of sparse graphs, while an adjacency matrix is preferred if the graph is dense; that is, the number of edges , ''E'', is close to the number of vertices squared, , ''V'', 2, or if one must be able to quickly look up if there is an edge connecting two vertices.Parallel representations
The parallelization of graph problems faces significant challenges: Data-driven computations, unstructured problems, poor locality and high data access to computation ratio. The graph representation used for parallel architectures plays a significant role in facing those challenges. Poorly chosen representations may unnecessarily drive up the communication cost of the algorithm, which will decrease its scalability. In the following, shared and distributed memory architectures are considered.Shared memory
In the case of a shared memory model, the graph representations used for parallel processing are the same as in the sequential case, since parallel read-only access to the graph representation (e.g. an adjacency list) is efficient in shared memory.Distributed memory
In the distributed memory model, the usual approach is to partition the vertex set of the graph into sets . Here, is the amount of available processing elements (PE). The vertex set partitions are then distributed to the PEs with matching index, additionally to the corresponding edges. Every PE has its own subgraph representation, where edges with an endpoint in another partition require special attention. For standard communication interfaces likeCompressed representations
Graphs with trillions of edges occur in machine learning, social network analysis, and other areas. Compressed graph representations have been developed to reduce I/O and memory requirements. General techniques such as Huffman coding are applicable, but the adjacency list or adjacency matrix can be processed in specific ways to increase efficiency.See also
* Graph traversal for graph walking strategies * Graph database for graph (data structure) persistency * Graph rewriting for rule based transformations of graphs (graph data structures) * Graph drawing software for software, systems, and providers of systems for drawing graphsReferences
External links