Used to solve prefix sum problems. Why use BIT: can calculate prefix sums and update the sum with O(logn) efficiency.
Construct a BIT from a int array
LC collection: https://leetcode.com/tag/binary-indexed-tree/
1  | class BinaryIndexedTree:  | 
307. Range Sum Query - Mutable
Leetcode: https://leetcode.com/problems/range-sum-query-mutable/
1  | class NumArray:  | 
Binary Indexed Tree (Fenwick Array) (树状数组)
Indexed Tree: o(1) get child node and parent node
index i => complete tree
left child index = 2i + 1
right child index = 2i + 2
parent: (i - 1)/2
Use case:
- Range Sum, Query
 - 所有BIT能解决的问题都能被 segment tree解决
 
implemented in array
315. Count of Smaller Numbers After Self
Leetcode: https://leetcode.com/problems/count-of-smaller-numbers-after-self/
1  | # Got TLE somehow :(  |