title: How to get all leaf nodes from any parent node in a tree
body: <p>I am developing an app in android using Sqlite, I have a tree structure which I represent in the db like so :</p>
  
  <pre><code>        +------+------+-------+------+
          |comp_id nodeId parent| text |
          |------|------|-------|------|
          |  146 |  1   |  -1   | Top  |
          |      |      |       |      |
          | 146  |  2   |  1    | Ch1  |
          |      |      |       |      |
          | 146  |  3   |  2    | Leaf |
          |      |      |       |      |
          |  ... |      |       |      |
          | 152  |  1   |  -1   | Top  |
          +------+------+-------+------+
  </code></pre>
  
  <p>I am having difficulty coding an algorithm in a self contained method like below to return me all the leafs under any node.</p>
  
  <pre><code>Node
  {
     public Node[] getAllLeafs()
     {
        // traverse all the way down the tree
        // and get only leafs
     }
  }
  </code></pre>
  
  <p>If there is a way to accomplish this more easily by modifying my table structure and/or using SQL please mention that as I am able to do so.</p>