Coding and Algorithms

Ontario 09 Applied (MFM1P)

Following directions (Investigation)

Lesson

An algorithm is a process or set of rules to be followed to solve a calculation or other problem, or to complete a task. When we are coding, we write algorithms for the computer. We can also write algorithms or instructions for real life activities too. Take a minute to think of some now.

Recipes, instruction books and giving directions are real life examples of algorithms.

When you're giving directions it's really important to be clear and precise! Imagine if your friend was blindfolded and you had to direct them through an obstacle course. What might happen if your instructions weren't clear? Well your friend could run into a wall or slip into a muddy pond- yuk!

So let's practice giving clear instructions now.

Direct this hungry zombie towards the sunflower so it can eat. Make sure you avoid the chompers!

See if you can do it in the fewest steps possible.

Click here to go to the activity.

- Click on the "show code" button when you have finished each puzzle. What similarities do you notice between the blocks you used and the code that is written?
- What happened to the number of steps when you used the repeat function? What might the benefits of this be?
- What challenges did you face as you worked through this task? How did you overcome these? What did you learn from them?

Work in groups of four to complete this task.

- Come up with your own step-by-step algorithm to tell someone how to get from your classroom to the school canteen.
- List the steps in order, numbering them $1,2,3$1,2,3 and so on.
- Pretend that this person has no idea how to get around your school, and needs to be told absolutely everything! Tell them how many steps to take/ how far they need to walk, when to turn left or right, and whether to go down stairs.
- After you have worked with your group to come up with your algorithm, take a stop watch and time how long it takes to walk from the classroom to the canteen using your algorithm. Make sure that everyone in the class is walking at the same speed (no running!).
- After every group has finished timing their algorithms, return to the classroom.

Compare your results as a class and answer the following questions.

- Which group had the shortest time? What was their algorithm?
- Which group had the longest time? What was their algorithm?
- Which group had the algorithm with the most written steps? What was their time?
- Which group had the algorithm with the least written steps? What was their time?
- Will an algorithm with the least amount of steps always take the least time?
- Keeping the same steps, could you have changed the order of any steps, and still arrived at the canteen?