title: Ruby recursive DFS method
body: <p>I have some troubles with recursive method for depth first search algorithm implementation. Here's the binary tree photo:</p>
  
  <p><img src="https://i.stack.imgur.com/Vl5XT.jpg" alt="enter image description here"></p>
  
  <p>The method works well with the right side of the tree (55, 89, 144), but it returns nil when it comes to the left side, even though it puts "yes". So, what's wrong with the code? The node is an instance of Node class that has value (integer) and links to the left and right child (other instances of Node class) which is nil if it doesn't have the child from that side.</p>
  
  <p>Here's the method code:</p>
  
  <pre><code>def depth_first_search(node, target)
      if node.value == target
          puts "yes"
          return node
      end
      depth_first_search(node.child_left, target) if node.child_left
      depth_first_search(node.child_right, target) if node.child_right
  end
  </code></pre>