Merge branch 'master' into improved_sorting_algo

This commit is contained in:
Yasir Choudhary 2018-10-19 12:05:26 +05:30 committed by GitHub
commit 9561259285
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
33 changed files with 576 additions and 118 deletions

1
.gitignore vendored
View File

@ -7,6 +7,7 @@ __pycache__/
*.so
# Distribution / packaging
.vscode/
.Python
env/
build/

View File

@ -1,3 +0,0 @@
{
"python.pythonPath": "/usr/bin/python3"
}

View File

@ -1,7 +1,7 @@
import math
import numpy
def LUDecompose (table): #table that contains our data
def LUDecompose (table):
#table that contains our data
#table has to be a square array so we need to check first
rows,columns=numpy.shape(table)
L=numpy.zeros((rows,columns))
@ -31,4 +31,4 @@ def LUDecompose (table): #table that contains our data
matrix =numpy.array([[2,-2,1],[0,1,2],[5,3,1]])
L,U = LUDecompose(matrix)
print(L)
print(U)
print(U)

View File

@ -1,18 +1,16 @@
# Implementing Newton Raphson method in python
# Implementing Newton Raphson method in Python
# Author: Haseeb
from sympy import diff
from decimal import Decimal
from math import sin, cos, exp
def NewtonRaphson(func, a):
''' Finds root from the point 'a' onwards by Newton-Raphson method '''
while True:
x = a
c = Decimal(a) - ( Decimal(eval(func)) / Decimal(eval(str(diff(func)))) )
x = c
a = c
# This number dictates the accuracy of the answer
if abs(eval(func)) < 10**-15:
return c
@ -20,8 +18,8 @@ def NewtonRaphson(func, a):
# Let's Execute
if __name__ == '__main__':
# Find root of trignometric fucntion
# Find value of pi
# Find root of trigonometric function
# Find value of pi
print ('sin(x) = 0', NewtonRaphson('sin(x)', 2))
# Find root of polynomial
@ -30,7 +28,7 @@ if __name__ == '__main__':
# Find Square Root of 5
print ('x**2 - 5 = 0', NewtonRaphson('x**2 - 5', 0.1))
# Exponential Roots
# Exponential Roots
print ('exp(x) - 1 = 0', NewtonRaphson('exp(x) - 1', 0))

View File

@ -1,8 +1,6 @@
from __future__ import print_function
import heapq
import numpy as np
import math
import copy
try:
xrange # Python 2

View File

@ -140,7 +140,7 @@ from collections import deque
def topo(G, ind=None, Q=[1]):
if ind == None:
if ind is None:
ind = [0] * (len(G) + 1) # SInce oth Index is ignored
for u in G:
for v in G[u]:

View File

@ -62,9 +62,13 @@ def eulerPhi(n):
s *= (x - 1)/x
return s
print(primeFactors(100))
print(numberOfDivisors(100))
print(sumOfDivisors(100))
print(eulerPhi(100))
def main():
print(primeFactors(100))
print(numberOfDivisors(100))
print(sumOfDivisors(100))
print(eulerPhi(100))
if __name__ == '__main__':
main()

View File

@ -0,0 +1,18 @@
# Fibonacci Sequence Using Recursion
def recur_fibo(n):
return n if n <= 1 else (recur_fibo(n-1) + recur_fibo(n-2))
def isPositiveInteger(limit):
return limit >= 0
def main():
limit = int(input("How many terms to include in fibonacci series: "))
if isPositiveInteger(limit):
print(f"The first {limit} terms of the fibonacci series are as follows:")
print([recur_fibo(n) for n in range(limit)])
else:
print("Please enter a positive integer: ")
if __name__ == '__main__':
main()

View File

@ -0,0 +1,15 @@
# Greater Common Divisor - https://en.wikipedia.org/wiki/Greatest_common_divisor
def gcd(a, b):
return b if a == 0 else gcd(b % a, a)
def main():
try:
nums = input("Enter two Integers separated by comma (,): ").split(',')
num1 = int(nums[0]); num2 = int(nums[1])
except (IndexError, UnboundLocalError, ValueError):
print("Wrong Input")
print(f"gcd({num1}, {num2}) = {gcd(num1, num2)}")
if __name__ == '__main__':
main()

View File

@ -1,16 +0,0 @@
# Fibonacci Sequence Using Recursion
def recur_fibo(n):
if n <= 1:
return n
else:
return(recur_fibo(n-1) + recur_fibo(n-2))
limit = int(input("How many terms to include in fionacci series:"))
if limit <= 0:
print("Plese enter a positive integer")
else:
print("Fibonacci series:")
for i in range(limit):
print(recur_fibo(i))

View File

@ -1,12 +0,0 @@
def gcd(a, b):
if a == 0 :
return b
return gcd(b%a, a)
def main():
print(gcd(3, 6))
if __name__ == '__main__':
main()

View File

@ -25,7 +25,7 @@ class Perceptron:
self.col_sample = len(sample[0])
self.weight = []
def trannig(self):
def training(self):
for sample in self.sample:
sample.insert(0, self.bias)
@ -121,4 +121,4 @@ while True:
sample = []
for i in range(3):
sample.insert(i, float(input('value: ')))
network.sort(sample)
network.sort(sample)

View File

@ -3,7 +3,6 @@ a^2+b^2=c^2
Given N, Check if there exists any Pythagorean triplet for which a+b+c=N
Find maximum possible value of product of a,b,c among all such Pythagorean triplets, If there is no such Pythagorean triplet print -1."""
#!/bin/python3
import sys
product=-1
d=0

View File

@ -1,5 +1,5 @@
from __future__ import print_function
from math import factorial, ceil
from math import factorial
def lattice_paths(n):
n = 2*n #middle entry of odd rows starting at row 3 is the solution for n = 1, 2, 3,...

103
README.md
View File

@ -13,9 +13,9 @@ These are for demonstration purposes only. There are many implementations of sor
From [Wikipedia][bubble-wiki]: Bubble sort, sometimes referred to as sinking sort, is a simple sorting algorithm that repeatedly steps through the list to be sorted, compares each pair of adjacent items and swaps them if they are in the wrong order. The pass through the list is repeated until no swaps are needed, which indicates that the list is sorted.
__Properties__
* Worst case performance O(n^2)
* Worst case performance O(n<sup>2</sup>)
* Best case performance O(n)
* Average case performance O(n^2)
* Average case performance O(n<sup>2</sup>)
###### View the algorithm in [action][bubble-toptal]
@ -26,19 +26,19 @@ __Properties__
From [Wikipedia][bucket-wiki]: Bucket sort, or bin sort, is a sorting algorithm that works by distributing the elements of an array into a number of buckets. Each bucket is then sorted individually, either using a different sorting algorithm, or by recursively applying the bucket sorting algorithm.
__Properties__
* Worst case performance O(n^2)
* Worst case performance O(n<sup>2</sup>)
* Best case performance O(n+k)
* Average case performance O(n+k)
### Coctail shaker
### Cocktail shaker
![alt text][cocktail-shaker-image]
From [Wikipedia][cocktail-shaker-wiki]: Cocktail shaker sort, also known as bidirectional bubble sort, cocktail sort, shaker sort (which can also refer to a variant of selection sort), ripple sort, shuffle sort, or shuttle sort, is a variation of bubble sort that is both a stable sorting algorithm and a comparison sort. The algorithm differs from a bubble sort in that it sorts in both directions on each pass through the list.
__Properties__
* Worst case performance O(n^2)
* Worst case performance O(n<sup>2</sup>)
* Best case performance O(n)
* Average case performance O(n^2)
* Average case performance O(n<sup>2</sup>)
### Insertion
@ -47,9 +47,9 @@ __Properties__
From [Wikipedia][insertion-wiki]: Insertion sort is a simple sorting algorithm that builds the final sorted array (or list) one item at a time. It is much less efficient on large lists than more advanced algorithms such as quicksort, heapsort, or merge sort.
__Properties__
* Worst case performance O(n^2)
* Worst case performance O(n<sup>2</sup>)
* Best case performance O(n)
* Average case performance O(n^2)
* Average case performance O(n<sup>2</sup>)
###### View the algorithm in [action][insertion-toptal]
@ -73,12 +73,26 @@ __Properties__
From [Wikipedia][quick-wiki]: Quicksort (sometimes called partition-exchange sort) is an efficient sorting algorithm, serving as a systematic method for placing the elements of an array in order.
__Properties__
* Worst case performance O(n^2)
* Worst case performance O(n<sup>2</sup>)
* Best case performance O(n log n) or O(n) with three-way partition
* Average case performance O(n log n)
###### View the algorithm in [action][quick-toptal]
### Heap
From [Wikipedia][heap-wiki]: Heapsort is a comparison-based sorting algorithm. It can be thought of as an improved selection sort. It divides its input into a sorted and an unsorted region, and it iteratively shrinks the unsorted region by extracting the largest element and moving that to the sorted region
__Properties__
* Worst case performance O(n log n)
* Best case performance O(n log n)
* Average case performance O(n log n)
###### View the algorithm in [action](https://www.toptal.com/developers/sorting-algorithms/heap-sort)
### Radix
From [Wikipedia][radix-wiki]: In computer science, radix sort is a non-comparative integer sorting algorithm that sorts data with integer keys by grouping keys by the individual digits which share the same significant position and value.
@ -94,9 +108,9 @@ __Properties__
From [Wikipedia][selection-wiki]: The algorithm divides the input list into two parts: the sublist of items already sorted, which is built up from left to right at the front (left) of the list, and the sublist of items remaining to be sorted that occupy the rest of the list. Initially, the sorted sublist is empty and the unsorted sublist is the entire input list. The algorithm proceeds by finding the smallest (or largest, depending on sorting order) element in the unsorted sublist, exchanging (swapping) it with the leftmost unsorted element (putting it in sorted order), and moving the sublist boundaries one element to the right.
__Properties__
* Worst case performance O(n^2)
* Best case performance O(n^2)
* Average case performance O(n^2)
* Worst case performance O(n<sup>2</sup>)
* Best case performance O(n<sup>2</sup>)
* Average case performance O(n<sup>2</sup>)
###### View the algorithm in [action][selection-toptal]
@ -151,8 +165,40 @@ __Properties__
* Worst case performance O(log n)
* Best case performance O(1)
* Average case performance O(log n)
* Worst case space complexity O(1)
* Worst case space complexity O(1)
## Interpolation
Interpolation search is an algorithm for searching for a key in an array that has been ordered by numerical values assigned to the keys (key values). It was first described by W. W. Peterson in 1957.[1] Interpolation search resembles the method by which people search a telephone directory for a name (the key value by which the book's entries are ordered): in each step the algorithm calculates where in the remaining search space the sought item might be, based on the key values at the bounds of the search space and the value of the sought key, usually via a linear interpolation. The key value actually found at this estimated position is then compared to the key value being sought. If it is not equal, then depending on the comparison, the remaining search space is reduced to the part before or after the estimated position. This method will only work if calculations on the size of differences between key values are sensible.
By comparison, binary search always chooses the middle of the remaining search space, discarding one half or the other, depending on the comparison between the key found at the estimated position and the key sought — it does not require numerical values for the keys, just a total order on them. The remaining search space is reduced to the part before or after the estimated position. The linear search uses equality only as it compares elements one-by-one from the start, ignoring any sorting.
On average the interpolation search makes about log(log(n)) comparisons (if the elements are uniformly distributed), where n is the number of elements to be searched. In the worst case (for instance where the numerical values of the keys increase exponentially) it can make up to O(n) comparisons.
In interpolation-sequential search, interpolation is used to find an item near the one being searched for, then linear search is used to find the exact item.
###### Source: [Wikipedia](https://en.wikipedia.org/wiki/Interpolation_search)
## Jump Search
In computer science, a jump search or block search refers to a search algorithm for ordered lists. It works by first checking all items Lkm, where {\displaystyle k\in \mathbb {N} } k\in \mathbb {N} and m is the block size, until an item is found that is larger than the search key. To find the exact position of the search key in the list a linear search is performed on the sublist L[(k-1)m, km].
The optimal value of m is √n, where n is the length of the list L. Because both steps of the algorithm look at, at most, √n items the algorithm runs in O(√n) time. This is better than a linear search, but worse than a binary search. The advantage over the latter is that a jump search only needs to jump backwards once, while a binary can jump backwards up to log n times. This can be important if a jumping backwards takes significantly more time than jumping forward.
The algorithm can be modified by performing multiple levels of jump search on the sublists, before finally performing the linear search. For an k-level jump search the optimum block size ml for the lth level (counting from 1) is n(k-l)/k. The modified algorithm will perform k backward jumps and runs in O(kn1/(k+1)) time.
###### Source: [Wikipedia](https://en.wikipedia.org/wiki/Jump_search)
## Quick Select
![alt text][QuickSelect-image]
In computer science, quickselect is a selection algorithm to find the kth smallest element in an unordered list. It is related to the quicksort sorting algorithm. Like quicksort, it was developed by Tony Hoare, and thus is also known as Hoare's selection algorithm.[1] Like quicksort, it is efficient in practice and has good average-case performance, but has poor worst-case performance. Quickselect and its variants are the selection algorithms most often used in efficient real-world implementations.
Quickselect uses the same overall approach as quicksort, choosing one element as a pivot and partitioning the data in two based on the pivot, accordingly as less than or greater than the pivot. However, instead of recursing into both sides, as in quicksort, quickselect only recurses into one side the side with the element it is searching for. This reduces the average complexity from O(n log n) to O(n), with a worst case of O(n2).
As with quicksort, quickselect is generally implemented as an in-place algorithm, and beyond selecting the k'th element, it also partially sorts the data. See selection algorithm for further discussion of the connection with sorting.
###### Source: [Wikipedia](https://en.wikipedia.org/wiki/Quickselect)
## Tabu
Tabu search uses a local or neighborhood search procedure to iteratively move from one potential solution {\displaystyle x} x to an improved solution {\displaystyle x'} x' in the neighborhood of {\displaystyle x} x, until some stopping criterion has been satisfied (generally, an attempt limit or a score threshold). Local search procedures often become stuck in poor-scoring areas or areas where scores plateau. In order to avoid these pitfalls and explore regions of the search space that would be left unexplored by other local search procedures, tabu search carefully explores the neighborhood of each solution as the search progresses. The solutions admitted to the new neighborhood, {\displaystyle N^{*}(x)} N^*(x), are determined through the use of memory structures. Using these memory structures, the search progresses by iteratively moving from the current solution {\displaystyle x} x to an improved solution {\displaystyle x'} x' in {\displaystyle N^{*}(x)} N^*(x).
These memory structures form what is known as the tabu list, a set of rules and banned solutions used to filter which solutions will be admitted to the neighborhood {\displaystyle N^{*}(x)} N^*(x) to be explored by the search. In its simplest form, a tabu list is a short-term set of the solutions that have been visited in the recent past (less than {\displaystyle n} n iterations ago, where {\displaystyle n} n is the number of previous solutions to be stored — is also called the tabu tenure). More commonly, a tabu list consists of solutions that have changed by the process of moving from one solution to another. It is convenient, for ease of description, to understand a “solution” to be coded and represented by such attributes.
###### Source: [Wikipedia](https://en.wikipedia.org/wiki/Tabu_search)
----------------------------------------------------------------------------------------------------------------------
## Ciphers
@ -168,15 +214,38 @@ The encryption step performed by a Caesar cipher is often incorporated as part o
### Vigenère
The **Vigenère cipher** is a method of encrypting alphabetic text by using a series of **interwoven Caesar ciphers** based on the letters of a keyword. It is **a form of polyalphabetic substitution**.<br>
The Vigenère cipher has been reinvented many times. The method was originally described by Giovan Battista Bellaso in his 1553 book La cifra del. Sig. Giovan Battista Bellaso; however, the scheme was later misattributed to Blaise de Vigenère in the 19th century, and is now widely known as the "Vigenère cipher".<br>
Though the cipher is easy to understand and implement, for three centuries it resisted all attempts to break it; this earned it the description **le chiffre indéchiffrable**(French for 'the indecipherable cipher').
Though the cipher is easy to understand and implement, for three centuries it resisted all attempts to break it; this earned it the description **le chiffre indéchiffrable**(French for 'the indecipherable cipher').
Many people have tried to implement encryption schemes that are essentially Vigenère ciphers. Friedrich Kasiski was the first to publish a general method of deciphering a Vigenère cipher in 1863.
###### Source: [Wikipedia](https://en.wikipedia.org/wiki/Vigen%C3%A8re_cipher)
### Transposition
In cryptography, a **transposition cipher** is a method of encryption by which the positions held by units of plaintext (which are commonly characters or groups of characters) are shifted according to a regular system, so that the ciphertext constitutes a permutation of the plaintext. That is, the order of the units is changed (the plaintext is reordered).<br>
In cryptography, a **transposition cipher** is a method of encryption by which the positions held by units of plaintext (which are commonly characters or groups of characters) are shifted according to a regular system, so that the ciphertext constitutes a permutation of the plaintext. That is, the order of the units is changed (the plaintext is reordered).<br>
Mathematically a bijective function is used on the characters' positions to encrypt and an inverse function to decrypt.
###### Source: [Wikipedia](https://en.wikipedia.org/wiki/Transposition_cipher)
### RSA (RivestShamirAdleman)
RSA (RivestShamirAdleman) is one of the first public-key cryptosystems and is widely used for secure data transmission. In such a cryptosystem, the encryption key is public and it is different from the decryption key which is kept secret (private). In RSA, this asymmetry is based on the practical difficulty of the factorization of the product of two large prime numbers, the "factoring problem". The acronym RSA is made of the initial letters of the surnames of Ron Rivest, Adi Shamir, and Leonard Adleman, who first publicly described the algorithm in 1978. Clifford Cocks, an English mathematician working for the British intelligence agency Government Communications Headquarters (GCHQ), had developed an equivalent system in 1973, but this was not declassified until 1997.[1]
A user of RSA creates and then publishes a public key based on two large prime numbers, along with an auxiliary value. The prime numbers must be kept secret. Anyone can use the public key to encrypt a message, but with currently published methods, and if the public key is large enough, only someone with knowledge of the prime numbers can decode the message feasibly.[2] Breaking RSA encryption is known as the RSA problem. Whether it is as difficult as the factoring problem remains an open question.
###### Source: [Wikipedia](https://en.wikipedia.org/wiki/RSA_(cryptosystem))
## ROT13
![alt text][ROT13-image]
ROT13 ("rotate by 13 places", sometimes hyphenated ROT-13) is a simple letter substitution cipher that replaces a letter with the 13th letter after it, in the alphabet. ROT13 is a special case of the Caesar cipher which was developed in ancient Rome.
Because there are 26 letters (2×13) in the basic Latin alphabet, ROT13 is its own inverse; that is, to undo ROT13, the same algorithm is applied, so the same action can be used for encoding and decoding. The algorithm provides virtually no cryptographic security, and is often cited as a canonical example of weak encryption.[1]
###### Source: [Wikipedia](https://en.wikipedia.org/wiki/ROT13)
## XOR
In cryptography, the simple XOR cipher is a type of additive cipher,[1] an encryption algorithm that operates according to the principles:
A {\displaystyle \oplus } \oplus 0 = A,
A {\displaystyle \oplus } \oplus A = 0,
(A {\displaystyle \oplus } \oplus B) {\displaystyle \oplus } \oplus C = A {\displaystyle \oplus } \oplus (B {\displaystyle \oplus } \oplus C),
(B {\displaystyle \oplus } \oplus A) {\displaystyle \oplus } \oplus A = B {\displaystyle \oplus } \oplus 0 = B,
where {\displaystyle \oplus } \oplus denotes the exclusive disjunction (XOR) operation. This operation is sometimes called modulus 2 addition (or subtraction, which is identical).[2] With this logic, a string of text can be encrypted by applying the bitwise XOR operator to every character using a given key. To decrypt the output, merely reapplying the XOR function with the key will remove the cipher.
###### Source: [Wikipedia](https://en.wikipedia.org/wiki/XOR_cipher)
[bubble-toptal]: https://www.toptal.com/developers/sorting-algorithms/bubble-sort
[bubble-wiki]: https://en.wikipedia.org/wiki/Bubble_sort
[bubble-image]: https://upload.wikimedia.org/wikipedia/commons/thumb/8/83/Bubblesort-edited-color.svg/220px-Bubblesort-edited-color.svg.png "Bubble Sort"
@ -220,3 +289,7 @@ Mathematically a bijective function is used on the characters' positions to encr
[caesar]: https://upload.wikimedia.org/wikipedia/commons/4/4a/Caesar_cipher_left_shift_of_3.svg
[ROT13-image]: https://en.wikipedia.org/wiki/File:ROT13_table_with_example.svg
[QuickSelect-image]: https://en.wikipedia.org/wiki/File:Selecting_quickselect_frames.gif

View File

@ -68,8 +68,8 @@ def getRandomKey():
while True:
keyA = random.randint(2, len(SYMBOLS))
keyB = random.randint(2, len(SYMBOLS))
if cryptoMath.gcd(keyA, len(SYMBOLS)) == 1:
return keyA * len(SYMBOLS) + keyB
if cryptoMath.gcd(keyA, len(SYMBOLS)) == 1:
return keyA * len(SYMBOLS) + keyB
if __name__ == '__main__':
import doctest

View File

@ -24,7 +24,7 @@ class LinkedList:
temp = self.head
self.head = self.head.next # oldHead <--> 2ndElement(head)
self.head.previous = None # oldHead --> 2ndElement(head) nothing pointing at it so the old head will be removed
if(self.head == None):
if(self.head is None):
self.tail = None
return temp
@ -58,7 +58,7 @@ class LinkedList:
current.next.previous = current.previous # 1 <--> 3
def isEmpty(self): #Will return True if the list is empty
return(self.head == None)
return(self.head is None)
def display(self): #Prints contents of the list
current = self.head

View File

@ -19,4 +19,4 @@ class LinkedList:
return item
def is_empty(self):
return self.head == None
return self.head is None

View File

@ -67,3 +67,4 @@ class Linked_List:
current = next_node
# Return prev in order to put the head at the end
Head = prev
return Head

View File

@ -1,5 +1,5 @@
import tensorflow as tf
from random import choice, shuffle
from random import shuffle
from numpy import array

Binary file not shown.

File diff suppressed because one or more lines are too long

View File

@ -59,7 +59,6 @@ def sum_of_square_error(data_x, data_y, len_data, theta):
:param theta : contains the feature vector
:return : sum of square error computed from given feature's
"""
error = 0.0
prod = np.dot(theta, data_x.transpose())
prod -= data_y.transpose()
sum_elem = np.sum(np.square(prod))

View File

@ -28,9 +28,8 @@ Game-Of-Life Rules:
comes a live cell, as if by reproduction.
'''
import numpy as np
import random, time, sys
import random, sys
from matplotlib import pyplot as plt
import matplotlib.animation as animation
from matplotlib.colors import ListedColormap
usage_doc='Usage of script: script_nama <size_of_canvas:int>'

View File

@ -290,7 +290,7 @@ def goldbach(number):
while (i < lenPN and loop):
j = i+1;
j = i+1
while (j < lenPN and loop):
@ -300,9 +300,8 @@ def goldbach(number):
ans.append(primeNumbers[i])
ans.append(primeNumbers[j])
j += 1;
j += 1
i += 1
# precondition

View File

@ -2,7 +2,6 @@
This is pure python implementation of interpolation search algorithm
"""
from __future__ import print_function
import bisect
try:
raw_input # Python 2

View File

@ -1,8 +1,5 @@
import collections
import sys
import random
import time
import math
"""
A python implementation of the quick select algorithm, which is efficient for calculating the value that would appear in the index of a list if it would be sorted, even if it is not already sorted
https://en.wikipedia.org/wiki/Quickselect
@ -25,23 +22,23 @@ def _partition(data, pivot):
equal.append(element)
return less, equal, greater
def quickSelect(list, k):
def quickSelect(list, k):
#k = len(list) // 2 when trying to find the median (index that value would be when list is sorted)
smaller = []
larger = []
pivot = random.randint(0, len(list) - 1)
pivot = list[pivot]
count = 0
smaller, equal, larger =_partition(list, pivot)
count = len(equal)
m = len(smaller)
smaller = []
larger = []
pivot = random.randint(0, len(list) - 1)
pivot = list[pivot]
count = 0
smaller, equal, larger =_partition(list, pivot)
count = len(equal)
m = len(smaller)
#k is the pivot
if m <= k < m + count:
#k is the pivot
if m <= k < m + count:
return pivot
# must be in smaller
elif m > k:
elif m > k:
return quickSelect(smaller, k)
#must be in larger
else:
else:
return quickSelect(larger, k - (m + count))

View File

@ -1,15 +1,3 @@
"""
This is pure python implementation of bubble sort algorithm
For doctests run following command:
python -m doctest -v bubble_sort.py
or
python3 -m doctest -v bubble_sort.py
For manual testing run:
python bubble_sort.py
"""
from __future__ import print_function
@ -46,7 +34,6 @@ if __name__ == '__main__':
raw_input # Python 2
except NameError:
raw_input = input # Python 3
user_input = raw_input('Enter numbers separated by a comma:\n').strip()
user_input = raw_input('Enter numbers separated by a comma:').strip()
unsorted = [int(item) for item in user_input.split(',')]
print(bubble_sort(unsorted))
print(*bubble_sort(unsorted), sep=',')

View File

@ -4,7 +4,6 @@
# Sort large text files in a minimum amount of memory
#
import os
import sys
import argparse
class FileSplitter(object):

View File

@ -2,7 +2,6 @@ from __future__ import print_function
from random import randint
from tempfile import TemporaryFile
import numpy as np
import math

View File

@ -11,12 +11,12 @@ class node():
def insert(self,val):
if self.val:
if val < self.val:
if self.left == None:
if self.left is None:
self.left = node(val)
else:
self.left.insert(val)
elif val > self.val:
if self.right == None:
if self.right is None:
self.right = node(val)
else:
self.right.insert(val)

View File

@ -68,7 +68,6 @@ def assemble_transformation(ops, i, j):
return seq
if __name__ == '__main__':
from time import sleep
_, operations = compute_transform_tables('Python', 'Algorithms', -1, 1, 2, 2)
m = len(operations)