in reply to Re^3: algorithm for 'best subsets'
in thread algorithm for 'best subsets'
I suppose you could use Graph::UnionFind by itself, but it would be horrendously inefficient. You would have to compare each pair of items to see if they intersected -- O(N^2). With my method (once I get it working right) I only have to test against the combined bit-set of each partition -- O(N*P) where P is the average number of partitions.
If you really want to scale to tens of thousands of items, I think this is the right approach. However, trying to work from the outside of Graph::UnionFind was probably a mistake. I need to create a modified version that stores the bit-vectors as part of the internal structure. Then, as it re-organizes itself, it would be able to keep the information accurately.
UnionFind uses a forest of n-ary trees which have only parent pointers. You can easily go from a child to the root, but not vice-versa. It can also "flatten" the tree by making more of the pointers go directly to the top. I believe the flattening is what is causing me to lose information.
There are many references to the "union find" algorithm, some with animated Java applets. Here is one.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^5: algorithm for 'best subsets'
by halley (Prior) on Mar 05, 2005 at 15:57 UTC | |
by tall_man (Parson) on Mar 06, 2005 at 13:43 UTC |