Skip to content

Refactor #234

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions ciphers/playfair_cipher.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def chunker(seq, size):

def prepare_input(dirty):
"""
Prepare the plaintext by uppcasing it
and seperating repeated letters with X's
Prepare the plaintext by up-casing it
and separating repeated letters with X's
"""

dirty = ''.join([c.upper() for c in dirty if c in string.ascii_letters])
Expand All @@ -38,7 +38,7 @@ def prepare_input(dirty):

def generate_table(key):

# I and J are used interchangably to allow
# I and J are used interchangeably to allow
# us to use a 5x5 table (25 letters)
alphabet = "ABCDEFGHIKLMNOPQRSTUVWXYZ"
# we're using a list instead of a '2d' array because it makes the math
Expand Down
14 changes: 7 additions & 7 deletions data_structures/AVL/AVL.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'''
A AVL tree
'''
"""
An AVL tree
"""
from __future__ import print_function


Expand Down Expand Up @@ -101,10 +101,10 @@ def rebalance(self, node):
if height_left > height_right:
left_child = n.left
if left_child is not None:
h_right = (right_child.right.height
if (right_child.right is not None) else 0)
h_left = (right_child.left.height
if (right_child.left is not None) else 0)
h_right = (left_child.right.height
if (left_child.right is not None) else 0)
h_left = (left_child.left.height
if (left_child.left is not None) else 0)
if (h_left > h_right):
self.rotate_left(n)
break
Expand Down
2 changes: 1 addition & 1 deletion data_structures/Arrays
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Arrays implimentation using python programming.
Arrays implementation using python programming.
10 changes: 5 additions & 5 deletions data_structures/Graph/BellmanFord.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ def printDist(dist, V):
print(i,"\t",int(dist[i]),end = "\t")
else:
print(i,"\t","INF",end="\t")
print();
print()

def BellmanFord(graph, V, E, src):
mdist=[float('inf') for i in range(V)]
mdist[src] = 0.0;
mdist[src] = 0.0

for i in range(V-1):
for j in range(V):
Expand All @@ -35,13 +35,13 @@ def BellmanFord(graph, V, E, src):


#MAIN
V = int(input("Enter number of vertices: "));
E = int(input("Enter number of edges: "));
V = int(input("Enter number of vertices: "))
E = int(input("Enter number of edges: "))

graph = [dict() for j in range(E)]

for i in range(V):
graph[i][i] = 0.0;
graph[i][i] = 0.0

for i in range(E):
print("\nEdge ",i+1)
Expand Down
12 changes: 6 additions & 6 deletions data_structures/Graph/Dijkstra.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def printDist(dist, V):
print(i,"\t",int(dist[i]),end = "\t")
else:
print(i,"\t","INF",end="\t")
print();
print()

def minDist(mdist, vset, V):
minVal = float('inf')
Expand All @@ -25,7 +25,7 @@ def Dijkstra(graph, V, src):

for i in range(V-1):
u = minDist(mdist, vset, V)
vset[u] = True;
vset[u] = True

for v in range(V):
if (not vset[v]) and graph[u][v]!=float('inf') and mdist[u] + graph[u][v] < mdist[v]:
Expand All @@ -38,20 +38,20 @@ def Dijkstra(graph, V, src):


#MAIN
V = int(input("Enter number of vertices: "));
E = int(input("Enter number of edges: "));
V = int(input("Enter number of vertices: "))
E = int(input("Enter number of edges: "))

graph = [[float('inf') for i in range(V)] for j in range(V)]

for i in range(V):
graph[i][i] = 0.0;
graph[i][i] = 0.0

for i in range(E):
print("\nEdge ",i+1)
src = int(input("Enter source:"))
dst = int(input("Enter destination:"))
weight = float(input("Enter weight:"))
graph[src][dst] = weight;
graph[src][dst] = weight

gsrc = int(input("\nEnter shortest path source:"))
Dijkstra(graph, V, gsrc)
2 changes: 1 addition & 1 deletion dynamic_programming/FloydWarshall.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def __init__(self, N = 0): # a graph with Node 0,1,...,N-1
self.dp = [[math.inf for j in range(0,N)] for i in range(0,N)] # dp[i][j] stores minimum distance from i to j

def addEdge(self, u, v, w):
self.dp[u][v] = w;
self.dp[u][v] = w

def floyd_warshall(self):
for k in range(0,self.N):
Expand Down