Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6c7d0b8

Browse files
author
Amogh Singhal
authored
Merge pull request devAmoghS#7 from rhthomas/flake-issues
Fixed flake errors from issue devAmoghS#4
2 parents cb713c1 + 5b7c47e commit 6c7d0b8

File tree

6 files changed

+40
-33
lines changed

6 files changed

+40
-33
lines changed

‎dfs_bfs.py‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Given a graph, there are two methods to
1+
# Given a graph, there are two methods to
22
# perform traversal on it.
33
# 1. Depth First Search (DFS)
44
# 2. Breadth First Search (BFS)
@@ -17,9 +17,9 @@ def dfs_2(graph, start, visited=None):
1717
visited = set()
1818
visited.add(start)
1919
for next in graph[start] - visited:
20-
dfs(graph, next, visited)
20+
dfs_2(graph, next, visited)
2121
return visited
22-
22+
2323
def bfs(graph, start):
2424
visited, queue = set(), [start]
2525
while queue:
@@ -30,7 +30,7 @@ def bfs(graph, start):
3030
return visited
3131

3232
# bfs(graph, 'A') # {'B', 'C', 'A', 'F', 'D', 'E'}
33-
33+
3434
def dfs_paths(graph, start, goal):
3535
stack = [(start, [start])]
3636
while stack:
@@ -47,6 +47,6 @@ def dfs_paths(graph, start, goal):
4747
'D': set(['B']),
4848
'E': set(['B', 'F']),
4949
'F': set(['C', 'E'])}
50-
50+
5151
result = list(dfs_paths(graph, 'A', 'F')) # [['A', 'C', 'F'], ['A', 'B', 'E', 'F']]
5252
print(result)

‎find_m_to_last_llist.py‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,23 @@
33
# 2->3->4->8->5; m=2 will return 8
44
# since 8 is second to last
55

6+
from linked_list_data_structure import LinkedList
7+
68
def findMToLast(l_list, m):
79
current = l_list.head
810
count = 0
9-
11+
1012
while current is not None and count < m:
1113
count+=1
1214
current = current.getNextNode()
13-
15+
1416
m_behind = l_list.head
1517
while current.next_node is not None:
1618
current = current.getNextNode()
1719
m_behind = m_behind.getNextNode()
18-
20+
1921
return m_behind
20-
22+
2123
linked_list = LinkedList()
2224
m_to_last = 3
2325
# Returns the third element from last

‎heap_structure.py‎

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
class Heap(object):
2-
2+
33
HEAP_SIZE = 10;
4-
4+
55
def __init__(self):
66
self.heap = [0]*Heap.HEAP_SIZE
77
self.currentPosition = -1
8-
8+
99
def insert(self, item):
10-
10+
1111
# if heap is full , we print a notification
1212
if self.isFull():
1313
print("Heap is full")
@@ -16,7 +16,7 @@ def insert(self, item):
1616
self.currentPosition+=1
1717
self.heap[self.currentPosition] = item
1818
self.fixUp(self.currentPosition)
19-
19+
2020
def fixUp(self, index):
2121
parentIndex = int((index-1)/2)
2222
while parentIndex >=0 and self.heap[parentIndex] < self.heap[index]:
@@ -27,54 +27,54 @@ def fixUp(self, index):
2727
# update the index and parentIndex
2828
index = parentIndex
2929
parentIndex = int((index-1)/2)
30-
30+
3131
def fixDown(self, index, upto):
3232
if upto < 0:
3333
upto = self.currentPosition
34-
34+
3535
while index<=upto:
3636
leftChild = 2*index+1
3737
rightChild = 2*index+2
38-
38+
3939
if leftChild <= upto:
4040
childToSwap = 0
4141
else:
4242
if self.heap[leftChild] < self.heap[rightChild]:
4343
childToSwap = leftChild
4444
else:
4545
childToSwap = rightChild
46-
46+
4747
if self.heap[index] < self.heap[childToSwap]:
4848
temp = self.heap[index]
4949
self.heap[index] = self.heap[childToSwap]
5050
self.heap[childToSwap] = temp
5151
else:
5252
break
53-
53+
5454
index = childToSwap
55-
55+
5656
else:
5757
return
58-
58+
5959
def heapSort(self):
6060
for i in range(0, self.currentPosition+1):
6161
temp = self.heap[0]
6262
print("%d"%temp)
6363
self.heap[0] = self.heap[self.currentPosition-i]
6464
self.heap[self.currentPosition-i] = temp
6565
self.fixDown(0, self.currentPosition-i-1)
66-
67-
def getMax():
66+
67+
def getMax(self):
6868
result = self.heap[0]
6969
self.currentPosition-=1
7070
self.heap[0] = self.heap[self.currentPosition]
7171
del self.heap[self.currentPosition]
7272
self.fixDown(0, -1)
7373
return result
74-
74+
7575
def isFull(self):
7676
return self.currentPosition == Heap.HEAP_SIZE
77-
77+
7878
some_heap=Heap()
7979
some_heap.insert(12)
8080
some_heap.insert(-3)

‎loop_in_linkedlist.py‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
from linked_list_data_structure import LinkedList
2+
from find_m_to_last_llist import findMToLast
3+
14
def hasLoop(l_list):
25
fast = l_list.head.next_node
36
slow = l_list.head
@@ -11,9 +14,9 @@ def hasLoop(l_list):
1114
else:
1215
fast = fast.next_node
1316
slow = slow.next_node
14-
17+
1518
return hasLoop
16-
19+
1720
linked_list = LinkedList()
1821
# Returns the third element from last
1922
print(findMToLast(linked_list))

‎preorder_iterative_bst.py‎

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@ def preOrderTraversal(root):
44
while len(stack) > 0:
55
current = stack.pop()
66
print(current.value)
7-
7+
88
right = current.right
9-
stack.insert(0, right) if right is not None
10-
9+
if right is not None:
10+
stack.insert(0, right)
11+
1112
left = current.left
12-
stack.insert(0, left) if left is not None
13+
if left is not None:
14+
stack.insert(0, left)

‎remove_duplicates_v2.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ def remove_duplicates_v2(arr):
44
for i in arr:
55
if i not in dedupe_arr:
66
dedupe_arr.append(i)
7-
7+
88
return dedupe_arr
99

10-
result = remove_duplicates([0,0,0,1,1,2,2,3,4,5])
10+
result = remove_duplicates_v2([0,0,0,1,1,2,2,3,4,5])
1111
print(result)

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /