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 corresponds to
1st level.
                   Now let temp=L.
                   Traverse back from the leftmost tree to its parent(if
T.root is reached then start traversing towards right)
                   For each traverse decrease temp by 1.Keep on doing this
till temp is not equal to 1.
                   let temp. Call sum_find(temp)

For 2nd part : int sum=0;
                     int sum_find(node)
                           {if (node==null)   return 0;
                            else return ( sum + sum_find(node.left.right) +
sum_find(node.right.left) )    }


Cheers,
Sehaj Singh Kalra
IIT Delhi
B.Tech,Computer Science Department,
2nd Sem.



>
>

-- 
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.

Reply via email to