Skip to content

Commit 564748b

Browse files
committedApr 14, 2018
Minor changes and fixes
1 parent 1dc2a0e commit 564748b

18 files changed

+30
-30
lines changed
 

‎Bit_Manipulation/Next_Number.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def next_greater(num):
1717
right_pattern = (num ^ left_pattern) >> (right_one + 1)
1818

1919
# OR both the patterns
20-
# Ex. res = 0 bin = 1001
20+
# Ex. res = 9 bin = 1001
2121
res = left_pattern | right_pattern
2222

2323
return res

‎DynamicProgramming/TheMaximumSubarray.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#HackerRank problem Algorithms DP
1+
# HackerRank problem Algorithms DP
22

33

44
def maxSubArray(a, size):

‎Graph/Boggle.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ def findWords(words, boggle):
5555

5656
if __name__ == '__main__':
5757
words = {"GEEKS", "FOR", "QUIZ", "GO", "SEEK"}
58-
boggle = [['G','I','Z'],
59-
['U','E','K'],
60-
['Q','S','E']]
58+
boggle = [['G', 'I', 'Z'],
59+
['U', 'E', 'K'],
60+
['Q', 'S', 'E']]
6161

6262
found = findWords(words, boggle)
6363

6464
print("Words found in the boggle from the dictionary are:")
6565
for word in found:
66-
print(word)
66+
print(word)

‎Graph/DijkstraShortestPath.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def find_min(self, dist, visited):
2525

2626
return index
2727

28-
def dikstra(self, src):
28+
def dijkstra(self, src):
2929
visited = {i: False for i in self.graph}
3030
dist = {i: float('inf') for i in self.graph}
3131
parent = {i: None for i in self.graph}
@@ -54,7 +54,7 @@ def printPath(self, parent, v):
5454
if parent[v] is None:
5555
return
5656
self.printPath(parent, parent[v])
57-
print(v,end=' ')
57+
print(v, end=' ')
5858

5959
def printSolution(self, dist, parent, src):
6060
print('{}\t{}\t{}'.format('Vertex', 'Distance', 'Path'))
@@ -63,7 +63,7 @@ def printSolution(self, dist, parent, src):
6363
if i == src:
6464
continue
6565
print('{} -> {}\t\t{}\t\t{}'.format(src, i, dist[i], src), end=' ')
66-
self.printPath(parent,i)
66+
self.printPath(parent, i)
6767
print()
6868

6969
if __name__ == '__main__':
@@ -85,7 +85,7 @@ def printSolution(self, dist, parent, src):
8585
graph.addEdge(3, 5, 14)
8686
graph.addEdge(5, 4, 10)
8787

88-
parent, dist = graph.dikstra(0)
88+
parent, dist = graph.dijkstra(0)
8989

9090
graph.printSolution(dist, parent, 0)
9191

‎Graph/Graph.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def addVertex(self, key):
4040
node = Vertex(key)
4141
self.vertices[key] = node
4242
self.numberOfVertices += 1
43-
return node
43+
return node
4444

4545
def addEdge(self, frm, to, weight=0):
4646
if frm not in self.vertices:

‎Graph/KruskalMST.py

-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
# Kruskal’s Minimum Spanning Tree Algorithm
2-
from collections import defaultdict
32

43

54
class Graph:
@@ -73,10 +72,6 @@ def kruskalMST(self):
7372
return g
7473

7574

76-
77-
78-
79-
8075
if __name__ == '__main__':
8176
# make an undirected graph
8277
graph = Graph()
@@ -91,4 +86,3 @@ def kruskalMST(self):
9186

9287
for f, t, w in new_graph.edges:
9388
print(f, "--", t, "=", w)
94-

‎Graph/TopologicalSort.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def topoSortUtil(self, s, visited, sortList):
2525

2626
sortList.insert(0, s)
2727

28-
def topologicalSort(self, s=None):
28+
def topologicalSort(self):
2929
visited = {i: False for i in self.graph}
3030

3131
sortList = []

‎Heaps/RunningMedian.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def min(self):
227227
"""
228228
Algorithm:
229229
*) Split the array stream in 2 halves, min heap(upper array) and max heap (lower array)
230-
*) This was the min and max of the heaps will help you get the median fast.
230+
*) This way the min and max of the heaps will help you get the median fast.
231231
*) Note that the elements should be inserted in the heaps in such a way that the elements
232232
in lowerMaxHeap are all smaller than all the elements in the upperMinHeap
233233
(i.e., as if the arrays were sorted and then split into two heaps)

‎Mathematics/Prime_factors.py

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from math import sqrt
66

7+
78
def prime_factors(num):
89
# list to store the prime factors
910
prime_factor_lis = []

‎Mathematics/Sieve_of_Eratosthenes.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@ def find_primes_sieve(num):
2929

3030
if __name__ == '__main__':
3131
primes = find_primes_sieve(30)
32-
print(primes)
32+
print(primes)

‎Matrix/SearchRowColumnSorted.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Given an n x n matrix, where every row and column is sorted in increasing order.
22
Given a number x, how to decide whether this x is in the matrix."""
33

4+
45
def search(mat, x):
56
n = len(mat)
67
i = 0

‎Matrix/SpiralPrint.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ def print_spiral(mat):
3838
[13, 14, 15, 16, 17, 18]
3939
]
4040

41-
print_spiral(a)
41+
print_spiral(a)

‎String_or_Array/K_Unique_Substring.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def longest_k_unique(string, k):
1111
unique += 1
1212

1313
if unique < k:
14-
return -1
14+
return -1, -1
1515

1616
count = [0] * 26
1717
curr_end = curr_start = max_window_start = 0
@@ -43,8 +43,12 @@ def isValid(count, k):
4343

4444

4545
if __name__ == '__main__':
46-
string = 'aabacbebebe'
46+
string = 'aabaabab'
4747
k = 3
4848
max_start, max_len = longest_k_unique(string, k)
49-
print('max string with {} unique characters is "'.format(k) + string[max_start: max_start + max_len] +
50-
'" of length', max_len)
49+
50+
if max_len == -1:
51+
print("K unique characters sub string does not exist.")
52+
else:
53+
print('max string with {} unique characters is "'.format(k) + string[max_start: max_start + max_len] +
54+
'" of length', max_len)

‎String_or_Array/PairSum_is_X.py

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def find_pair_unsorted(arr, x):
3636
Space Complexity: O(1)
3737
"""
3838

39+
3940
def find_pair_sorted(arr, x):
4041
# initialize variables to the start and end of the array
4142
l = 0

‎String_or_Array/Sorting/K_Messed_Sort.py

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44
import heapq
55

6+
67
def kHeapSort(arr, k):
78
h = []
89
n = len(arr)

‎Tree/BinaryTree/Lowest_Common_Ancestor.py

-2
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,3 @@ def findLCA(root, n1, n2):
9797
print("LCA(4,10) = ", lca.key)
9898
else:
9999
print("Keys are not present")
100-
101-
# This code is contributed by Nikhil Kumar Singh(nickzuck_007)

‎Tree/BinaryTree/Max_Path_Sum.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ def max_sum_path_util(root):
2222
right_sum = max_sum_path_util(root.right)
2323

2424
# if current node is one of the nodes in the path above for max
25-
# it can either be along, or with left sub tree or right sub tree
25+
# it can either be alone, or with left sub tree or right sub tree
2626
max_single = max(max(left_sum, right_sum) + root.data, root.data)
2727

2828
# if the current root itself is considered as top node of the max path

‎Tree/BinaryTree/Minimum_height.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ def get_min_depth(root):
2626
else:
2727
if node.left is not None:
2828
queue.append((node.left, height + 1))
29-
if node.right is not None:
30-
queue.append((node.right, height + 1))
29+
if node.right is not None:
30+
queue.append((node.right, height + 1))
3131

3232

3333
if __name__ == '__main__':

0 commit comments

Comments
 (0)
Please sign in to comment.