Get the latest tech news

You could have invented Fenwick trees


You could have invented Fenwick trees - Volume 35

Although this implementation is simple and relatively straightforward to understand, compared to simply storing the sequence of values in an array, it incurs a good deal of overhead. Finally, the following definition of negation is probably familiar to anyone who has studied two’s complement arithmetic; I leave it as an exercise for the interested reader to prove that ${{x}\oplus{neg}\;{x}\equiv {Rep}\;{O}}$ for all ${{x}\mathbin{::}{Bits}}$ . Recall that the imperative code for update works this way, apparently finding the closest active parent at each step by adding the LSB of the current index:

Get the Android app

Or read this on Hacker News

Read more on:

Photo of Fenwick

Fenwick

Photo of Fenwick trees

Fenwick trees