Notes

  • An algorithm’s efficiency is determine through formal or mathematical reasoning.

  • Decidable problem: problems for which algorithms can be written to solve/produce a correct output for all possible inputs.

  • Decision problem: problem with a binary answer (yes or no). An optimization problem is a problem with the objective of finding the BEST solution amongst many possibilities to solve a problem.

  • Problem: description of a task that may or may not be able to be solved through the use of an algorithm. An instance of a problem includes a specific input. One example of this type of problem is a sorting problem.

  • Undecidable problem: problems for which no algorithms can be built that can provide a correct yes or no answer.

Hack 1

Decidable problems are those that can be solved through the use of an algorithm. An example is determining whether a number is even or odd. Undecidable problems cant be solved with an algorithmic procedure. An example is the halting problem which asks if the program will run forever or halt.

Hack 2

Which of the following is a 3 step algorithm?

A. 2 x 6 x 8

B. 4^5

C. (3 x 8)^2

D. None of the above

E. All of the above

C is the correct answer since you have to multiply the numbers inside of the parenthesis then take that value to the power of two.

Hacks 3 and 4

function peak_finder(array) {
  var peak = array[0];
  for (i = 0; i < array.length; i ++) {
    if (array[i] > peak) {
      var peak = array[i];
    }
  }
  return peak;
}

var numbers = [1, 2, 3, 4, 5, 6, 7, 8];
console.log(peak_finder(numbers));
  Cell In[2], line 1
    function peak_finder(array) {
             ^
SyntaxError: invalid syntax
data = [9, 1, 7, 6, 2, 8, 5, 3, 4, 0]

print("original list")
print(data)
data.sort()
print("-----------------")
print("sorted list")
print(data)
original list
[9, 1, 7, 6, 2, 8, 5, 3, 4, 0]
-----------------
sorted list
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

Hack 5

Explanation for Code: Imports the permutation method from the library itertools. Using this, we can use a built in command to create permutations. Using a for loop, we can iterate through all possible permutations, and print them.

from itertools import permutations

data = [1, 2, 3]

for i in permutations(data):
    print(i)
(1, 2, 3)
(1, 3, 2)
(2, 1, 3)
(2, 3, 1)
(3, 1, 2)
(3, 2, 1)

Reflection

These lessons were a little difficult at first, but with persistence, I was able to grasp the ideas, which enabled me to correctly respond to the questions. I took a lot away from the presentation because it was amazing.