/**

  • Increase the value at the given position in the tree array by the specified value.

  • @param {number} position - The position in the tree array.

  • @param {number} value - The value to be added.

  • @throws {Error} - If the position is outside the allowed range.

  • @returns {Object} - The updated tree array. */ increase(position, value) { if (position < 1 || position > this.arraySize) { throw new Error('Position is out of allowed range'); }

    for (let i = position; i <= this.arraySize; i += (i & -i)) { this.treeArray[i] += value; }

    return this; }

Binary Indexed Tree: Increase Value at Position

原文地址: https://www.cveoy.top/t/topic/qhll 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录