nd-binary-indexed-tree

1.0.0 • Public • Published

N-dimensional Binary Indexed Tree

Provides logarithmic time prefix-sums and updates to numeric data sets in 1, 2, 3, or more dimensions.

Check out Stack Overflow, Wikipedia, and TopCoder for an overview of the data structure in one dimension. GeeksForGeeks has a useful explanation of multi-dimensional generalization, but beware of buggy code.

NPM version Build Status

Getting Started

Install from NPM

$ npm install nd-binary-indexed-tree

Examples

const BITree = require('nd-binary-indexed-tree');
let biTree = new BITree({initialValues: [
  [3,  1, 5  ],
  [0, -1, 9.5],
  [4,  4, 90 ]
]});
biTree.sumPrefix([2, 1]); // 11
biTree.adjust([1, 1], +2);
biTree.sumPrefix([2, 1]); // 13
;

See tests for more examples.

Package Sidebar

Install

npm i nd-binary-indexed-tree

Weekly Downloads

0

Version

1.0.0

License

MIT

Last publish

Collaborators

  • hurrymaplelad