0

Sum of all nodes in Binary tree

Problem:

Calculate sum of all nodes in a binary tree.

You refer following image to understand  function calls in above recursive method.

Sum of Nodes recursive stack trace

 

We need to visit all nodes, so time complexity will be O( n)


Warning: count(): Parameter must be an array or an object that implements Countable in /home/algotu5/public_html/wp-includes/class-wp-comment-query.php on line 405