Skip to content

Commit 1c37060

Browse files
committed
various spelling corrections in documentation & several variables naming conventions fix
1 parent 4961b7c commit 1c37060

26 files changed

+123
-130
lines changed

backtracking/n_queens.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def solve(board, row):
4242
"""
4343
It creates a state space tree and calls the safe function until it receives a
4444
False Boolean and terminates that branch and backtracks to the next
45-
poosible solution branch.
45+
possible solution branch.
4646
"""
4747
if row >= len(board):
4848
"""
@@ -56,7 +56,7 @@ def solve(board, row):
5656
return
5757
for i in range(len(board)):
5858
"""
59-
For every row it iterates through each column to check if it is feesible to place a
59+
For every row it iterates through each column to check if it is feasible to place a
6060
queen there.
6161
If all the combinations for that particular branch are successful the board is
6262
reinitialized for the next possible combination.

ciphers/onepad_cipher.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
class Onepad:
55
def encrypt(self, text):
6-
"""Function to encrypt text using psedo-random numbers"""
6+
"""Function to encrypt text using pseudo-random numbers"""
77
plain = [ord(i) for i in text]
88
key = []
99
cipher = []
@@ -15,7 +15,7 @@ def encrypt(self, text):
1515
return cipher, key
1616

1717
def decrypt(self, cipher, key):
18-
"""Function to decrypt text using psedo-random numbers."""
18+
"""Function to decrypt text using pseudo-random numbers."""
1919
plain = []
2020
for i in range(len(key)):
2121
p = int((cipher[i] - (key[i]) ** 2) / key[i])

data_structures/binary_tree/binary_search_tree.py

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,16 @@ def __str__(self):
2828
"""
2929
return str(self.root)
3030

31-
def __reassign_nodes(self, node, newChildren):
32-
if newChildren is not None: # reset its kids
33-
newChildren.parent = node.parent
31+
def __reassign_nodes(self, node, new_children):
32+
if new_children is not None: # reset its kids
33+
new_children.parent = node.parent
3434
if node.parent is not None: # reset its parent
3535
if self.is_right(node): # If it is the right children
36-
node.parent.right = newChildren
36+
node.parent.right = new_children
3737
else:
38-
node.parent.left = newChildren
38+
node.parent.left = new_children
3939
else:
40-
self.root = newChildren
40+
self.root = new_children
4141

4242
def is_right(self, node):
4343
return node == node.parent.right
@@ -117,39 +117,39 @@ def remove(self, value):
117117
elif node.right is None: # Has only left children
118118
self.__reassign_nodes(node, node.left)
119119
else:
120-
tmpNode = self.get_max(
120+
tmp_node = self.get_max(
121121
node.left
122-
) # Gets the max value of the left branch
123-
self.remove(tmpNode.value)
122+
) # Gets the max value of the left branch
123+
self.remove(tmp_node.value)
124124
node.value = (
125-
tmpNode.value
126-
) # Assigns the value to the node to delete and keesp tree structure
125+
tmp_node.value
126+
) # Assigns the value to the node to delete and keep tree structure
127127

128128
def preorder_traverse(self, node):
129129
if node is not None:
130-
yield node # Preorder Traversal
130+
yield node # Preorder Traversal
131131
yield from self.preorder_traverse(node.left)
132132
yield from self.preorder_traverse(node.right)
133133

134-
def traversal_tree(self, traversalFunction=None):
134+
def traversal_tree(self, traversal_function=None):
135135
"""
136136
This function traversal the tree.
137137
You can pass a function to traversal the tree as needed by client code
138138
"""
139-
if traversalFunction is None:
139+
if traversal_function is None:
140140
return self.preorder_traverse(self.root)
141141
else:
142-
return traversalFunction(self.root)
142+
return traversal_function(self.root)
143143

144144

145145
def postorder(curr_node):
146146
"""
147147
postOrder (left, right, self)
148148
"""
149-
nodeList = list()
149+
node_list = list()
150150
if curr_node is not None:
151-
nodeList = postorder(curr_node.left) + postorder(curr_node.right) + [curr_node]
152-
return nodeList
151+
node_list = postorder(curr_node.left) + postorder(curr_node.right) + [curr_node]
152+
return node_list
153153

154154

155155
def binary_search_tree():

data_structures/binary_tree/number_of_possible_binary_trees.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def binary_tree_count(node_count: int) -> int:
8282
"""
8383
Return the number of possible of binary trees.
8484
:param n: number of nodes
85-
:return: Number of possilble binary trees
85+
:return: Number of possible binary trees
8686
8787
>>> binary_tree_count(5)
8888
5040

divide_and_conquer/convex_hull.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -344,19 +344,19 @@ def convex_hull_recursive(points):
344344
right_most_point = points[n - 1]
345345

346346
convex_set = {left_most_point, right_most_point}
347-
upperhull = []
348-
lowerhull = []
347+
upper_hull = []
348+
lower_hull = []
349349

350350
for i in range(1, n - 1):
351351
det = _det(left_most_point, right_most_point, points[i])
352352

353353
if det > 0:
354-
upperhull.append(points[i])
354+
upper_hull.append(points[i])
355355
elif det < 0:
356-
lowerhull.append(points[i])
356+
lower_hull.append(points[i])
357357

358-
_construct_hull(upperhull, left_most_point, right_most_point, convex_set)
359-
_construct_hull(lowerhull, right_most_point, left_most_point, convex_set)
358+
_construct_hull(upper_hull, left_most_point, right_most_point, convex_set)
359+
_construct_hull(lower_hull, right_most_point, left_most_point, convex_set)
360360

361361
return sorted(convex_set)
362362

dynamic_programming/bitmask.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,41 +25,41 @@ def __init__(self, task_performed, total):
2525

2626
self.task = defaultdict(list) # stores the list of persons for each task
2727

28-
# finalmask is used to check if all persons are included by setting all bits to 1
29-
self.finalmask = (1 << len(task_performed)) - 1
28+
# final_mask is used to check if all persons are included by setting all bits to 1
29+
self.final_mask = (1 << len(task_performed)) - 1
3030

31-
def CountWaysUtil(self, mask, taskno):
31+
def CountWaysUtil(self, mask, task_no):
3232

3333
# if mask == self.finalmask all persons are distributed tasks, return 1
34-
if mask == self.finalmask:
34+
if mask == self.final_mask:
3535
return 1
3636

3737
# if not everyone gets the task and no more tasks are available, return 0
38-
if taskno > self.total_tasks:
38+
if task_no > self.total_tasks:
3939
return 0
4040

4141
# if case already considered
42-
if self.dp[mask][taskno] != -1:
43-
return self.dp[mask][taskno]
42+
if self.dp[mask][task_no] != -1:
43+
return self.dp[mask][task_no]
4444

4545
# Number of ways when we don't this task in the arrangement
46-
total_ways_util = self.CountWaysUtil(mask, taskno + 1)
46+
total_ways_util = self.CountWaysUtil(mask, task_no + 1)
4747

4848
# now assign the tasks one by one to all possible persons and recursively assign for the remaining tasks.
49-
if taskno in self.task:
50-
for p in self.task[taskno]:
49+
if task_no in self.task:
50+
for p in self.task[task_no]:
5151

5252
# if p is already given a task
5353
if mask & (1 << p):
5454
continue
5555

5656
# assign this task to p and change the mask value. And recursively assign tasks with the new mask value.
57-
total_ways_util += self.CountWaysUtil(mask | (1 << p), taskno + 1)
57+
total_ways_util += self.CountWaysUtil(mask | (1 << p), task_no + 1)
5858

5959
# save the value.
60-
self.dp[mask][taskno] = total_ways_util
60+
self.dp[mask][task_no] = total_ways_util
6161

62-
return self.dp[mask][taskno]
62+
return self.dp[mask][task_no]
6363

6464
def countNoOfWays(self, task_performed):
6565

graphs/bellman_ford.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ def printDist(dist, V):
88

99

1010
def BellmanFord(graph: List[Dict[str, int]], V: int, E: int, src: int) -> int:
11-
r"""
11+
"""
1212
Returns shortest paths from a vertex src to all
1313
other vertices.
1414
"""

graphs/directed_and_undirected_(weighted)_graph.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import math as math
44
import time
55

6-
# the dfault weight is 1 if not assigned but all the implementation is weighted
6+
# the default weight is 1 if not assigned but all the implementation is weighted
77

88

99
class DirectedGraph:

graphs/minimum_spanning_tree_prims.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@ def PrimsAlgorithm(l):
66

77
nodePosition = []
88

9-
def getPosition(vertex):
9+
def get_position(vertex):
1010
return nodePosition[vertex]
1111

12-
def setPosition(vertex, pos):
12+
def set_position(vertex, pos):
1313
nodePosition[vertex] = pos
1414

15-
def topToBottom(heap, start, size, positions):
15+
def top_to_bottom(heap, start, size, positions):
1616
if start > size // 2 - 1:
1717
return
1818
else:
@@ -28,14 +28,14 @@ def topToBottom(heap, start, size, positions):
2828
heap[m], positions[m] = heap[start], positions[start]
2929
heap[start], positions[start] = temp, temp1
3030

31-
temp = getPosition(positions[m])
32-
setPosition(positions[m], getPosition(positions[start]))
33-
setPosition(positions[start], temp)
31+
temp = get_position(positions[m])
32+
set_position(positions[m], get_position(positions[start]))
33+
set_position(positions[start], temp)
3434

35-
topToBottom(heap, m, size, positions)
35+
top_to_bottom(heap, m, size, positions)
3636

3737
# Update function if value of any node in min-heap decreases
38-
def bottomToTop(val, index, heap, position):
38+
def bottom_to_top(val, index, heap, position):
3939
temp = position[index]
4040

4141
while index != 0:
@@ -47,27 +47,27 @@ def bottomToTop(val, index, heap, position):
4747
if val < heap[parent]:
4848
heap[index] = heap[parent]
4949
position[index] = position[parent]
50-
setPosition(position[parent], index)
50+
set_position(position[parent], index)
5151
else:
5252
heap[index] = val
5353
position[index] = temp
54-
setPosition(temp, index)
54+
set_position(temp, index)
5555
break
5656
index = parent
5757
else:
5858
heap[0] = val
5959
position[0] = temp
60-
setPosition(temp, 0)
60+
set_position(temp, 0)
6161

6262
def heapify(heap, positions):
6363
start = len(heap) // 2 - 1
6464
for i in range(start, -1, -1):
65-
topToBottom(heap, i, len(heap), positions)
65+
top_to_bottom(heap, i, len(heap), positions)
6666

6767
def deleteMinimum(heap, positions):
6868
temp = positions[0]
6969
heap[0] = sys.maxsize
70-
topToBottom(heap, 0, len(heap), positions)
70+
top_to_bottom(heap, 0, len(heap), positions)
7171
return temp
7272

7373
visited = [0 for i in range(len(l))]
@@ -96,9 +96,9 @@ def deleteMinimum(heap, positions):
9696
TreeEdges.append((Nbr_TV[vertex], vertex))
9797
visited[vertex] = 1
9898
for v in l[vertex]:
99-
if visited[v[0]] == 0 and v[1] < Distance_TV[getPosition(v[0])]:
100-
Distance_TV[getPosition(v[0])] = v[1]
101-
bottomToTop(v[1], getPosition(v[0]), Distance_TV, Positions)
99+
if visited[v[0]] == 0 and v[1] < Distance_TV[get_position(v[0])]:
100+
Distance_TV[get_position(v[0])] = v[1]
101+
bottom_to_top(v[1], get_position(v[0]), Distance_TV, Positions)
102102
Nbr_TV[v[0]] = vertex
103103
return TreeEdges
104104

0 commit comments

Comments
 (0)