• No results found

Hypergraph Representation of Spatial Semantics

4.4 Efficient Hypergraph Data Structures

Since we represent all possible query result sets as a hypergraph, we next introduce several efficient hypergraph data structures that are crucial in achieving efficiency for our methods. Some of them have also been used in the implementation of (Bar-Yehuda, 2001).

First, the nodes of the hyperedges are stored sequentially in an array (called a node array) and the positions that mark the endings of the hyperedges in the array are stored in another array (called an edge index array), which serve as indexes to the nodes in the hyperedges. The weights of the hyperedges are stored in a third array (weight array). An inverse hypergraph is also built for the hypergraph. The inverse hypergraph has an array to store the hyperedge IDs that contain the nodes in the original graph sequentially (called an edge array). Similar to the index array used in a hypergraph, the positions that mark the endings of hyperedges containing the nodes are stored in a second array (called a node index array) of the inverse hypergraph. We will show how these arrays can be used to efficiently manipulate a hypergraph through an example shortly.

To build the hypergraph data arrays, a hypergraph data file is needed to be scanned twice. The hypergraph data file is assumed to be stored in the order of hyperedges and the numbers of nodes and hyperedges are given. Each hyperedge is

stored as a record in the data file with the following format: its number of nodes in the hyperedge, followed by the IDs of the nodes, then its weight. During the first scan, the edge index array and the weight array are filled. After the first scan, the total number of nodes in all hyperedges is computed and the node array of the hypergraph is then allocated. During the second scan, the node array is actually filled while scanning.

Once the hypergraph data arrays are constructed, the inverse hypergraph data arrays can be constructed in a more efficient manner since their constructions require only memory access to the hypergraph data arrays. The node array of a hypergraph is first scanned to compute the number of hyperedges associated with each node. These numbers are accumulated and filled in the node index array of the corresponding inverse hypergraph. The node array of the hypergraph is then scanned the second time to find the edge number of each node that is contained in the edge and which is then put into the proper position of the edge array of the inverse hypergraph.

From the construction processes, we can see that both the time complexity and space complexity of the node array, the edge index array and weight array in a hypergraph are linear with respect to the number of total nodes in all hyperedges, the number of hyperedges and the number of hyperedges, respectively. Similarly, both the time complexity and space complexity of the edge array and the node index array are linear with respect to the number of total nodes in all hyperedges and the number of nodes in a hypergraph, respectively.

By using the arrays of a hypergraph and the corresponding inverse hypergraph, we can perform the following operations efficiently. First, we can retrieve all the nodes in a hyperedge of ID e by first retrieving the ending position of the previous edge (e-1) and the ending position of e from the edge index array and then retrieving all the nodes from the node array of the hypergraph. Second, we can retrieve all the hyperedges that contain a node v by first retrieving the ending position of the previous node (v-1) and the ending position of v from the node index array and then retrieving all the IDs of the hyperedges between the two positions from the edge array of the corresponding inverse hypergraph. Note that we can retrieve the weight of a hyperedge by accessing the weight array of the hypergraph by its ID e directly.

We next illustrate these hypergraph data structures using the hypergraph shown in Fig. 4-1. For the sake of simplicity, we remove the edges that have only one node. The node array, edge index array and the weight array of the hypergraph, and the edge array and the node index array of the inverse hypergraph are shown in Fig. 4-6. From the node index array of the inverse hypergraph, we know that there are 8- 3=5 hyperedges passing through node 2. By seeking the 4th through the 8th elements

in the edge array of the inverse hypergraph we know that they are hyperedges 2, 3, 5, 6, and 7. By accessing the weight array of the hypergraph, we know that their weights are 38, 22, 3, 14 and 4, respectively. Furthermore, by looking up at the edge index array of the hypergraph, we know that there are 13-10 =3 nodes in the hyperedge 6 and we know that they are the 11th to the 13th elements in the node array of the

Hypergraph: Node Array: [1,3,2,3,1,2,3,4,2,4,1,2,3,2,3,4] Edge Array: [0,2,4,6,8,10,13,16] Weight Array: [2,38,22,8,3,14,4] Inverse Hypergraph: Edge Array: [1,3,6,2,3,5,6,7,1,2,4,6,7,4,5,7] Node Array: [0,3,8,13,16] Hyperedge Node List Weight 1 1,3 2 2 2,3 38 3 1,2 22 4 3,4 8 5 2,4 3 6 1,2,3 14 7 2,3,4 4 4 14 4 3 2 1 8 3 2

+

38 22 4 3 2 1

The example hypergraph

Fig. 4-6. Illustration of the Hypergraph Data Structures