title: Gremlin recursive graph traversal with parent and child relationship
body: <p>I want to traverse a tree and aggregate the parent and its immediate children only. How would I do this using Gremlin and aggregate this into a structure list arrayOf({parent1,child},{child, child1}...}</p>
  <p><a href="https://i.stack.imgur.com/kJpQ2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kJpQ2.png" alt="Example graph here" /></a></p>
  <p>In this case I want to output <code>[{0,1}, {0,2}, {1,8} {1,6}, {2,7},{2,9}, {8,16},{8,14},{8,15},{7,17}}</code></p>
  <p>The order isnt important. Also, note I want to avoid any circular edges which can exist on the same node only (no circular loop possible from a child vertex to a parent)</p>
  <p>Each vertex has a label <em>city</em> and each edge has a label <em>highway</em></p>
  <pre><code>g.V().hasLabel(&quot;city&quot;).toList().map(x-&gt;x.id()+x.edges(Direction.OUT,&quot;highway&quot;).collect(Collectors.toList())
  </code></pre>
  <p>My query is timing out and I was wondering if there is a faster way to do this. I have abt 5000 vertices and two vertices are connected with only one edge.</p>