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?
Take 1 minute to think about how you will find the answers to these questions.
Find the answers to these questions.
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.
MOVE_FORWARD() TURN_RIGHT() MOVE_FORWARD() TURN_RIGHT() MOVE_FORWARD() TURN_RIGHT() MOVE_FORWARD() TURN_RIGHT()
REPEAT 2 TIMES
{
MOVE_FORWARD()
MOVE_FORWARD()
TURN_RIGHT()
MOVE_FORWARD()
TURN_RIGHT()
}moves ← ["F","R","F","R",
"F","R","F","R"]
FOR EACH move IN moves
{
IF (move = "F")
{
MOVE_FORWARD()
}
ELSE
{
TURN_RIGHT()
}
}
REPEAT 2 TIMES
{
REPEAT 2 TIMES
{
MOVE_FORWARD()
}
REPEAT 3 TIMES
{
TURN_LEFT()
}
MOVE_FORWARD()
REPEAT 3 TIMES
{
TURN_LEFT()
}
}
Which of these algorithms are "the same" as one another? How did you decide that?
A general description of a task that can (or cannot) be solved with an 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.
Putting steps in order.
Deciding which steps to do next.
Doing some steps over and over.
How did today's activities change the way you think about algorithms and problems?
In your own words, explain the difference between a problem and an algorithm.