Get the tools you need to learn Java skills fast!
Video tutorials, eBooks, hands-on lab exercises, sample code.
Get started
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

Win a copy of The Software Craftsman this week in the Agile forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "algorithm problem with recursion" Watch "algorithm problem with recursion" New topic

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...

Steve Fahlbusch

Joined: Sep 18, 2000
Posts: 593

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...
Have you tried LearnNowOnline?
subject: algorithm problem with recursion