Please read the new rule regarding the restriction on the use of AI tools. ×

Why do point updates work in a Fenwick Tree (Binary Indexed Tree) ?

Revision en1, by mshereef, 2021-08-27 20:07:36

I recently learnt about the Fenwick Tree data structure and i understand how everything works and how it is implemented.

Now my issue is in the point update algorithm:

I understand why adding the LSB to a number would get us the next number with a range that also contains/covers the current number we are on. This is because adding any number less than the LSB won’t work, as well as a number with the same LSB can not cover our current number either (Proof in this article). Therefore the only possible option left is a number with a greater LSB, and to get the smallest such number this can be done by adding the LSB to the current number, and I understand why this number will always cover the previous number we were on.

Now what I can’t see is why adding the LSB again to the number we moved on to would also get us the next range that we need to update. I tried reading this article with the same question but I could not find any useful answer.

If anyone can help me with this I would really appreciate it because personally it doesn’t feel right using something without understanding why it works.

Thank you in advance.

Tags #fenwick tree, binary-indexed-tree, #range query, point update

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English mshereef 2021-08-27 20:07:36 1300 Initial revision (published)