aspose file tools*
The moose likes Java in General and the fly likes algorithm problem with recursion Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "algorithm problem with recursion" Watch "algorithm problem with recursion" New topic
Author

algorithm problem with recursion

Max Vandenburg
Ranch Hand

Joined: Mar 09, 2006
Posts: 51
I have an algorithm problem with recursion:

i have a route from A to D and it looks like this



the alphabet in the above list is an object of a class, lets call that class Nodes

each of this Nodes object they have some attributes... these are of type set..

the first set will store a bunch of other Nodes (these represent the current nodes neighbour)
the second set will store a bunch of tracks (Integer object representing what tracks the current nodes belong to)

(... bare with me here... )

so now i write up some code that initialise all the nodes... and here is the output...



and here is the code: (i removed the System.out... to shorten the code..)



what i want to do is to come up with some recursive algorithm so that it would print out something like this...

so i've come up with a pseudo code...


i've also come up with an actuall code but for some reason it'll only prints out the first step...

the code for this to follow...


MV
Steve Fahlbusch
Bartender

Joined: Sep 18, 2000
Posts: 562
    
    7

Given the data shouldn't your output be:



Or are there some other rules here?
Max Vandenburg
Ranch Hand

Joined: Mar 09, 2006
Posts: 51
No. Here is the output from again



here A has 3 next neighbours that is B Z and E
and A has a/belongs to 3 tracks 1, 2, and 3

and we are given a route from A - B - C - D

so from A we are only interested with B (dont care about Z & E)
then we look at the what track A has and we also look at what track B has...
in this case track 1 is a match...

so then we do a next matching

B neighbour is A and C. A is already been visited... so we only care about C... see for macthing line and between B and C which is 1... and so on...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: algorithm problem with recursion