Results 1 to 3 of 3
Thread: Multiple paths through trees
- 03-06-2009, 03:30 PM #1
Member
- Join Date
- Mar 2009
- Posts
- 2
- Rep Power
- 0
Multiple paths through trees
Hi
I have a tree structure (root, internal nodes and leaves) and at each internal node I have recorded one or more values.
I want to be able to move from the root to the leaves and generate all possible paths through the tree. Im using recursion to move through the tree and processing each node individually.
i.e. where an internal node has two values I need to generate two paths and if the next node has only one value this is appended to each path and so on.
Therefore the number of possible paths is the product of the number of values at each node.
I have managed to code this but it is inefficient and generates an out of memory error when the number of potential paths through the tree is large (i.e. about 7 million)
I was wondering if anyone could suggest data structures or an api suitable for this type of problem.
Thanks in advance.
- 03-08-2009, 08:08 AM #2
Try adding some indicator. A boolean data which indicates whether that path has already been traversed.
- 03-10-2009, 12:34 PM #3
Member
- Join Date
- Mar 2009
- Posts
- 2
- Rep Power
- 0
Hi Sylar
The problem isn't that I store redundant paths through the tree. Its just that there are so many paths I run out of memory before I have found them all. The problem I think is finding an efficient way to store a large number of strings. I have since tried the StringBuffer class which allowed me to store more objects but still not enough.
Similar Threads
-
passing variable in trees??
By player123 in forum Advanced JavaReplies: 2Last Post: 02-03-2009, 12:42 PM -
Game Trees
By javaBoy1 in forum Advanced JavaReplies: 0Last Post: 12-27-2008, 12:20 AM -
Help With Tournament Trees
By wiggsfly in forum New To JavaReplies: 2Last Post: 10-26-2008, 09:38 PM -
Eclipse with VERY LARGE source trees
By wyrickre in forum EclipseReplies: 0Last Post: 02-01-2008, 02:23 AM -
ElegantJ Trees Bean 1.1
By JavaBean in forum Java SoftwareReplies: 0Last Post: 07-06-2007, 02:59 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks