From aa21b2545fd1ef7a7c2499808d885c0dded8fff1 Mon Sep 17 00:00:00 2001 From: AmirMohammad Hosseini Nasab Date: Fri, 12 Aug 2022 10:40:22 +0430 Subject: [PATCH 01/14] Enhance fenwick_tree.py --- data_structures/binary_tree/fenwick_tree.py | 80 +++++++++++++++------ 1 file changed, 58 insertions(+), 22 deletions(-) diff --git a/data_structures/binary_tree/fenwick_tree.py b/data_structures/binary_tree/fenwick_tree.py index 54f0f07ac68d..ec9df75c9345 100644 --- a/data_structures/binary_tree/fenwick_tree.py +++ b/data_structures/binary_tree/fenwick_tree.py @@ -1,28 +1,64 @@ class FenwickTree: - def __init__(self, SIZE): # create fenwick tree with size SIZE - self.Size = SIZE - self.ft = [0 for i in range(0, SIZE)] + """ + Fenwick Tree - def update(self, i, val): # update data (adding) in index i in O(lg N) - while i < self.Size: - self.ft[i] += val - i += i & (-i) + More info: https://en.wikipedia.org/wiki/Fenwick_tree - def query(self, i): # query cumulative data from index 0 to i in O(lg N) - ret = 0 - while i > 0: - ret += self.ft[i] - i -= i & (-i) - return ret + >>> f = FenwickTree(10) + >>> f.query(10) + 0 + >>> f.update(1, 20) + >>> f.query(1) + 0 + >>> f.query(2) + 20 + >>> f.query(3) + 20 + >>> f.update(2, 10) + >>> f.query(2) + 20 + >>> f.query(3) + 30 + >>> f.query(10) + 30 + """ + + def __init__(self, size: int): + """ + Initialize a Fenwick tree with size elements + """ + self.size = size + self.tree = [0] * (size + 1) + + @staticmethod + def next(index: int): + return index + (index & (-index)) + + @staticmethod + def prev(index: int): + return index - (index & (-index)) + + def update(self, index: int, value: int): + """ + Add a value to index in O(lg N) + """ + index += 1 # 1-indexed + while index < self.size: + self.tree[index] += value + index = self.next(index) + + def query(self, right: int): + """ + Query the sum of all elements in [0, right) in O(lg N) + """ + result = 0 + while right > 0: + result += self.tree[right] + right = self.prev(right) + return result if __name__ == "__main__": - f = FenwickTree(100) - f.update(1, 20) - f.update(4, 4) - print(f.query(1)) - print(f.query(3)) - print(f.query(4)) - f.update(2, -5) - print(f.query(1)) - print(f.query(3)) + import doctest + + doctest.testmod() From 85e2ef9682536170380ddf7bb9c418f82c094735 Mon Sep 17 00:00:00 2001 From: AmirMohammad Hosseini Nasab Date: Fri, 12 Aug 2022 10:40:55 +0430 Subject: [PATCH 02/14] Change update to add in fenwick_tree.py --- data_structures/binary_tree/fenwick_tree.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/data_structures/binary_tree/fenwick_tree.py b/data_structures/binary_tree/fenwick_tree.py index ec9df75c9345..4d01644ac733 100644 --- a/data_structures/binary_tree/fenwick_tree.py +++ b/data_structures/binary_tree/fenwick_tree.py @@ -7,14 +7,14 @@ class FenwickTree: >>> f = FenwickTree(10) >>> f.query(10) 0 - >>> f.update(1, 20) + >>> f.add(1, 20) >>> f.query(1) 0 >>> f.query(2) 20 >>> f.query(3) 20 - >>> f.update(2, 10) + >>> f.add(2, 10) >>> f.query(2) 20 >>> f.query(3) @@ -38,7 +38,7 @@ def next(index: int): def prev(index: int): return index - (index & (-index)) - def update(self, index: int, value: int): + def add(self, index: int, value: int): """ Add a value to index in O(lg N) """ From 251cf3ed26fcf6717ed5851f76bd2546d969287c Mon Sep 17 00:00:00 2001 From: AmirMohammad Hosseini Nasab Date: Fri, 12 Aug 2022 10:46:20 +0430 Subject: [PATCH 03/14] Some changes --- data_structures/binary_tree/fenwick_tree.py | 64 +++++++++++++++++---- 1 file changed, 53 insertions(+), 11 deletions(-) diff --git a/data_structures/binary_tree/fenwick_tree.py b/data_structures/binary_tree/fenwick_tree.py index 4d01644ac733..8ad8ad5cf9a4 100644 --- a/data_structures/binary_tree/fenwick_tree.py +++ b/data_structures/binary_tree/fenwick_tree.py @@ -5,27 +5,30 @@ class FenwickTree: More info: https://en.wikipedia.org/wiki/Fenwick_tree >>> f = FenwickTree(10) - >>> f.query(10) + >>> f.query(0, 10) 0 >>> f.add(1, 20) - >>> f.query(1) + >>> f.query(0, 1) 0 - >>> f.query(2) + >>> f.query(1, 10) 20 - >>> f.query(3) + >>> f.query(0, 10) 20 - >>> f.add(2, 10) - >>> f.query(2) + >>> f.update(2, 10) + >>> f.query(0, 2) 20 - >>> f.query(3) - 30 - >>> f.query(10) + >>> f.query(2, 3) + 10 + >>> f.query(0, 10) 30 """ def __init__(self, size: int): """ Initialize a Fenwick tree with size elements + + Parameters: + size (int): size of the Fenwick tree """ self.size = size self.tree = [0] * (size + 1) @@ -41,15 +44,41 @@ def prev(index: int): def add(self, index: int, value: int): """ Add a value to index in O(lg N) + + Parameters: + index (int): index to add value to + value (int): value to add to index + + Returns: + None """ index += 1 # 1-indexed while index < self.size: self.tree[index] += value index = self.next(index) - def query(self, right: int): + def update(self, index: int, value: int): + """ + Set the value of index in O(lg N) + + Parameters: + index (int): index to set value to + value (int): value to set in index + + Returns: + None + """ + self.add(index, value - self.query(index, index + 1)) + + def prefix(self, right: int): """ - Query the sum of all elements in [0, right) in O(lg N) + Prefix sum of all elements in [0, right) in O(lg N) + + Parameters: + right (int): right bound of the query (exclusive) + + Returns: + int: sum of all elements in [0, right) """ result = 0 while right > 0: @@ -57,6 +86,19 @@ def query(self, right: int): right = self.prev(right) return result + def query(self, left: int, right: int): + """ + Query the sum of all elements in [left, right) in O(lg N) + + Parameters: + left (int): left bound of the query (inclusive) + right (int): right bound of the query (exclusive) + + Returns: + int: sum of all elements in [left, right) + """ + return self.prefix(right) - self.prefix(left) + if __name__ == "__main__": import doctest From fe1f8ae3330e18d0b2b34cd4963ca1a7aadfa2d8 Mon Sep 17 00:00:00 2001 From: AmirMohammad Hosseini Nasab Date: Fri, 12 Aug 2022 10:53:58 +0430 Subject: [PATCH 04/14] Fix bug --- data_structures/binary_tree/fenwick_tree.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/data_structures/binary_tree/fenwick_tree.py b/data_structures/binary_tree/fenwick_tree.py index 8ad8ad5cf9a4..4a6e6e719612 100644 --- a/data_structures/binary_tree/fenwick_tree.py +++ b/data_structures/binary_tree/fenwick_tree.py @@ -7,6 +7,10 @@ class FenwickTree: >>> f = FenwickTree(10) >>> f.query(0, 10) 0 + >>> f.add(9, 10) + >>> f.prefix(10) + 10 + >>> f.add(9, -10) >>> f.add(1, 20) >>> f.query(0, 1) 0 @@ -53,7 +57,7 @@ def add(self, index: int, value: int): None """ index += 1 # 1-indexed - while index < self.size: + while index < self.size + 1: self.tree[index] += value index = self.next(index) From 015d3f3d4c8d85fb453f40319f53d2fcea25f958 Mon Sep 17 00:00:00 2001 From: AmirMohammad Hosseini Nasab Date: Fri, 12 Aug 2022 10:59:36 +0430 Subject: [PATCH 05/14] Add O(N) initializer to FenwickTree --- data_structures/binary_tree/fenwick_tree.py | 47 ++++++++++++++++++--- 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/data_structures/binary_tree/fenwick_tree.py b/data_structures/binary_tree/fenwick_tree.py index 4a6e6e719612..d11898913a97 100644 --- a/data_structures/binary_tree/fenwick_tree.py +++ b/data_structures/binary_tree/fenwick_tree.py @@ -1,10 +1,13 @@ +from typing import List + + class FenwickTree: """ Fenwick Tree More info: https://en.wikipedia.org/wiki/Fenwick_tree - >>> f = FenwickTree(10) + >>> f = FenwickTree(size=10) >>> f.query(0, 10) 0 >>> f.add(9, 10) @@ -27,15 +30,47 @@ class FenwickTree: 30 """ - def __init__(self, size: int): + def __init__(self, arr: List[int] = None, size: int = None): + """ + 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) + """ + + if arr is None and size is not None: + self.size = size + self.tree = [0] * (size + 1) + elif arr is not None: + self.init(arr) + else: + raise ValueError("Either arr or size must be specified") + + def init(self, arr: List[int]): """ - Initialize a Fenwick tree with size elements + Initialize the Fenwick tree with arr in O(N) Parameters: - size (int): size of the Fenwick tree + arr (list): list of elements to initialize the tree with + + Returns: + None + + >>> a = [1, 2, 3, 4, 5] + >>> f1 = FenwickTree(a) + >>> f2 = FenwickTree(size=len(a)) + >>> for index, value in enumerate(a): + ... f2.add(index, value) + >>> f1.tree == f2.tree + True """ - self.size = size - self.tree = [0] * (size + 1) + self.size = len(arr) + self.tree = [0] + arr + for i in range(1, self.size + 1): + j = self.next(i) + if j < self.size + 1: + self.tree[j] += self.tree[i] @staticmethod def next(index: int): From a45e744afbf69de8883d55410fe87baf97919394 Mon Sep 17 00:00:00 2001 From: AmirMohammad Hosseini Nasab Date: Fri, 12 Aug 2022 11:10:21 +0430 Subject: [PATCH 06/14] Add get method to Fenwick Tree --- data_structures/binary_tree/fenwick_tree.py | 28 +++++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/data_structures/binary_tree/fenwick_tree.py b/data_structures/binary_tree/fenwick_tree.py index d11898913a97..3a4bfa84d60c 100644 --- a/data_structures/binary_tree/fenwick_tree.py +++ b/data_structures/binary_tree/fenwick_tree.py @@ -47,7 +47,7 @@ def __init__(self, arr: List[int] = None, size: int = None): else: raise ValueError("Either arr or size must be specified") - def init(self, arr: List[int]): + def init(self, arr: List[int]) -> None: """ Initialize the Fenwick tree with arr in O(N) @@ -73,14 +73,14 @@ def init(self, arr: List[int]): self.tree[j] += self.tree[i] @staticmethod - def next(index: int): + def next(index: int) -> int: return index + (index & (-index)) @staticmethod - def prev(index: int): + def prev(index: int) -> int: return index - (index & (-index)) - def add(self, index: int, value: int): + def add(self, index: int, value: int) -> None: """ Add a value to index in O(lg N) @@ -96,7 +96,7 @@ def add(self, index: int, value: int): self.tree[index] += value index = self.next(index) - def update(self, index: int, value: int): + def update(self, index: int, value: int) -> None: """ Set the value of index in O(lg N) @@ -107,9 +107,9 @@ def update(self, index: int, value: int): Returns: None """ - self.add(index, value - self.query(index, index + 1)) + self.add(index, value - self.get(index)) - def prefix(self, right: int): + def prefix(self, right: int) -> int: """ Prefix sum of all elements in [0, right) in O(lg N) @@ -125,7 +125,7 @@ def prefix(self, right: int): right = self.prev(right) return result - def query(self, left: int, right: int): + def query(self, left: int, right: int) -> int: """ Query the sum of all elements in [left, right) in O(lg N) @@ -138,6 +138,18 @@ def query(self, left: int, right: int): """ return self.prefix(right) - self.prefix(left) + def get(self, index: int) -> int: + """ + Get value at index in O(lg N) + + Parameters: + index (int): index to get the value + + Returns: + int: Value of element at index + """ + return self.query(index, index + 1) + if __name__ == "__main__": import doctest From 6423a1ba8ad2e681e9e6f073f74fa2355bbf5ac8 Mon Sep 17 00:00:00 2001 From: AmirMohammad Hosseini Nasab Date: Fri, 12 Aug 2022 11:19:42 +0430 Subject: [PATCH 07/14] Change tree in Fenwick Tree --- data_structures/binary_tree/fenwick_tree.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/data_structures/binary_tree/fenwick_tree.py b/data_structures/binary_tree/fenwick_tree.py index 3a4bfa84d60c..7de76999af34 100644 --- a/data_structures/binary_tree/fenwick_tree.py +++ b/data_structures/binary_tree/fenwick_tree.py @@ -30,7 +30,7 @@ class FenwickTree: 30 """ - def __init__(self, arr: List[int] = None, size: int = None): + def __init__(self, arr: List[int] = None, size: int = None) -> None: """ Constructor for the Fenwick tree @@ -41,7 +41,7 @@ def __init__(self, arr: List[int] = None, size: int = None): if arr is None and size is not None: self.size = size - self.tree = [0] * (size + 1) + self.tree = [0] * size elif arr is not None: self.init(arr) else: @@ -66,10 +66,10 @@ def init(self, arr: List[int]) -> None: True """ self.size = len(arr) - self.tree = [0] + arr - for i in range(1, self.size + 1): + self.tree = deepcopy(arr) + for i in range(1, self.size): j = self.next(i) - if j < self.size + 1: + if j < self.size: self.tree[j] += self.tree[i] @staticmethod @@ -91,8 +91,10 @@ def add(self, index: int, value: int) -> None: Returns: None """ - index += 1 # 1-indexed - while index < self.size + 1: + if index == 0: + self.tree[0] += value + return + while index < self.size: self.tree[index] += value index = self.next(index) @@ -119,7 +121,10 @@ def prefix(self, right: int) -> int: Returns: int: sum of all elements in [0, right) """ - result = 0 + if right == 0: + return 0 + result = self.tree[0] + right -= 1 # make right inclusive while right > 0: result += self.tree[right] right = self.prev(right) From 92bca3aa1a4ba8ca395a9594a375f506b2a4db57 Mon Sep 17 00:00:00 2001 From: AmirMohammad Hosseini Nasab Date: Fri, 12 Aug 2022 11:30:18 +0430 Subject: [PATCH 08/14] Add rank query to FenwickTree --- data_structures/binary_tree/fenwick_tree.py | 46 +++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/data_structures/binary_tree/fenwick_tree.py b/data_structures/binary_tree/fenwick_tree.py index 7de76999af34..061eacf1ef4c 100644 --- a/data_structures/binary_tree/fenwick_tree.py +++ b/data_structures/binary_tree/fenwick_tree.py @@ -1,3 +1,4 @@ +from copy import deepcopy from typing import List @@ -155,6 +156,51 @@ def get(self, index: int) -> int: """ return self.query(index, index + 1) + def rank_query(self, value: int) -> int: + """ + Find the largest index with prefix(i) <= value in O(lg N) + NOTE: Requires that all values are non-negative! + + Parameters: + value (int): value to find the largest index of + + Returns: + -1: if value is smaller than all elements in prefix sum + int: largest index with prefix(i) <= value + + >>> f = FenwickTree([1, 2, 0, 3, 0, 5]) + >>> f.rank_query(0) + -1 + >>> f.rank_query(2) + 0 + >>> f.rank_query(1) + 0 + >>> f.rank_query(3) + 2 + >>> f.rank_query(5) + 2 + >>> f.rank_query(6) + 4 + >>> f.rank_query(11) + 5 + """ + value -= self.tree[0] + if value < 0: + return -1 + + j = 1 # Largest power of 2 <= size + while j * 2 < self.size: + j *= 2 + + i = 0 + + while j > 0: + if i + j < self.size and self.tree[i + j] <= value: + value -= self.tree[i + j] + i += j + j //= 2 + return i + if __name__ == "__main__": import doctest From 6bd20fa63675db9e37284fd36fb0a18da3ee6a88 Mon Sep 17 00:00:00 2001 From: AmirMohammad Hosseini Nasab Date: Fri, 12 Aug 2022 11:41:30 +0430 Subject: [PATCH 09/14] Add get_array method to FenwickTree --- data_structures/binary_tree/fenwick_tree.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/data_structures/binary_tree/fenwick_tree.py b/data_structures/binary_tree/fenwick_tree.py index 061eacf1ef4c..849638c79799 100644 --- a/data_structures/binary_tree/fenwick_tree.py +++ b/data_structures/binary_tree/fenwick_tree.py @@ -73,6 +73,25 @@ def init(self, arr: List[int]) -> None: if j < self.size: self.tree[j] += self.tree[i] + def get_array(self) -> List[int]: + """ + Get the Normal Array of the Fenwick tree in O(N) + + Returns: + list: Normal Array of the Fenwick tree + + >>> a = [i for i in range(128)] + >>> f = FenwickTree(a) + >>> f.get_array() == a + True + """ + arr = deepcopy(self.tree) + for i in range(self.size - 1, 0, -1): + j = self.next(i) + if j < self.size: + arr[j] -= arr[i] + return arr + @staticmethod def next(index: int) -> int: return index + (index & (-index)) From fecde440f20076f9a8956f6e4dd927190e350be5 Mon Sep 17 00:00:00 2001 From: AmirMohammad Hosseini Nasab Date: Fri, 12 Aug 2022 11:44:24 +0430 Subject: [PATCH 10/14] Add some tests --- data_structures/binary_tree/fenwick_tree.py | 65 ++++++++++++++------- 1 file changed, 43 insertions(+), 22 deletions(-) diff --git a/data_structures/binary_tree/fenwick_tree.py b/data_structures/binary_tree/fenwick_tree.py index 849638c79799..3974ee9f9e5d 100644 --- a/data_structures/binary_tree/fenwick_tree.py +++ b/data_structures/binary_tree/fenwick_tree.py @@ -7,28 +7,6 @@ class FenwickTree: Fenwick Tree More info: https://en.wikipedia.org/wiki/Fenwick_tree - - >>> f = FenwickTree(size=10) - >>> f.query(0, 10) - 0 - >>> f.add(9, 10) - >>> f.prefix(10) - 10 - >>> f.add(9, -10) - >>> f.add(1, 20) - >>> f.query(0, 1) - 0 - >>> f.query(1, 10) - 20 - >>> f.query(0, 10) - 20 - >>> f.update(2, 10) - >>> f.query(0, 2) - 20 - >>> f.query(2, 3) - 10 - >>> f.query(0, 10) - 30 """ def __init__(self, arr: List[int] = None, size: int = None) -> None: @@ -110,6 +88,15 @@ def add(self, index: int, value: int) -> None: Returns: None + + >>> f = FenwickTree([1, 2, 3, 4, 5]) + >>> f.add(0, 1) + >>> f.add(1, 2) + >>> f.add(2, 3) + >>> f.add(3, 4) + >>> f.add(4, 5) + >>> f.get_array() + [2, 4, 6, 8, 10] """ if index == 0: self.tree[0] += value @@ -128,6 +115,15 @@ def update(self, index: int, value: int) -> None: Returns: None + + >>> f = FenwickTree([5, 4, 3, 2, 1]) + >>> f.update(0, 1) + >>> f.update(1, 2) + >>> f.update(2, 3) + >>> f.update(3, 4) + >>> f.update(4, 5) + >>> f.get_array() + [1, 2, 3, 4, 5] """ self.add(index, value - self.get(index)) @@ -140,6 +136,14 @@ def prefix(self, right: int) -> int: Returns: int: sum of all elements in [0, right) + + >>> a = [i for i in range(128)] + >>> f = FenwickTree(a) + >>> res = True + >>> for i in range(len(a)): + ... res = res and f.prefix(i) == sum(a[:i]) + >>> res + True """ if right == 0: return 0 @@ -160,6 +164,15 @@ def query(self, left: int, right: int) -> int: Returns: int: sum of all elements in [left, right) + + >>> a = [i for i in range(128)] + >>> f = FenwickTree(a) + >>> res = True + >>> for i in range(len(a)): + ... for j in range(i + 1, len(a)): + ... res = res and f.query(i, j) == sum(a[i:j]) + >>> res + True """ return self.prefix(right) - self.prefix(left) @@ -172,6 +185,14 @@ def get(self, index: int) -> int: Returns: int: Value of element at index + + >>> a = [i for i in range(128)] + >>> f = FenwickTree(a) + >>> res = True + >>> for i in range(len(a)): + ... res = res and f.get(i) == a[i] + >>> res + True """ return self.query(index, index + 1) From 46e9747655e05ddf5b5b300de0af599081ea105a Mon Sep 17 00:00:00 2001 From: AmirMohammad Hosseini Nasab <19665344+itsamirhn@users.noreply.github.com> Date: Sat, 13 Aug 2022 16:12:24 +0430 Subject: [PATCH 11/14] Update data_structures/binary_tree/fenwick_tree.py Co-authored-by: Christian Clauss --- data_structures/binary_tree/fenwick_tree.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data_structures/binary_tree/fenwick_tree.py b/data_structures/binary_tree/fenwick_tree.py index 3974ee9f9e5d..53212cd3a8d1 100644 --- a/data_structures/binary_tree/fenwick_tree.py +++ b/data_structures/binary_tree/fenwick_tree.py @@ -63,7 +63,7 @@ def get_array(self) -> List[int]: >>> f.get_array() == a True """ - arr = deepcopy(self.tree) + arr = self.tree[:] for i in range(self.size - 1, 0, -1): j = self.next(i) if j < self.size: From 769d5b44b71749bc7ea62becc55b2857df450574 Mon Sep 17 00:00:00 2001 From: AmirMohammad Hosseini Nasab <19665344+itsamirhn@users.noreply.github.com> Date: Sat, 13 Aug 2022 16:12:32 +0430 Subject: [PATCH 12/14] Update data_structures/binary_tree/fenwick_tree.py Co-authored-by: Christian Clauss --- data_structures/binary_tree/fenwick_tree.py | 1 - 1 file changed, 1 deletion(-) diff --git a/data_structures/binary_tree/fenwick_tree.py b/data_structures/binary_tree/fenwick_tree.py index 53212cd3a8d1..c79c087c354e 100644 --- a/data_structures/binary_tree/fenwick_tree.py +++ b/data_structures/binary_tree/fenwick_tree.py @@ -1,5 +1,4 @@ from copy import deepcopy -from typing import List class FenwickTree: From d493a580ca0762aa561562e704d4db233be497e3 Mon Sep 17 00:00:00 2001 From: AmirMohammad Hosseini Nasab <19665344+itsamirhn@users.noreply.github.com> Date: Sat, 13 Aug 2022 16:12:39 +0430 Subject: [PATCH 13/14] Update data_structures/binary_tree/fenwick_tree.py Co-authored-by: Christian Clauss --- data_structures/binary_tree/fenwick_tree.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data_structures/binary_tree/fenwick_tree.py b/data_structures/binary_tree/fenwick_tree.py index c79c087c354e..93700b704dc8 100644 --- a/data_structures/binary_tree/fenwick_tree.py +++ b/data_structures/binary_tree/fenwick_tree.py @@ -8,7 +8,7 @@ class FenwickTree: More info: https://en.wikipedia.org/wiki/Fenwick_tree """ - def __init__(self, arr: List[int] = None, size: int = None) -> None: + def __init__(self, arr: list[int] = None, size: int = None) -> None: """ Constructor for the Fenwick tree From 66c906ea6f4c5fa88c999b61afcf46e6e594683a Mon Sep 17 00:00:00 2001 From: AmirMohammad Hosseini Nasab Date: Sat, 13 Aug 2022 16:16:36 +0430 Subject: [PATCH 14/14] change `List` to `list` --- data_structures/binary_tree/fenwick_tree.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/data_structures/binary_tree/fenwick_tree.py b/data_structures/binary_tree/fenwick_tree.py index 93700b704dc8..96020d1427af 100644 --- a/data_structures/binary_tree/fenwick_tree.py +++ b/data_structures/binary_tree/fenwick_tree.py @@ -25,7 +25,7 @@ def __init__(self, arr: list[int] = None, size: int = None) -> None: else: raise ValueError("Either arr or size must be specified") - def init(self, arr: List[int]) -> None: + def init(self, arr: list[int]) -> None: """ Initialize the Fenwick tree with arr in O(N) @@ -50,7 +50,7 @@ def init(self, arr: List[int]) -> None: if j < self.size: self.tree[j] += self.tree[i] - def get_array(self) -> List[int]: + def get_array(self) -> list[int]: """ Get the Normal Array of the Fenwick tree in O(N)