Unit 8 · Lesson 1

Algorithms
Solve Problems

FRQ · Warm-Up

What Makes Code "the Same"?

What makes two pieces of code "the same"? Could there ever be two pieces of code that you consider to be "the same" even if they are not identical?

Activity · Think

Birthday Problems

Take 1 minute to think about how you will find the answers to these questions.

  • Find a person whose birthday is before yours.
  • Find a person whose birthday is after yours.
  • Find the person whose birthday is closest before yours.
  • Find the person whose birthday is closest after yours.
  • Find the person whose birthday is closest to yours.
  • Find the person with an equal number of birthdays before and after theirs.
  • Find the two people with the closest birthdays in the room.
  • Find the shortest period of time in which three people have birthdays.
  • Find the shortest period of time in which four people have birthdays.
  • Find the longest period of time in which no one has a birthday.
Activity · Go

Birthday Problems

Find the answers to these questions.

  • Find a person whose birthday is before yours.
  • Find a person whose birthday is after yours.
  • Find the person whose birthday is closest before yours.
  • Find the person whose birthday is closest after yours.
  • Find the person whose birthday is closest to yours.
  • Find the person with an equal number of birthdays before and after theirs.
  • Find the two people with the closest birthdays in the room.
  • Find the shortest period of time in which three people have birthdays.
  • Find the shortest period of time in which four people have birthdays.
  • Find the longest period of time in which no one has a birthday.
Activity · Debrief

Reflect on Your Process

How did you go about solving each of these problems?

Which problems required you to do something similar in order to solve?

With your partner, decide which of these programs are "the same" as one another.

Algorithm 1
MOVE_FORWARD()
TURN_RIGHT()
MOVE_FORWARD()
TURN_RIGHT()
MOVE_FORWARD()
TURN_RIGHT()
MOVE_FORWARD()
TURN_RIGHT()
Algorithm 2
REPEAT 2 TIMES
{
    MOVE_FORWARD()
    MOVE_FORWARD()
    TURN_RIGHT()
    MOVE_FORWARD()
    TURN_RIGHT()
}
Algorithm 3
moves ← ["F","R","F","R",
         "F","R","F","R"]
FOR EACH move IN moves
{
    IF (move = "F")
    {
        MOVE_FORWARD()
    }
    ELSE
    {
        TURN_RIGHT()
    }
}
Algorithm 4
Algorithm 4 flowchart: count loop repeating MOVE_FORWARD and TURN_RIGHT
Algorithm 5
REPEAT 2 TIMES
{
    REPEAT 2 TIMES
    {
        MOVE_FORWARD()
    }
    REPEAT 3 TIMES
    {
        TURN_LEFT()
    }
    MOVE_FORWARD()
    REPEAT 3 TIMES
    {
        TURN_LEFT()
    }
}
Algorithm 6
Algorithm 6 flowchart: nested count loop with TURN_LEFT inner loop
FRQ · Discussion

Which Algorithms Are "the Same"?

Which of these algorithms are "the same" as one another? How did you decide that?

Wrap-Up · Key Terms

Problem

A general description of a task that can (or cannot) be solved with an algorithm.

Algorithm

A finite set of instructions that accomplish a task. There are usually many algorithms to solve the same problem, and many ways to write or express one algorithm: natural language, pseudocode, diagrams, and programming code.

All algorithms can be created by combining steps in three different ways.

Sequencing flowchart: steps connected in a linear chain

Sequencing

Putting steps in order.

Selection flowchart: a diamond decision node branching true or false

Selection

Deciding which steps to do next.

Iteration flowchart: a loop that repeats a block of steps

Iteration

Doing some steps over and over.

FRQ · Reflection

Looking Back

How did today's activities change the way you think about algorithms and problems?

FRQ · Exit Ticket

Exit Ticket

In your own words, explain the difference between a problem and an algorithm.