Just a slight addition , you would also like to keep a record for the maximum range of the levels (assuming the function is called as (root , 0))
On Feb 14, 5:25 pm, jalaj jaiswal <jalaj.jaiswa...@gmail.com> wrote: > use hash > > take an array verticalsum[]={0}; > > the function will be like this > void vertcal_sum(node *root, int level){ > if(root!=NULL){ > verticalsum[level]+=root->data; > vertcal_sum(root->left,level-1); > vertcal_sum(root->left,level+1); > } > > > > > > } > On Mon, Feb 14, 2011 at 5:04 PM, bittu <shashank7andr...@gmail.com> wrote: > > Given a binary tree with no size limitation, write a program to find > > the sum of each vertical level and store the result in an appropriate > > data structure (Note: You cannot use an array as the tree can be of > > any size). > > > 4 > > / \ > > 7 8 > > / \ / \ > > 10 11 / 13 > > 12 > > > here 4(root) , 11(leftsubtree's right child ), 12 (rightsubtree's left > > child) are in same vertical Line > > > so here vertical line 1 is fro 10 > > vertical line 2 sum is 7 > > > vertical line 3 sum is 4+11+12=27 (May Have Some Doubt So i Have > > represented the figure in correct way) > > > vertical line 4 is 8 > > vertical line 5 is 13 > > > Hope its clear to every one > > > Thanks & Regards > > Shashank Mani > > > -- > > You received this message because you are subscribed to the Google Groups > > "Algorithm Geeks" group. > > To post to this group, send email to algogeeks@googlegroups.com. > > To unsubscribe from this group, send email to > > algogeeks+unsubscr...@googlegroups.com. > > For more options, visit this group at > >http://groups.google.com/group/algogeeks?hl=en. > > -- > With Regards, > *Jalaj Jaiswal* (+919019947895) > Software developer, Cisco Systems > B.Tech IIIT ALLAHABAD -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.