title: How to find number of possible binary tree topological permutations?
body: <p>Given number of binary tree nodes (X) write method that returns the number of random permutations of binary trees with X nodes.</p>
  
  <p><strong>Examples:</strong></p>
  
  <p><strong>X=1: 1</strong></p>
  
  <pre><code>     o
  </code></pre>
  
  <p><strong>X=2: 2</strong></p>
  
  <pre><code>     o    o
     o        o
  </code></pre>
  
  <p><strong>X=3: 5</strong></p>
  
  <pre><code>        o    o          o     o        o
        o        o      o         o    o   o
      o            o      o     o
  </code></pre>
  
  <p>I ended up with :</p>
  
  <pre><code>    public static int numOfPerms(int numOfNodes) {
         if (numOfNodes&lt;=2 &amp;&amp; numOfNodes &gt; 0) {
             return numOfNodes;
         }
         int res = 1;
         for (int i=1; i&lt;=numOfNodes; i++) {
             res = res*(4*i-1)/(i+1);
         }
         return res;
      } 
  </code></pre>
  
  <p>I would appreciate sharing here better solutions.</p>