Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> comp.databases.theory -> Re: transitive closure of a graph

Re: transitive closure of a graph

From: Mikito Harakiri <mikharakiri_nospaum_at_yahoo.com>
Date: 11 Oct 2005 19:11:35 -0700
Message-ID: <1129083095.324985.273800@f14g2000cwb.googlegroups.com>

Mikito Harakiri wrote:
> Transitive closure (TC) of a graph is
>
> with TransClosedEdges (tail, head) as
> ( select tail, head from Edges
> union all
> select e.tail, ee.head from Edges e, TransClosedEdges ee
> where e.head = ee.tail
> )
> select distinct * from TransClosedEdges
>
> except that this query might never terminate.

Oops, it's actually quite obvious

with TransClosedEdges (tail, head) as
( select tail, head from Edges
  where tail <> head --*******
  union all
  select e.tail, ee.head from Edges e, TransClosedEdges ee   where e.head = ee.tail
  and e.tail <> ee.head --*******
)
select distinct * from TransClosedEdges

Graeme handles more general case, hence the complication. Received on Tue Oct 11 2005 - 21:11:35 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US