Skip to content

Commit 91657f9

Browse files
committed
white spaces removal
1 parent 9a9cca1 commit 91657f9

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

pydatastructs/trees/fenwich_tree.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def __init__(self, size_or_array):
1818
if isinstance(size_or_array, int):
1919
self.size = size_or_array
2020
self.tree = [0] * (self.size + 1)
21-
self.original_array = [0] * self.size
21+
self.original_array = [0] * self.size
2222
elif isinstance(size_or_array, list):
2323
self.original_array = list(size_or_array)
2424
self.size = len(self.original_array)
@@ -27,7 +27,7 @@ def __init__(self, size_or_array):
2727
self._update_tree(i, val)
2828
else:
2929
raise ValueError("size_or_array must be an integer or a list.")
30-
30+
3131
def _update_tree(self, index, delta):
3232
"""
3333
Internal helper to update the Fenwick Tree after a change in the original array.
@@ -67,9 +67,9 @@ def prefix_sum(self, index):
6767
sum_val = 0
6868
while index > 0:
6969
sum_val += self.tree[index]
70-
index -= index & (-index)
70+
index -= index & (-index)
7171
return sum_val
72-
72+
7373
def range_sum(self, start_index, end_index):
7474
"""
7575
Calculates the sum of elements within the given range (inclusive).
@@ -83,7 +83,7 @@ def range_sum(self, start_index, end_index):
8383
"""
8484
if not (0 <= start_index <= end_index < self.size):
8585
raise IndexError("Indices out of bounds")
86-
if start_index is 0:
86+
if start_index == 0:
8787
return self.prefix_sum(end_index)
8888
else:
8989
return self.prefix_sum(end_index) - self.prefix_sum(start_index - 1)

pydatastructs/trees/trie.py

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,47 +2,47 @@ class TrieNode:
22
"""Represents a node in the Trie data structure."""
33
def __init__(self):
44
"""Initializes a TrieNode with empty children and is_end_of_word set to False."""
5-
self.children = {}
6-
self.is_end_of_word = False
7-
self.word = None
5+
self.children = {}
6+
self.is_end_of_word = False
7+
self.word = None
88

99
class Trie:
1010
"""Represents the Trie (prefix tree) data structure."""
1111
def __init__(self):
1212
"""Initializes an empty Trie with a root TrieNode."""
13-
self.root = TrieNode()
13+
self.root = TrieNode()
1414
self.word_count = 0
1515

1616
def insert(self, word):
1717
"""Inserts a word into the Trie."""
18-
node = self.root
18+
node = self.root
1919
for char in word:
2020
if char not in node.children:
2121
node.children[char] = TrieNode()
22-
node = node.children[char]
22+
node = node.children[char]
2323
if not node.is_end_of_word:
24-
node.is_end_of_word = True
24+
node.is_end_of_word = True
2525
node.word = word
2626
self.word_count += 1
2727

2828
def search(self, word):
2929
"""Searches for a word in the Trie."""
30-
node = self.root
30+
node = self.root
3131
for char in word:
3232
if char not in node.children:
3333
return False
34-
node = node.children[char]
35-
return node.is_end_of_word
34+
node = node.children[char]
35+
return node.is_end_of_word
3636

3737
def starts_with(self, prefix):
3838
"""Checks if any word in the Trie starts with the given prefix."""
39-
node = self.root
39+
node = self.root
4040
for char in prefix:
4141
if char not in node.children:
4242
return False
43-
node = node.children[char]
44-
return True
45-
43+
node = node.children[char]
44+
return True
45+
4646
def count_words(self):
4747
"""Returns the total number of words stored in the Trie."""
4848
return self.word_count

0 commit comments

Comments
 (0)