Transitive Closure Algorithm using Binary OR Operation : Primes Algorithm , GHK Algorithm

ISSN: 2321-2381 © 2015 | Published by The Standard International Journals (The SIJ) 42 Abstract—In real world scenarios, transitive closures play a vital role in computer networks RDBMS and Graph theory. An efficient algorithm to find transitive closure is in need. Following paper presents new algorithms to find out Transitive Closure of a Relation Matrix and compares the performance with Warshall algorithm. Sections 3 and 4 explain primes and GHK algorithm respectively. Primes algorithm uses prime numbers to find out transitive closures of a relation, and GHK algorithm uses bit sets to find out the transitive closures of a relation efficiently. Section 4 presents experimental results of Primes and GHK against Warshall‟s algorithm.


INTRODUCTION
relation R on a binary relation X is transitive if for every x,y,z in X if xRy, yRz then xRz.Many algorithms are proposed to find transitive closure of relation like Warshall [7,9,10], Warren [11] algorithms, Matrix multiplication by Arlazarov et al., [1], the Aho-Corasick algorithm by Alfred V. Aho et al., [2], Boolean matrix multiplication and transitive closure by Fischer et al., [3], Linear Graph Algorithms by Tarjan [4] and by Schimitz [5], Closure Algorithms by Raghu Rama Krishnan [6], Graphs And Networks by Carre [8], which by Dewitt & Gerber [13], Breaking through the o(n 2 ) barrier by Demetrescu & Italiano [14], which by Alsed et al., [15], which by Blondel et al., [16], Large Graphs and Networks with stability or stabilizability of linear systems with parametric uncertainty, robust control, time-varying linear systems, nonlinear and hybrid systems, and stochastic optimal control by Blondel et al., [17], which by Bochnak et al., [18] and by Collins [19] which use a bit-matrix representation of the graph, the Schmitz [12] algorithm, which uses Tarjan"s algorithm to identify strongly connected components in reverse topological order.Finding the transitive closure of a directed graph is an important subproblem in many computational tasks.Recently, transitive closure computation has been recognized as a signicant subproblem in evaluating recursive database queries, since almost all practical recursive queries are transitive.In Section 2, we presented Warshall algorithm and in Section 3, we presented PRIMES algorithm with an example.In Section 4, we presented GHK algorithm with an explanation.In section 5, we presented the experimental resuls.Setion 6 concludes this paper.
The motivation of the research is: Today all the electronic devices like computers, laptops, mobiles etc., all connected with internet; there is a need to transfer data between these devices efficiently.By using efficient transitive closure algorithm, the data transfer cost is reduced at the expense of small communication cost.

II. WARSHALL'S ALGORITHM
Stephen Warshall presented an efficient algorithm to compute the transitive closure of a relation.Warshall's algorithm to compute transitive closure is defined below.
Let 'n' be the number of nodes in the graph or number of distinct elements in a relation.Array b[i][j] be the relation matrix for the given relation, then Warshall's algorithm computes the transitive closure of a relation in O(n 3 ) time.
Algorithm Warshall( ) If a graph is represented as a relation with each tuple, representing an arc, the Warshall algorithm can be implemented in the following manner.For each node n, first fetch its successor list.Then for each predecessor p of n, fetch the successor list of p, and add to the successor list of p the successor list of n (removing duplicates if any).In order to determine the predecessors of n, the successor list of all other nodes may be scanned to see if n appears in them.An alternative would be to maintain, in addition to the successor list, a predecessor list also with each node.In that case, the determination of the predecessors of n would become trivial, but at the time of updating the successor list of the predecessor p, the predecessor list associated with each of the successors of n must also be updated to include p in them.

III. PRIMES ALGORITHM
In number theory, the fundamental theorem of Arithmetic states that every integer greater than 1 is either Prime itself or the product of Prime numbers.That means, every composite integer (n > 1) can be represented in exactly one way as a product of Prime powers.PRIMES Algorithm uses Fundamental Theorem of Arithmetic and Simple division logic which satisfies Transitive property.
In PRIMES algorithm, each vertex is assigned with a unique Prime number.It works on basic division principle, "If a divides b and b divides c then a divides c".

PRIMES Algorithm Pseudo Code
Step 1: Read the relation matrix a

[n][n]
Step 2: Calculate first 'n' prime numbers and save these in prime[n] and initialize forward[n] with 1 by default Step 3: Call the initial scan procedure.Pseudo code is given below Proc initialscan() { for j := 1 to n { for i : Step 4: Call the forwardScan method, to compute transitive closures Proc forwardScan() gcd() finds the Greatest common divisor of two numbers.
Step 5: Call the compute procedure to update the final transitive closure matrix Proc Compute() means there exist a relation from j to i a[j][i] = 0 means there is no relation from j to i Usually multiplication operation consumes more time as compared to addition, subtraction and bitwise operations.Implementation results in Section 5 shows both Primes and Warshall"s algorithms are running with nearly equal time complexity.
Since Primes algorithm needs Prime numbers Multiplication so it takes time complexity of O(n 3 ) like Warshall"s Algorithm.In Section 4, we reduced the time complexity of Primes algorithm by modifying Primes multiplication operation with Binary OR operation in GHK algorithm.

Example to Find Transitive Closure using Primes Algorithm
Consider the below relation matrix: [4] is the relation matrix that represents above relation.
Prime [4] is one dimensional matrix that store first 4 prime numbers.
Prime [4] = {2, 3, 5, 7} forward [4] is initialized with values 1 forward[4] = {1,1,1,1} Call the initial scan procedure to update the array forward [4] After calling the procedure initial scan the array is like below forward [4] = { 1, 10, 3, 5 } Call the forward scan method to find out transitive closure relations After calling forward scan method the forward scan array is like below forward [4] = { 1, 30, 30, 30 } Call the compute method to update the given input relation matrix Final transitive relation matrix is Bitset [1] = 01000 since vertex 1 has outgoing edges to vertex 2 and 3. So, 2 nd and 3 rd bits of Bitset [1] are set to 1 and remaining bits are set to 0. Similarly the values for remaining vertices are shown below.

IV. GHK ALGORITHM
Bitset [2] = 00011 Bitset [3] = 10010 Bitset [4] = 00001 Bitset [5] = 00000 forwardScan method computes transitive closure in "n" iterations.For each iteration, Bitset of every vertex will be computed and updated accordingly.In i th iteration, forwardScan method checks is there any incoming edges to vertex "i" from all vertices.In first iteration, we will check for an incoming edge to vertex 1.If an edge exists from vertex "v", then Bitset[v] will be updated by performing binary OR operation on Bitsets v and i. Bitset or Bitset [1]; For Example: -After first iteration, Bitsets for the vertices will be updated as shown below.

GHK Algorithm Pseudo Code
Step 1: Read the relation matrix a

3. 1 .
Notation n: Number of nodes in a Graph a[n][n]: Relation matrix for a given relation prime[n] : Array which contains first 'n' prime numbers Forward[n]: Array which contains the final values to compute transitive closures Hence, Total space required for this algorithm is 1.O(n*n): To store relation matrix 2. O(n): To store first 'n' prime numbers 3. O(n): To store 'n' computed values in forward[n] So, total space needed is O(n*n + 2n).

Figure 1 :
Figure 1: Directed Graph As shown in Figure 1, Graph has 5 vertices.Initial scan computes initial Bitsets for every Vertex.Bitset of a Vertex represents the outgoing edges from the vertex.Bitset[1] = 01000 since vertex 1 has outgoing edges to vertex 2 and 3. So, 2 nd and 3 rd bits of Bitset[1] are set to 1 and

4. 1 .
Notation n: Number of nodes in a Graph a[n][n]: Relation matrix for a given relation Bitset[n]: Bitsets representing n vertices.Hence Total space required for this algoritm is 1. n*n -To store relation matrix 2. n*n bits -To define Bitset[] So total space required is n*n + n*n bits.
[n][n]Step 2: Initialize Bitset[n] with 0 by default, i.e, all the bit values in each element of Bitset[n] are set to 0Step 3: Call the initial scan procedure.Pseudo code is given