MCPcopy Index your code
hub / github.com/TheAlgorithms/Python / __init__

Method __init__

data_structures/binary_tree/fenwick_tree.py:11–26  ·  view source on GitHub ↗

Constructor for the Fenwick tree Parameters: arr (list): list of elements to initialize the tree with (optional) size (int): size of the Fenwick tree (if arr is None)

(self, arr: list[int] | None = None, size: int | None = None)

Source from the content-addressed store, hash-verified

9 """
10
11 def __init__(self, arr: list[int] | None = None, size: int | None = None) -> None:
12 """
13 Constructor for the Fenwick tree
14
15 Parameters:
16 arr (list): list of elements to initialize the tree with (optional)
17 size (int): size of the Fenwick tree (if arr is None)
18 """
19
20 if arr is None and size is not None:
21 self.size = size
22 self.tree = [0] * size
23 elif arr is not None:
24 self.init(arr)
25 else:
26 raise ValueError("Either arr or size must be specified")
27
28 def init(self, arr: list[int]) -> None:
29 """

Callers

nothing calls this directly

Calls 1

initMethod · 0.95

Tested by

no test coverage detected