Fenwick tree
What is a Fenwick tree?
I raise you a better one, who is Fenwick
I imagine Fenwick tree to be another version of LSM tree in database (wow, my database background still affecting me), but it doesn't grow
It doubles every layer as there are data coming in, the differences is that how it is organizing the data
It uses this weird trick:
class Fenwick:
"""1-indexed Binary Indexed Tree for prefix sums."""
def __init__(self, n: int):
self.n = n
self.tree = [0] * (n + 1)
def add(self, i: int, delta: int) -> None:
# Walk up: every node whose block covers index i
while i <= self.n:
self.tree[i] += delta
i += i & -ithe i += i & -i
trick to find the closest block/node that you should be adding it to, and as you can see it walks up/propagate upwards
This is a clever way to do prefix sum, where you will need to find sum of range x or x - y making it easier if you just subtract the left and right to get the sum of that range.
The runtime should be O(logn) for querying, and updating the sum of a range (this happens if you update a value in the array and you need to update the block currently at and above)
Side note:
Here is the GPT 3 beta access I got during the freshman summer XD, I think I was trying to make an app that does my middle cousin's homework. (It wasn't too good)

if anyone at OpenAI reading this, can I get unlimited token? I'm down to contribute to what you guys do