August 26, 2024

P82 - Cycle from a given node.

Write a method namedfindCyclesto find closed paths (cycles) starting at a given node in a graph. The method should return all cycles.

> Graph.fromString("[b-c, f-c, g-h, d, f-b, k-f, h-g]").findCycles("f")
  res0: List[List[String]] = List(List(f, c, b, f), List(f, b, c, f))
Be first to comment
Leave a reply