Skip to content

Instantly share code, notes, and snippets.

View wilcoln's full-sized avatar
:octocat:

Wilfried L. Bounsi wilcoln

:octocat:
View GitHub Profile
def count(a,x, left, right):
count = 0
for i in range(left, right+1):
if a[i] == x:
count+=1
return count
def maj(a,left, right):
if left == right:
return a[left]
middle = (left+right)//2
@wilcoln
wilcoln / quickSort.py
Created December 9, 2018 17:53
Quick sort in python
def partition(a,p,r):
pivot = p
for i in range(p+1,r+1):
if(a[i]<a[pivot]):
tmp = a[i]
a[i] = a[pivot+1]
a[pivot+1] = a[pivot]
a[pivot] = tmp
pivot = pivot + 1
return pivot
@wilcoln
wilcoln / souvenirs.py
Created December 9, 2018 14:06
Partitioning souvenirs into three equal parts
# >> Code for quick sort
def partition(a,p,r):
pivot = p
for i in range(p+1,r+1):
if(a[i]<a[pivot]):
tmp = a[i]
a[i] = a[pivot+1]
a[pivot+1] = a[pivot]
a[pivot] = tmp
pivot = pivot + 1
@wilcoln
wilcoln / circular.py
Last active December 9, 2018 17:53
Google string problem
def areCircular(s1,s2):
result = False
size = len(s1)
nbPermut = size
tmp = s1
while( not result and nbPermut > 0):
circularPermutation = []
for i in range(size):
circularPermutation.append(tmp[(i - 1)%size])
tmp = ''.join(circularPermutation)
@wilcoln
wilcoln / bubbleSort.py
Created March 10, 2018 19:17
Python bubble sort code
def bubble(tab):
permutation = True
while(permutation):
permutation = False
for i in range(0,len(tab)-1):
if(tab[i] > tab[i+1]):
tmp = tab[i]
tab[i] = tab[i+1]
tab[i+1] = tmp
permutation = True
@wilcoln
wilcoln / selectionSort.py
Created March 10, 2018 19:16
Python Selection sort code
def selection(array):
for i in range(len(array)):
key = i
for j in range(i+1, len(array)):
if(array[key] > array[j]):
key = j
tmp = array[i]
array[i] = array[key]
array[key] = tmp
@wilcoln
wilcoln / InsertionSort.py
Created March 10, 2018 19:14
Python Insertion sort code
def insertion(array):
for i in range(1, len(array)):
key = array[i]
j = i-1
while(j>-1 and array[j] > key):
array[j+1] = array[j]
j-=1
array[j+1] = key
@wilcoln
wilcoln / mergeSort.py
Created March 10, 2018 19:13
python merge sort code
def merge(array, p, q, r):
sub1 = array[p:q+1]
sub2 = array[q+1:r+1]
k, i, j = p, 0, 0
for k in range(p,r+1):
if(i > len(sub1) - 1):
array[k] = sub2[j]
j+=1
elif(j > len(sub2) - 1):
array[k] = sub1[i]