Re: How to judge if the graph is cyclic when add a new edge?
- From: Simon Richard Clarkstone <s.r.clarkstone@xxxxxxxxxxxx>
- Date: Fri, 27 Apr 2007 23:01:56 +0100
cstnt wrote:
How to judge if the graph is cyclic when add a new edge? How to do it quickly.
I will assume that the graph is undirected, otherwise the following won't work:
Give each connected group in the graph a distinct name, and label each node with the name of its group. When you add an edge then:
(a) If the edge is between two nodes with the same label, you are creating a cycle or cycles.
(b) If the edge is between two nodes with different labels, you are not creating a cycle, and you should re-label the nodes of one group to match the other group, as the two groups have merged.
I think that if you create a tree from a cloud of n disconnected nodes by add random non-cycle-inducing links, and you always re-name the smaller group in case (b), you will need O(n log n) individual re-labelling operations, though I am not sure how to prove it.
--
Simon Richard Clarkstone:
s.r.cl?rkst?n?@durham.ac.uk/s?m?n.cl?rkst?n?@hotmail.com
Scheme guy says: (> Scheme Haskell)
Haskell guy says: (> Scheme) Haskell
.
- References:
- Prev by Date: Re: help with statistics library
- Next by Date: Re: random integer
- Previous by thread: Re: How to judge if the graph is cyclic when add a new edge?
- Next by thread: Re: How to judge if the graph is cyclic when add a new edge?
- Index(es):
Relevant Pages
|