On Tue, Oct 18, 2011 at 6:31 PM, rahul patil <rahul.deshmukhpa...@gmail.com>wrote:
> Use recursion with the code as follows > > sum array of sums, with horizontal levels, level 0 is for leftmost element > > void add(node *root, int *sum, int level) > { > if(root->left) > { if(level != -1) > level = add(root->left,sum, level-1); > else /* go till left with level =- 1 i.e uninitialized*/ > level = add(root->left,sum, level); > /*level of root is level of left node plus 1*/ level += 1; } /*set level =0 for leftmost element*/ if(level == -1) level = 0; /*level of right node is level of parent +1 */ if(root->right) level = add(root->right,sum, level+1); return level; } call with add(root, sum, -1); > > > > On Tue, Oct 18, 2011 at 8:58 AM, sravanreddy001 > <sravanreddy...@gmail.com>wrote: > >> I that is what is suggested in the above code. Even here you can avoid the >> sorting and add all with same x coordinate.. O(n) space as suggested.. >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To view this discussion on the web visit >> https://groups.google.com/d/msg/algogeeks/-/CZ2rgqRAlW0J. >> 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. >> >> > > > -- > Regards, > Rahul Patil > -- Regards, Rahul Patil -- 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.