@ all,Here first we have find the width of the tree(means how many columns are in the tree) after that we make a array of size of that much width.
void total_no_col(NODEPTR tmp,int cur_col,int *l,int *r) { if(!tmp) return; if(cur_col<*l) *l=cur_col; if(cur_col>*r) *r=cur_col; total_no_col(tmp->left,cur_col-1,l,r); total_no_col(tmp->right,cur_col+1,l,r); } In total_no_col function() so, here as in the code given by me, I start with cur_col=0 and when I Travers left side then I decrement the value by 1 and when I Travers right side then I increment by 1. total no. of columns= (lowest number)*(-1) give me the number of column on left side of the root + Highest number give me the number of column on right side of the root + 1(for column containing root node) void sumofcol(NODEPTR tmp,int cur_col,int sum[]) { if(!tmp) return; sum[cur_col]+=tmp->data; sumofcol(tmp->left,cur_col-1,sum); sumofcol(tmp->right,cur_col+1,sum); } In this function I am doing sum of all elements(column wise) in array sum[total_number_of_column] as described below, Initially array sum is initialised by 0. 4 / \ 7 8 / \ / \ 10 11 / 13 12 Index of the column containing root node is equal to number of column on left side of the root node ,here in above example it is 2. this value is the starting cur_col value which I passed to sumofcol function. now we can Travers the tree in any one of pre,in,post-order. I had followed pre-order traversal. Now I am adding the value of node in array sum column wise by recursively. -- 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.