Write a program to find Average of Nodes in tree

To find average , Maglia Larry Bird calculate the sum of all node by traversing whole tree and divide it by number of node it contains . mochilas fjallraven kanken baratas Code :

 void average(Node n,  <a href="http://www.rgmwebmedia.nl/">Ray Ban nederland</a> int sumcount[]) { if (n == null) return; sumcount[0] += n.data; // Store the sum of data sumcount[1] += 1; // Store the count of node .  <a href="http://www.dodgersfanszone.com/authentic/scott-kazmir-authentic-jersey.html">Scott Kazmir Authentic Jersey</a> average(n.left,  <a href="http://www.aqualet.fr/newbalance.php?soldes_id=bjx18YZ-nbfr-new-balance-mrl996dd-deconstructed-khakikhaki--cher">new balance mrl996dd deconstructed khakikhaki</a> sumcount); average(n.right,  <a href="http://www.dorodni.pl/buty-asics-meskie/asics-gel-nimbus-17-meskie.html">Asics Gel Nimbus 17 męskie</a> sumcount); } Average will be sumcount[0]/sumcount[1]

Time & Space Complexities: Since this program is similar to traversal of tree,

Leave a Reply

Your email address will not be published. Required fields are marked *

For Inserting code :
Paste your code in the comment form, select it and then click the language link

C | C++ | Java |

*