# Lesson 1: Algorithms Solve Problems

## Overview

Students will complete two exploratory activities that introduce the concept of a problem and an algorithm. In the first students answer a series of questions about birthdates and names of their classmates. They then discuss the similarities and differences between the problems. In the second activity students are given six different algorithms and must analyze them to determine which they think are the same or different. At the end of the lesson they are introduced to the formal definitions of a problem and an algorithm.

## Purpose

This lesson is an approachable and interactive introduction to the main concepts of this short unit. Students have been writing a lot of code, and now they are ready to think on a high level about the patterns that make two different problems, or two different algorithms, similar or different. This mindset will be important as they tackle the more challenging material later in the unit where students will learn to compare different algorithms that address the same problem.

## Agenda

### Lesson Modifications

### Warm Up (5 mins)

### Activity (30 mins)

### Wrap Up (10 mins)

### View on Code Studio

## Objectives

### Students will be able to:

- Explain the formal definitions of a problem, an algorithm, sequencing, selection, and iteration.
- Explain that some problems may look different but be similar or look similar but be different.
- Explain that some algorithms may look or operate differently but still solve the same problem.

## Preparation

- Review the algorithms students will be comparing in the second activity to make sure you are prepared to support students in trying them out.

## Links

**Heads Up!** Please make a copy of any documents you plan to share with students.

### For the Teachers

- CSP Unit 6 - Algorithms - Presentation

# Teaching Guide

## Lesson Modifications

**Attention, teachers!** If you are teaching virtually or in a socially-distanced classroom, please read the full lesson plan below, then click here to access the modifications.

## Warm Up (5 mins)

Discussion Goal

**Goal:** This is an optional prompt. If you are able to move directly to the main activity you should do so. This prompt should get students thinking about the themes of the lesson.

There are no "wrong answers" here though you should expect answers that focus on the fact that often there's lots of ways to write code that does the same thing.

**Prompt:** 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 aren’t identical?

**Discuss:** Have students think about their answers on their own, then share with a partner, and then finally discuss responses with the entire room.

## Activity (30 mins)

Remarks

Today we are going to kick off a short unit about how computer scientists think about problem solving. A really important skill will be recognizing patterns and similarities.

### Comparing Problems

**Distribute:** Ask students to take out their journals or give them some blank paper for working on the following problems

**Display:** Show the slides for the ten problems students will need to solve.

Discussion Goal

**Goal:** This discussion should focus on what made the problems that students solved similar to one another. You likely will want to put the problems back on the screen to make it easier to talk through. Here are some connections you may pull out though there are more students may make.

- Problems 1 and 2 are very similar. As soon as you find one person who meets the criteria you know you're done.
- Problem 3 and 4 are very similar but you need to talk to every other student to answer it. You only need to keep track of the closest birthday you've heard so far, however.
- Problem 5 is easy to solve as soon as you've solved problems 3 and 4.
- Problem 6 - 10 require you to have written down everyone's birthday, likely in order.
- Problems 7 - 9 are the same problem but for different numbers of people. Whatever strategy you use for one of those would be helpful to solve the others
- Problem 10 is a different version of problem 7 but instead of finding the smallest gap you're finding the largest.

**Circulate:** Ask students to review the problems for one minute, and then let them move around the room collecting information needed to solve the problems. This may take them several minutes.

**Prompt:** Which problems did you need to do something similar in order to solve them?

**Discuss:** Have students discuss the prompt with a neighbor before asking them to share with the room. Lead a discussion on their experiences.

Remarks

The first thing that we need to think about as computer scientists is what is a "problem". We just looked at 10 problems, but as we discussed, a lot of them are similar. If we solve one problem we may actually solve another, or at least have a good idea for how to start solving another. As computer scientists it's important to ask "have I seen this problem before" or "how is this problem similar to others I've solved?"

### Comparing Algorithms

Remarks

We just thought about whether problems are similar. Now we're going to look at whether we're actually solving the same problem.

**Prompt:** Which of these algorithms are “the same” as one another?

Discussion Goal

**Goal:** This discussion should focus on what made the algorithms the same. While they are designed to fall into two categories, ideally a number of points should come out of this discussion.

- Algorithms 1, 3, and 4 draw a square while 2, 5, and 6 draw a rectangle
- Algorithms 4 and 6 are written using a flowchart while 1, 2, 3, and 5 are written in the AP Pseudocode
- Some of these algorithms turn the robot right but turning left three times. It's debateable whether we can really call these algorithms "the same"
- Some of these algorithms create lists or variables to store information. Depending on the context we may not be able to call these algorithms "the same"

**Circulate:** Ask students to review the algorithms with a partner and group them into categories. Move around the room making sure students are not getting stuck. If they finish early push them to see if they can think about the problem in a different way.

**Prompt:** Discuss with another group. which of these algorithms are “the same” as one another?

**Discuss:** Have students discuss the prompt with another before asking them to share with the room. Lead a discussion on their experiences using tips from the discussion goal at the side.

## Wrap Up (10 mins)

**Journal:** Students add the following vocabulary words and definitions to their journals: problem, algorithm, sequencing, selection, iteration.

Discussion Goal

**Goal:** Use this discussion to reinforce vocabulary introduced in the slides and check in on whether students have begun the transition towards thinking on a higher level about algorithms and problems.

**Prompt:** How did today’s activities change the way you think about algorithms and problems?

**Discuss:** Have students think about their answers on their own, then share with a partner, and then finally discuss responses with the entire room.

Remarks

Computer scientists don't just think about "code", they think about problems and the algorithms that solve them. In this unit we're going to explore what makes two problems, or two algorithms, similar or different from one another, and the way computer scientists talk about them. Not only will you be a better programmer, but you'll get to work on some really interesting problems along the way.

### Assessment: Check For Understanding

*Check For Understanding Question(s) and solutions can be found in each lesson on Code Studio. These questions can be used for an exit ticket.*

**Question:** In your own words explain the difference between a problem and an algorithm.

## Standards Alignment

#### View full course alignment

#### CSP2021

**AAP-2** - The way statements are sequenced and combined in a program determines the computed result

**AAP-2.A** - Express an algorithm that uses sequencing without using a programming language.

**AAP-2.A.1**- An algorithm is a finite set of instructions that accomplish a specific task.**AAP-2.A.2**- Beyond visual and textual programming languages, algorithms can be expressed in a variety of ways, such as natural language, diagrams, and pseudocode.**AAP-2.A.3**- Algorithms executed by programs are implemented using programming languages.**AAP-2.A.4**- Every algorithm can be constructed using combinations of sequencing, selection, and iteration.

**AAP-2.B** - Represent a step-by-step algorithmic process using sequential code statements.

**AAP-2.B.1**- Sequencing is the application of each step of an algorithm in the order in which the code statements are given.

**AAP-2.G** - Express an algorithm that uses selection without using a programming language.

**AAP-2.G.1**- Selection determines which parts of an algorithm are executed based on a condition being true or false.

**AAP-2.I** - For nested selection: a. Represent using nested conditional statements. b. Determine the result of nested conditional statements.

**AAP-2.J.1**- Iteration is a repeating portion of an algorithm. Iteration repeats a specified number of times or until a given condition is met.

**AAP-2.L** - Compare multiple algorithms to determine if they yield the same side effect or result.

**AAP-2.L.1**- Algorithms can be written in different ways and still accomplish the same tasks.**AAP-2.L.2**- Algorithms that appear similar can yield different side effects or results.**AAP-2.L.5**- Different algorithms can be developed or used to solve the same problem.