From 4fb978cf58f79f65cfd43b84ba52c457f8d710a2 Mon Sep 17 00:00:00 2001 From: ashu01 Date: Sun, 31 Dec 2017 14:30:31 +0530 Subject: [PATCH 1/3] 1. typo fix {playfair_cipher.py, AVL.py} 2. Corrected Logic {AVL.py, 104-107} 3. Removed unnecessary semicolons {BellmanFord.py, Dijkstra.py} --- ciphers/playfair_cipher.py | 6 +++--- data_structures/AVL/AVL.py | 14 +++++++------- data_structures/Graph/BellmanFord.py | 10 +++++----- data_structures/Graph/Dijkstra.py | 12 ++++++------ 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/ciphers/playfair_cipher.py b/ciphers/playfair_cipher.py index 8ef09160d..20449b161 100644 --- a/ciphers/playfair_cipher.py +++ b/ciphers/playfair_cipher.py @@ -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]) @@ -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 diff --git a/data_structures/AVL/AVL.py b/data_structures/AVL/AVL.py index 84f79fd1c..d01e8f825 100644 --- a/data_structures/AVL/AVL.py +++ b/data_structures/AVL/AVL.py @@ -1,6 +1,6 @@ -''' -A AVL tree -''' +""" +An AVL tree +""" from __future__ import print_function @@ -101,10 +101,10 @@ class AVL: 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 diff --git a/data_structures/Graph/BellmanFord.py b/data_structures/Graph/BellmanFord.py index b9207c422..82db80546 100644 --- a/data_structures/Graph/BellmanFord.py +++ b/data_structures/Graph/BellmanFord.py @@ -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): @@ -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) diff --git a/data_structures/Graph/Dijkstra.py b/data_structures/Graph/Dijkstra.py index ae6a1a283..891717141 100644 --- a/data_structures/Graph/Dijkstra.py +++ b/data_structures/Graph/Dijkstra.py @@ -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') @@ -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]: @@ -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) From 06c7827a9428c5ce14be4f630e5b8082d073f9a0 Mon Sep 17 00:00:00 2001 From: ashu01 Date: Sun, 31 Dec 2017 14:33:14 +0530 Subject: [PATCH 2/3] 1. typo fix {Arrays| --- data_structures/Arrays | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data_structures/Arrays b/data_structures/Arrays index 03eaefac1..e2c1243f5 100644 --- a/data_structures/Arrays +++ b/data_structures/Arrays @@ -1 +1 @@ -Arrays implimentation using python programming. +Arrays implementation using python programming. From c9debdbd413170630bd0050c1a8e816fe8c5b143 Mon Sep 17 00:00:00 2001 From: ashu01 Date: Sun, 31 Dec 2017 14:36:29 +0530 Subject: [PATCH 3/3] 1. Removed ; --- dynamic_programming/FloydWarshall.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dynamic_programming/FloydWarshall.py b/dynamic_programming/FloydWarshall.py index bf7714124..038499ca0 100644 --- a/dynamic_programming/FloydWarshall.py +++ b/dynamic_programming/FloydWarshall.py @@ -8,7 +8,7 @@ class Graph: 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):