Help needed with first segment tree problem.

Revision en1, by iamdumb, 2015-06-20 08:39:50

Hello everyone,I have just learnt segment tree(range sum and range min/max).I tried first segment tree question which is this.But I am getting what value should I assign to the parents while building the tree.I know What to assign to leaf nodes but not getting to the parent.Here I am facing problem

void build(string &s,int pos,int low,int high)
{
    if(low==high)
    {
        tree[pos]=s[low]-'0';
        return;
    }
    int mid=(low+high)/2;
    build(s,2*pos,low,mid);
    build(s,2*pos+1,mid+1,high);
    tree[pos]=                    //Here ?? What should be in this place
}
Tags segment tree

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English iamdumb 2015-06-20 08:39:50 748 Initial revision (published)