views:

52

answers:

2

I'm looking for a tool that finds duplicate nodes in a tree data structure (using Freemind to map the data structure, but I'll settle for anything I can export a generic data tree out too...)

The idea is that I can break the tree down into modules which I can repeat thus simplifying the structure of the tree.

A: 

Wouldn't it actually be better to prevent duplicate nodes in a tree? Why do you need duplicate nodes in a tree?

sybreon
Yes, it would be much better. But it's not a luxury I have on my job. I didn't write the stuff, someone else did. I'm trying to "clean up after them" as it were.
leeand00
+1  A: 

I would just have a table of subtrees.

Walk the tree depth-first. At each node, after visiting sub-nodes, if there is an equivalent node in the table, replace the current node with the one in the table. If there is not an equivalent node in the table, then add the current node to the table.

Does that do it? I believe it's called common-subexpression-elimination.

Mike Dunlavey
Sounds good man, and thanks for the technical name for it, that'll make it easier to research. :)
leeand00
As a web developer it seems that I'm always doing this...
leeand00
@leeand00: Good luck. If you need some sample (pseudo)code I can gen up some.
Mike Dunlavey