-2

Can some one help me understand in binary index tree when we do range update- Why no we update every element why only starting element and ending element

For example 0

we have to update array element range in BIT for arr[x] to arr[y] .As per binary index tree point update function .It will update cumulative frequency of index x and all those indexes > than x which will get effected by update.


But if we are using point update function for range update.Than why we are not updating every index greater than x and less than y using point update function. Since range update meaning every element should be updated with value and how does updating starting index and one above end index cover all updates

why we are not doing

..................................................

 for (i =[x] to [y])
    pointupdate(ar[i],val);// why we are not doing this 

update(p, v): //point update
  for (; p <= N; p += p&(-p))
    ft[p] += v   

# Add v to A[a...b] 
update(a, b, v):     // why we are using this only for update of one element how other elements greater than a will be coverd
  update(a, v)     
  update(b + 1, -v)     

I

1 Answers1

0

When you update the BIT[a]+=v, this means that query on every index x>=a will see the v increment.

To perform a range update this way, you increment v on the range begin and decrement v after the range end. This means only between a and b the increment will be visible.

Juan Lopes
  • 10,143
  • 2
  • 25
  • 44