title: in Binary Tree ,checking if given node is leaf node or not
body: <p>I have written the code to find if the given node is leaf node or not , It works fine for positive case , i.e. when the entered node is a leaf node , the code code traverse till the node and and if it is leaf node , gives the output and stops , but the negative scenario is failing when the entered node is not a leaf node, The code keeps traversing the complete tree even when it has passed through the node and it is not a leaf node.</p>
  
  <pre><code>boolean isLeaf(BTNode node, int data) {
     if (node == null) {
      return false;
     }
  System.out.println("Node traversed :"+ node.data);
  if (node.left == null &amp;&amp; node.right == null &amp;&amp; node.data == data) {
      System.out.println("Node : " + node.data + " is leaf node");
      return true;
  }
  return (isLeaf(node.left, data) || isLeaf(node.right, data));
  }
  </code></pre>
  
  <p>Can any one tell what is the condition to stop the recursion if the node is found and  it is not a leaf node.</p>
  
  <p>Thanks.</p>