title: Gremlin - Traverse to leaf nodes in tree graph
body: <p>I have tree data structure in graph as shown in below diagram. Each color represents node with different labels with relation like employee -> app -> project -> pv -> scan). </p>
  
  <p><strong>Question #1:</strong></p>
  
  <p>I want to find all leaf nodes (ones in green) of top node 0. </p>
  
  <p>I tried below code with loop which returns all nodes with label employee. Not just leaf nodes.</p>
  
  <pre><code>g.V().has('person', 'id', '0').repeat(__.in('reportsTo')).emit().values('id')
  </code></pre>
  
  <p>Sample graph can be found in <a href="http://www.gremlinbin.com/bin/view/5a577fed6d8c1" rel="nofollow noreferrer">gremlinbin</a>. </p>
  
  <p>How do I find all green leaf nodes? </p>
  
  <p><strong>Update #1:</strong></p>
  
  <p>As mentioned in comments, I tried tree pattern. But it doesn't let me call getLeafObjects() on tree. Not sure what's missing. Also, again I am able to create tree of employee nodes only. How to traverse to scan nodes?</p>
  
  <pre><code>&gt; tree = g.V().has('person', 'id', '0').repeat(__.in('reportsTo')).emit().tree()
  &gt;  tree.getLeafObjects()
  No signature of method: org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal.getLeafObjects() is applicable for argument types: () values: []
  </code></pre>
  
  <p><strong>Question #2:</strong></p>
  
  <p>How do I retrieve a child vertex amongst children under each parent based on max(id)? So in my sample graph, each black vertex can have one or more green child vertex. I want to find the green vertices with max(property) under each black vertices. </p>
  
  <p><a href="https://i.stack.imgur.com/o4S5g.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/o4S5g.png" alt="enter image description here"></a></p>