Why should we start traversing towards right ?
root will be the ultimate parent anyways . May be I din get your
approach .Can you elaborate with an example as given by the Thread
starter ?
For vertical level 1 . The node is 10 and hence the sum is 10 .
For vertical line 2 (level 2) , going left
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
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,
It would be
*vertcal_sum(root-right,level+1);
*in the last line
--
Tushar Bindal
Computer Engineering
Delhi College of Engineering
Mob: +919818442705
E-Mail : tusharbin...@jugadengg.com, tushicom...@gmail.com
--
You received this message because you are subscribed to the Google Groups
Claim: any given vertical line will start with a node.(This is obvious)
Divide this problem into 2 subparts.
1st: Finding the starting node of given line.
2nd : finding the required sum.
Let T be the tree and L be the given level.
For 1st part: Find the leftmost node of the given tree,T.This
HAD MISSED OUT SOPME THINGS IN PREVIOUS REPLY.
SORRY GUYS
hereby i rectify the mistakes:
Claim: any given vertical line will start with a node.(This is obvious)
Divide this problem into 2 subparts.
1st: Finding the starting node of given line.
2nd : finding the required sum.
Let T
@tushar thnxx for correction :D
On Mon, Feb 14, 2011 at 7:50 PM, SEHAJ SINGH KALRA sehaj...@gmail.comwrote:
HAD MISSED OUT SOPME THINGS IN PREVIOUS REPLY.
SORRY GUYS
hereby i rectify the mistakes:
Claim: any given vertical line will start with a node.(This is obvious)
Divide