Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

algorithm problem with recursion

 
Max Vandenburg
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Bartender
Posts: 605
7
Mac OS X Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Given the data shouldn't your output be:



Or are there some other rules here?
 
Max Vandenburg
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic