# BinaryIndexedTree | data-structure-typed
Documentation for data-structure-typed

# Class BinaryIndexedTree

data-structure-typed

#### Author

Tyler Zeng

#### Copyright

Copyright (c) 2022 Tyler Zeng zrwusa@gmail.com

#### License

MIT License

#### Hierarchy

- BinaryIndexedTree

- Defined in src/data-structures/binary-tree/binary-indexed-tree.ts:8

#####
Index

### Constructors

constructor

### Properties

_sumTree

### Accessors

sumTree

### Methods

_setSumTree
getPrefixSum
getRangeSum
update
lowBit

## Constructors

### constructor

- new BinaryIndexedTree(n): BinaryIndexedTree

- 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

  - Defined in src/data-structures/binary-tree/binary-indexed-tree.ts:15

## Properties

### `Private` _sumTree

_sumTree: number[]

- Defined in src/data-structures/binary-tree/binary-indexed-tree.ts:19

## Accessors

### sumTree

- get sumTree(): number[]

- #### Returns number[]

  - Defined in src/data-structures/binary-tree/binary-indexed-tree.ts:21

## Methods

### `Protected` _setSumTree

- _setSumTree(value): void

- #### Parameters

  - ##### value: number[]

  #### Returns void

  - Defined in src/data-structures/binary-tree/binary-indexed-tree.ts:73

### getPrefixSum

- getPrefixSum(i): number

- 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`.

  - Defined in src/data-structures/binary-tree/binary-indexed-tree.ts:51

### getRangeSum

- getRangeSum(start, end): number

- 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.

  - Defined in src/data-structures/binary-tree/binary-indexed-tree.ts:68

### update

- update(i, delta): void

- 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

  - Defined in src/data-structures/binary-tree/binary-indexed-tree.ts:37

### `Static` lowBit

- lowBit(x): number

- #### Parameters

  - ##### x: number

  #### Returns number

  - Defined in src/data-structures/binary-tree/binary-indexed-tree.ts:25

Generated using TypeDoc