Class BinaryIndexedTree

Copyright

2030 Tyler Zeng zrwusa@gmail.com

License

MIT

Hierarchy

  • BinaryIndexedTree

Constructors

Properties

Methods

Constructors

  • The constructor initializes an array with a specified length and fills it with zeros.

    Parameters

    • n: number

      The parameter n represents the size of the array that will be used to store the sum tree. The sum tree is a binary tree data structure used to efficiently calculate the sum of a range of elements in an array. The size of the sum tree array is n + 1 because

    Returns BinaryIndexedTree

Properties

_sumTree: number[]

Methods

  • The function calculates the prefix sum of an array using a binary indexed tree.

    Parameters

    • i: number

      The parameter "i" in the function "getPrefixSum" represents the index of the element in the array for which we want to calculate the prefix sum.

    Returns number

    The function getPrefixSum returns the prefix sum of the elements in the binary indexed tree up to index i.

  • The function getRangeSum calculates the sum of a range of numbers in an array.

    Parameters

    • start: number

      The start parameter is the starting index of the range for which we want to calculate the sum.

    • end: number

      The "end" parameter represents the ending index of the range for which we want to calculate the sum.

    Returns number

    the sum of the elements in the range specified by the start and end indices.

  • The update function updates the values in a binary indexed tree by adding a delta value to the specified index and its ancestors.

    Parameters

    • i: number

      The parameter i represents the index of the element in the _sumTree array that needs to be updated.

    • delta: number

      The "delta" parameter represents the change in value that needs to be added to the element at index "i" in the "_sumTree" array.

    Returns void

Generated using TypeDoc