0

I am trying to work on a problem which gives me a hamiltonian path in a graph. I am aware of the algorithms used for it but they're all suited for imperative style. My confusion is if I have to use dynamic programming in scala to solve the problem what would be the best approach.Also is there a better algorithm which gives better efficiency than DP (both memory and space) ? Approximation is something I can think of but as far as my knowledge goes it requires a complete graph. Please enlighten me. Thanks!

Harsh Gupta
  • 339
  • 4
  • 20
  • 1
    The algorithms to solve such problems are, for the most part, language independent. You can implement it in Scala just as you would in Java, for instance. Hamiltonian Path algorithms fall in the NP-Complete category, requiring an exhaustive search. – Randomness Slayer Jun 27 '18 at 18:47
  • I understand that they're language independent but I want to understand the functional way of doing it where loops are not breakable or continuable. – Harsh Gupta Jun 27 '18 at 18:54
  • I don't follow. Any loop can be broken out of using conditional statements. If you want to be able to continue, you could make a function call and simply return when complete. – Randomness Slayer Jun 27 '18 at 20:25
  • I think this is a bit too broad for this site, but it is an interesting question. You might consider looking into the State monad - this blog post has some info: https://www.cakesolutions.net/teamblogs/solving-dynamic-programming-problems-using-functional-programming-part-2 You might also post this somewhere else like reddit.com/r/scala or some other more discussion-oriented forum – Joe K Jun 27 '18 at 20:44
  • In case you haven't checked, this [Scala app](https://github.com/uzh/signal-collect/blob/master/src/main/scala/com/signalcollect/examples/Hamiltonian.scala) (limited to certain graph type) might be of interest. – Leo C Jun 27 '18 at 21:46
  • @RandomnessSlayer we sure can but it's not the functional way. – Harsh Gupta Jun 28 '18 at 08:17
  • @JoeK I think your suggestions are helpful. I will take a look at it. – Harsh Gupta Jun 28 '18 at 08:18
  • @LeoC is signal collect some kind of algorithm or design pattern? – Harsh Gupta Jun 28 '18 at 08:18
  • Also one thing which went unanswered was is DP with approximation the ultimate efficient solution for this particular case? – Harsh Gupta Jun 28 '18 at 08:20
  • @Harsh Gupta, [Signal/Collect](http://uzh.github.io/signal-collect/documentation.html) is a programming model for graph processing. – Leo C Jun 28 '18 at 14:26
  • @HarshGupta any for loop can be deconstructed into a recursive function, if you insist on a functional style. I would argue that while Scala allows for more functional styles, it is up to the developers to follow and use these paradigms. How you choose to implement a for loop in Scala is ultimately trivial, it's all compiled using the JVM. Besides, graph algorithms are inherently based on states, which makes it impractical to implement them in a functional, state-less style. – Randomness Slayer Jun 28 '18 at 14:48

0 Answers0