A little review on Algorithms:

what are the three components of an algorithm?

  • sel__
  • seq__
  • it___

Today we will be looking at algorithms from another standpoint.
Q: How many ways are there to peel a banana? Is the result the same?

Main Idea 1:

Algorithms can be written in different ways and still do the same thing

  • However, Algorithms that look similar might not always have the same result
  • Different algorithms can be used to solve the same problem

Examples!

The goal with the two algorithms below is to show "Wow! Good job!" when you get an A and show "Nice!" when you get a B or C (pass), if you don't pass (lower than 70) it will show "Do Better"

print("What Grade Did You Get?")
grade = int(input("Enter Grade:"))
if grade >= 90:
        print("Wow! Good job!")
if 70 <= grade < 90:
        print("Nice!")
elif grade < 70:
        print("Do Better")
What Grade Did You Get?
Nice!

yay! it worked! Lets look at the next one. Do you notice any differences? Do you think this algorithm will still achieve the same goal? If not, what is the flaw?

print("What Grade Did You Get?")
grade = int(input("Enter Grade:"))
if grade >= 90:
        print("Wow! Good job!")
elif 70 < grade < 90:
        print("Nice!")
elif grade < 70:
        print("Do Better")
What Grade Did You Get?

So, why is this important? Why are we even doing this?

when 2 algorithms look extremely similar, it is easy to assume they do the same thing. However, that is not the case and we have learn how to notice small differences in code and pretty much debug.
- just know that codes that look similar don't always produce the same things:)

Real-life situation (Storytime)

Tommy and Billy are working on solving the same issue with an algorithm
Tommy creates a functioning code and yells "I did it!"
He looks over at his friend Billy which is having a bit of trouble and he offers help
However, Billy's code looks basically the same! which confuses them
Then they remeber that they were taught that algorithms that look similar don't always have the same results and they collaborate to do further investigation:)

Now, without running, investigate the algorithm below. This one looks different. Do you thing it will still achieve the same goal as above?

print("What Grade Did You Get?")
grade = int(input("Enter Grade:"))
A = grade >= 90
B = 70 <= grade < 90
C = grade < 70
if A:
        print("Wow! Good job!")
elif B:
        print("Nice!")
elif C:
        print("Do Better")
What Grade Did You Get?
Do Better

Why is this important?
When collaborating or working on group projects, two people might come up with two different ways to solve a problem, and that happens a lot.

  • know that same goal can be achieved in many ways (the possibilities are endless)
  • make notes in you code! (explain how it works to others or you future self)

Hacks:

Make your own version of this!
requirements:

  • main goal of algorithm
  • main/base algorithm (ideal algorithm)
  • an algorithm that visual looks like the first one but is flawed, has a different result, or both
    • explain the flaw either in notes of your code or in a markdown
  • an algorithm that looks very different from first algorithm but has some result/ solves the same problem
    • explanation/ comparison of this algorithm with the first one


The Algorithms don't have to be super complicated! But it should be complex enough to show a good understanding of this lesson as well as previous ones


Scoring Rubric:

  • 0.05 for an interesting goal
  • 0.05 for a well completed main algorithm
  • 0.05 for algorithm that looks the same but is different
  • 0.05 for algorithm that looks different but is the same
  • 0.05 for explanation of both algorithms above
  • total: 0.25

Extra things to add to notes:)


  • why having this understanding of algorithms is important to you as a coder