Hierarchy

  • SegmentTree

Constructors

  • The constructor initializes the values, start, end, and root properties of an object.

    Parameters

    • values: number[]

      An array of numbers that will be used to build a binary search tree.

    • Optional start: number

      The start parameter is the index of the first element in the values array that should be included in the range. If no value is provided for start, it defaults to 0, which means the range starts from the beginning of the array.

    • Optional end: number

      The "end" parameter is the index of the last element in the "values" array that should be included in the range. If not provided, it defaults to the index of the last element in the "values" array.

    Returns SegmentTree

Properties

_end: number
_root: null | SegmentTreeNode
_start: number = 0
_values: number[] = []

Accessors

Methods

  • The function builds a segment tree by recursively dividing the given range into smaller segments and creating nodes for each segment.

    Parameters

    • start: number

      The start parameter represents the starting index of the segment or range for which we are building the segment tree.

    • end: number

      The end parameter represents the ending index of the segment or range for which we are building the segment tree.

    Returns SegmentTreeNode

    a SegmentTreeNode object.

  • The function querySumByRange calculates the sum of values within a given range in a segment tree.

    Parameters

    • indexA: number

      The starting index of the range for which you want to calculate the sum.

    • indexB: number

      The parameter indexB represents the ending index of the range for which you want to calculate the sum.

    Returns number

    The function querySumByRange returns a number.

  • The function updates the value of a node in a segment tree and recalculates the sum of its children if they exist.

    Parameters

    • index: number

      The index parameter represents the index of the node in the segment tree that needs to be updated.

    • sum: number

      The sum parameter represents the new value that should be assigned to the sum property of the SegmentTreeNode at the specified index.

    • Optional val: number

      The val parameter is an optional value that can be assigned to the val property of the SegmentTreeNode object. It is not currently used in the code, but you can uncomment the line // cur.val = val; and pass a value for val in the

    Returns void

    The function does not return anything.

Generated using TypeDoc