Is there an algorithm to search a directed graph (tree) for its neighbors neighbor?My current brute-force solution works as follows:for each node n:   for each child c of n      for each parent p of c         if (p != n)           insert edge (p,n)I am dealing with ca. 700.000 nodes each having between 1 to 1000 edges and currently I am facing too long running times: which is mainly due to the reason I am executing this algorithm on a graph database, since it would require too much memory.
Algorithm for searching the neighbors neighbor of a directed graph
algorithms;performance;graph traversal
Are for each child and for each parent equally fast? If for each parent is slower, try this:for each node p  for each child c1 of p     for each child c2 of p       if (c1 != c2)         insert edge (c1,c2)EDIT: The above version creates a different result, a list of siblings. Now for another approach...for each node c  ps:=c.parents()     for each p1 in ps     for each p2 in ps       if (p1 != p2)         insert edge (p1,p2)