# how to suppress carefully a recursive tree

Date: Tue, 22 Jan 2008 03:04:40 -0800 (PST)

Message-ID: <dd97afc6-4cb5-45ad-b673-5eba38caa715_at_i7g2000prf.googlegroups.com>

I know how to suppress a normal tree but I meet the following kind of situation :

r1

-> b1

-> b2 -> ...

-> b3 -> ...

-> b2

-> b1 -> ...

-> b1 -> ...

-> b3

* -> b4
*

r2

-> b3 -> ...

A same node can be referenced at several places. Each node is associated to a storage count :

r1(0) b1(3) b2(2) b3(3) b4(1) r2(0)

In a normal tree without recursion (in the example above, recursion occurs because b1 contains b2 and vice versa), a node is destroyed when its count storage is equal to zero else its count storage is simply decremented.

What algorithm should be applied ? I want for instance to cleanup r1 but, of course, r2 must remain valid (=> b3 and b4 are not destroyed during the process and their storage count must be b3(1) b4(1)).

Notice that the deletion of of a tree must be possible even if the count storage of the root is not equal to zero :

r1 -> b1 -> b2 -> r1 -> ... Received on Tue Jan 22 2008 - 12:04:40 CET