Generalizing from these examples, we see that a graph node can be represented either by: Each of these representations has unique advantages for certain tasks, so we would like to support them all. In this representation, there are explicit edge objects (if each pair is considered an object), but no node objects. Each pair represents an edge, and stores two node indices (ranging 1 to N). Now consider a third graph representation: a list of pairs. The edges are implicit in the sense that there is no way to refer to an edge other than by its endpoints. Neither representation has explicit edge objects. The first representation has explicit node objects while the second representation does not. The second way is a Boolean matrix representation: the graph is a N by N matrix of Booleans, where N is the number of nodes and entry (i,j) indicates the presence of an edge between node i and node j. This is also known as a singly-linked adjacency list. The first way is a set-of-sets representation: the graph is a set of nodes, and each node stores a set of target nodes. To understand the variety of graph data structures, consider the following two ways of representing a simple graph. The second problem is that graph data structures are not necessarily composed of fine-grained Node and Edge objects. These subcollections are all linked in the sense that if we delete an edge from the graph, it should disappear from all the subcollections. Besides the typical collection operations such as counting edges and testing for presence of an edge, we often want to manipulate subcollections of nodes and edges, such as the set of edges with a given endpoint, or the set of nodes neighboring a given node. First, the operations we want to perform on graphs go beyond the standard collection interfaces. In some graphs, a node may not have any edges for this reason, we have to include the set of nodes in the definition of a graph (otherwise it would suffice to specify the edges).Īt first glance, it may seem like the graph interface could be ICollection together with ICollection. Unlike edges, the nodes always form a set this is essential for determining the endpoints of an edge. In a simple graph, the edges form a set otherwise, they form a bag (or general collection). If there are no parallel edges, then the graph is called a simple graph, otherwise it is called a multi-graph. Two edges with the same endpoints in the same direction are called parallel. In the directed case, the first node is called the source and the second node is the target. An edge consists of two endpoints that may be ordered (directed edge) or unordered (undirected edge). In particular, it should not be necessary to allocate temporary objects in order to do simple tasks, like determining if a particular edge is present, or counting the number of neighbors of a vertex.Ĭonceptually, a graph is a set of nodes and a collection of edges. However, the interface must be simple enough that any data structure can implement it efficiently. The common graph interface is important so that you don’t have to re-implement each graph algorithm on each graph type. It allows efficient access to a wide variety of different graph implementations.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |