title: Searching a node of a binary tree in Prolog
body: <p>A beginner in Prolog,working with binary trees for some hours.But as a newcomer in Prolog world,a little bit confused about it's working procedure.
  I do some code to form a tree and counting nodes of the tree.When i test,the program outputs just like as..</p>
  
  <pre><code>?- constructTree(T),count_nodes(T,N).
  T = tree(1, tree(2, tree(3, nil, nil), tree(4, nil, nil)), tree(5, tree(6, nil, nil), tree(7, nil, nil))),
  N = 7.
  </code></pre>
  
  <p>Where <strong>T</strong> is the corresponding tree and <strong>N</strong> represents the node number of the tree.</p>
  
  <p>Corresponding code is:</p>
  
  <pre><code>constructTree(tree(1,
              tree(2,
                  tree(3,nil,nil),
                  tree(4,nil,nil)),
              tree(5,
                  tree(6,nil,nil),
                  tree(7,nil,nil))
          )
      ).
  count_nodes(nil,0).
  count_nodes(tree(_,L,R),N):-
      count_nodes(L,CL),
      count_nodes(R,CR),
      N is CL+CR+1.
  </code></pre>
  
  <p>How can i implement searching nodes techniques,especially if i want to use <strong>DFS</strong> searching? Consider,i want to find the node 5 using DFS search and count iteration number needs to find that node.
  Explanation along with code will be great helpful to understand this new language..:)</p>