This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import matplotlib.pyplot as plt | |
def insertionSort(array): | |
steps = 0 | |
start = time.time() | |
for a in range(1,len(array)): | |
steps+=1 | |
key = array[a] | |
b = a-1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import matplotlib.pyplot as plt | |
import random | |
def merge(a,b,steps): | |
# creating array | |
c = [] | |
# creating pointers | |
j=0 | |
i=0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import math | |
def max_subarray(x): | |
# starting array to make any subarray bigger than its value | |
maxSubarray = [-(math.inf)] | |
# looping through all the array to find the maxsubarray | |
# bruteforce approach | |
for j in range(len(x)): | |
for i in range(j+1, len(x)+1): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def maxHeapify(A,i): | |
# it takes the node with index i and puts it in the right position | |
# in the heap to make it a maxHeap | |
l = Left(i) | |
r = Right(i) | |
# since we already know that element in index i will be: smaller | |
# than the right/left child or higher than both | |
# we are storing the index of the higher child in 'largest' | |
# which will be the substitution that we need to make, in case that we need to do any substitution | |
if l < (len(A)) and A[l] > A[i]: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import matplotlib.pyplot as plt | |
import random | |
def merge3(a,b,c): | |
# Starting array that will be returned | |
final = [] | |
# Starting pointers | |
i=0 # pointer for array 'a' | |
j=0 # pointer for array 'b' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import time | |
import matplotlib.pyplot as plt | |
import random | |
def merge3(a,b,c): | |
# Starting array that will be returned | |
final = [] | |
# Starting pointers | |
i=0 # pointer for array 'a' | |
j=0 # pointer for array 'b' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def Right(i): | |
# right child index | |
return 2*i + 2 | |
def Left(i): | |
# left child index | |
return 2*i +1 | |
def Parent(i): | |
# parent index |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
def Right(i): | |
# right child index | |
return 2*i + 2 | |
def Left(i): | |
# left child index | |
return 2*i +1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import matplotlib.pyplot as plt | |
def hatCheck(n): | |
# using index as the id for people | |
# creating list for hats from 0 to 'n' matching | |
# the index and then shuffling it | |
hat = [a for a in range(0,n)] | |
random.shuffle(hat) | |
correct =0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import matplotlib.pyplot as plt | |
import math | |
def askingNewAssistant(): | |
# getting new assistant ability | |
return random.random() | |
def hireAssistant(n): | |
# hire assistant for n applications |
OlderNewer