Hacks Section 17-18
Vocab
- undecidable problem problems for which no algorithms can be built that can provide a correct yes or no answer or a solution
- Decidable problem problems for which algorthms could be written to solve/produce a correct output for all inputs.
- Superpolynomial a specfic run time for an algorithm that help it grow througout time complexity.
Hack 1
- An undecidable problem is something an Algorithm cant really make this is shown in the questin about god as he has a certain amount of power but can he lift a rock that weighs more than the undefiable. A decidble problem is something that can be created for an algorithm for example how to randomize the role of a dice and compare it with another persons role.
function peak_finder2(array){
if (array.length)=== 0{
return `Array cannot be empty`
}else if (array.length === 1){
return array[0]
}else{
let mid_index = Math.floor(array.length*0.5)
if (array[mid_index +1]>array[mid_index]){
return peak_finding(array.slice(mid_index + 1 ))
}else if (array[mid_index -1]>array[mid_index]){
new=array.reverse().slice(mid_index+1).reverse()
return peak_finding(new)
}else{
return array[mid_index]
}
}
}
// Note I edited my answer based on the key as I was unsure of my previous answer I think I struggled due to my lack of profieceny in javascript, however I was able to make the array more simple and write a conditional
data = [9, 1, 7, 6, 2, 8, 5, 3, 4, 0]
data.sort()
print(data)
perm = permutations([1, 2, 3])
for i in list(perm):
print (i)
def heap_permutation(data, n):
if n == 1:
print(data)
return
for i in range(n):
heap_permutation(data, n - 1)
if n % 2 == 0:
data[i], data[n-1] = data[n-1], data[i]
else:
data[0], data[n-1] = data[n-1], data[0]
if __name__ == '__main__':
data = ["car, watch, toy"]
heap_permutation(data, len(data))
from itertools import permutations
perm = permutations(["car", "watch","toy"])
for i in list(perm):
print (i)