A FenwickTree, also known as a Binary Indexed Tree, is a data structure that provides efficient methods for cumulative frequency tables, allowing for quick updates and prefix sum queries.
import { FenwickTree } from "collection-kit";
import { FenwickTree } from "collection-kit";
const arr = [1, 2, 3, 4, 5];
const fenwick = new FenwickTree(arr);
console.log("Prefix sum [0-2]:", fenwick.query(2)); // 6
fenwick.update(1, 5);
console.log("Prefix sum [0-2]:", fenwick.query(2)); // 9