title: Finding all possible paths in graph
body: <p>I'm looking for some <strong>algorithm</strong> which will help me find <strong>all possible</strong> paths in a graph. Everything I found so far is not <em>fully</em> satisfying.</p>
  
  <p>Let's imagine we have a graph (tree) like this one:<br>
  <a href="https://i.stack.imgur.com/93Vgx.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/93Vgx.png" alt="enter image description here"></a></p>
  
  <p>And let's use some algorithm like <strong>Breadth-First Search</strong> or <strong>Depth-First Search</strong>. In return we'll get something like </p>
  
  <pre><code>1, 2, 4, (2), 5, (2), 6, (2), (1), 3, 7, 8, (7), 9
  </code></pre>
  
  <p>Which is how we go through this tree and this is not what I'm looking for. I'd love to get <em>all</em> paths, like:</p>
  
  <pre><code>1
  1, 2
  1, 2, 4
  1, 2, 5
  1, 2, 6
  1, 3
  1, 3, 7
  1, 3, 7, 8
  1, 3, 7, 9
  </code></pre>
  
  <p>The thing is that I want just to specify <code>root</code> node and algorithm should be able to provide me with all possible paths of any length.</p>
  
  <hr>
  
  <p>So far, the simple code I have looks like:</p>
  
  <pre><code>func dfs(_ graph: Graph, source: Node) -&gt; [String] {
      var nodesExplored = [source.label]
      source.visited = true
  
      for edge in source.neighbors {
          if !edge.neighbor.visited {
              nodesExplored += dfs(graph, source: edge.neighbor)
          }
      }
  
      return nodesExplored
  }
  </code></pre>