• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Algorithm � Find all the available paths in a graph

 
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey,

I need to find all the available paths from a root object.
Since in java objects can have references in the two directions, we are talking on a graph.

I want to get a reference to a class type and return a list of all the available paths from this object type.
If I have a reference from A->B->C->D and also A->D I need to have the two paths.

Performance is not important because this process run in offline. Simplicity is much important.

Can you please advice on the suitable algorithm for this?

Thank you
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you comfortable with recursion? You can make a "brute force" routine to try every path and report the ones that get to "D". Off the top of my head, no verification, something like ...

See if you can make that run in Java, show us your code, and we'll talk about some optimizations.
 
avihai marchiano
Ranch Hand
Posts: 342
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think this is DFS
reply
    Bookmark Topic Watch Topic
  • New Topic