World Book Logo Building Blocks

Writing Pseudocode Algorithms

This engaging, cross-curricular, two-day lesson is designed for students in grades 2-5. Students will combine their computer science knowledge of pseudocode and algorithms with their procedural writing skills to produce an algorithm for making the best peanut butter and jelly sandwich. Students will need to think efficiently like programmers while using a clear and precise writing style to create an algorithm that will hopefully give them the intended outcome: a delicious sandwich. On the second day, the teacher will actually make peanut butter and jelly sandwiches in class according to the students’ algorithms! For example, if the algorithm says, “put the peanut butter on the bread,” the teacher will literally place the jar of peanut butter on top of the loaf of bread to model just how precise programmers must be when writing code. Students will have an opportunity to practice their revision and editing skills by identifying and fixing bugs, a common coding problem.

Standards

Objectives:

Students will be able to apply what they know about sequencing to write a pseudocode algorithm for a human task: making a peanut butter and jelly sandwich.

Students will be able to apply their revising and editing skills to fix any bugs in their pseudocode algorithms, so they function as intended.

Lesson Duration:

Day 1: approximately 50-60 minutes

Day 2: approximately 55-80 minutes

Materials:

• Building Blocks of Computer Science books, specifically Algorithms, Coding Languages, Logic in Coding, and Debugging

• Writing Paper (for drafting and publishing)

• Pencils

• Optional: Colored pencils for editing

• Optional: Sequencing Graphic Organizer (1 per student)

• Optional: Sequencing Sentence Stems (1 per student)

• Ingredients for peanut butter and jelly sandwiches, such as bread, peanut butter, jelly, plates, napkins, knives, cutting board, and any other special ingredients students may call out in their pseudocode algorithms (i.e., bananas, chocolate chips, etc.)

Lesson Preparation Considerations:

If your students are allergic to any of the food used in this lesson, please swap them for other ingredients. For example, students could list the steps for making an ice cream sundae.

To prepare for Day 2, read students’ pseudocode algorithms and pull out any examples that will help you demonstrate the need for clear, precise, and efficient steps in an algorithm.

Requisite Prior Knowledge:

This two-day lesson is best used after reading the Algorithms and Debugging texts or, for extension, after reading the Coding Languages and Logic in Coding texts.

Students should know that algorithms are step-by-step instructions that produce a specific outcome. Students should be able to recognize that algorithms are not only useful in computer science, but are also used in other situations like in mathematics or when providing someone directions.

Students should have a foundational knowledge of programming bugs including syntax, token, and logic errors. In addition, they should have a general understanding of how programmers identify and fix bugs.

Because students will engage in writing and editing, it would be beneficial for them to have some peer editing experience prior to participating in this lesson. If your students have not participated in peer editing before, consider doing a mini lesson on this first.

Assessments:

Students’ first draft of their directions, collected on Day 1

Students’ edits on their first draft, collected on Day 2

Students’ final written piece, collected on Day 2

Vocabulary:

Algorithm – a set of step-by-step instructions used to write computer programs; also used to solve math problems and other problems

Bug – an error in a program’s code that keeps the program from working the way it is intended

Condition – a statement that can be true or false; a program may tell a computer to run a piece of code if a certain condition is true

Function – a set of statements that works together to accomplish a specific goal

Logic – the rules of proper reasoning

Logic error – a bug that does not stop the program from working but causes it to do the wrong thing

Loop – a piece of code that causes part of a program to run over and over again

Programming language – a set of symbols and rules that programmers use to write computer programs

Pseudocode – a description of a computer program written in human language

Statement – a command or instruction for the computer

Syntax – the rules that make up the “grammar” of a programming language

Syntax error – a bug caused by improper syntax in the code

Token error – a bug caused when code includes a word or symbol not in the programming language

Variable – a value, or piece of information, that can change

Differentiation Considerations:

For students who need more support with organizing their writing, consider providing them a copy of the Sequencing Graphic Organizer. You may also consider providing students with a copy of the Sequencing Supports to aid them in their writing process.

Consider the following extension opportunity: During the Application Activity phase of Day 2, have students identify and label the type of bugs they find when editing their writing. They can classify their bugs as syntax (S), token (T), or logic (L) errors by labeling them in a different colored pencil on their first draft. In addition, consider challenging these students to be more efficient with their code.

Challenge students who finish before their peers to write a related pseudocode algorithm for a modified type of peanut butter and jelly sandwich. For example, challenge students to describe the steps for just a peanut butter sandwich or a peanut butter and jelly sandwich with slices of bananas. Encourage students to apply what they know about variables, loops, and conditions here.

Consider pulling a small group of struggling writers to aid them in their use of the Sequencing Supports to edit their writing.

Day 1: Lesson and Instruction:

Introduction / Hook

Time Guidelines:

Approximately 10-12 minutes

Teacher Actions

Begin by activating prior knowledge with a “brain dump.” During a brain dump, students are encouraged to write anything they think or wonder about related to a particular subject on a piece of scratch paper. Here, students will have 2 minutes to brain dump everything they know or wonder about algorithms. Challenge students to write the entire time.

When time is up, have students share what they brain dumped with a neighbor before calling on a few volunteers to share out. Consider picking specific students and responses to address any misconceptions. Use the following prompts to guide your sharing and discussion:

  • • What makes an algorithm “good”?
  • • What are algorithms used for?
  • • How do algorithms work?
  • • Who creates and/or uses algorithms?

Explain to students that today they will have a chance to write their own algorithm for how to make the best peanut butter and jelly sandwich! Instead of writing this in a programming language, however, they will use pseudocode to create their algorithm. Depending on your students’ needs, consider reviewing the vocabulary terms programming language and pseudocode.

Direct Instruction and Modeling

Time Guidelines:

Approximately 15-18 minutes

Teacher Actions

Reread pages 10 and 11 of the Algorithms text and review the idea that algorithms are a series of step-by-step instructions used to complete a task or achieve a goal.

Remind students that although programmers use programming languages like Scratch and C, today they will use pseudocode to write their instructions out line by line. Discuss the benefits and drawbacks of different languages such as pseudocode, programming language, and machine language. Different languages are best for different purposes, and, for today’s goal, it is best to use pseudocode written in human language.

Reread pages 14-17 of the Algorithms text and discuss the idea of efficiency. Efficient algorithms are those that complete the task correctly in the fastest way and those that use the least of a machine’s power. Discuss with students why efficiency is important in programming. Depending on your students’ learning needs, consider discussing how one could make sure their code is as efficient as possible.

Pose the task to students: Explain that today they will write an algorithm in pseudocode for how to make the best peanut butter and jelly sandwich. They will write each step on its own line, making sure to include all the details needed while also ensuring the algorithm is efficient.

Independent Application and Demonstration of Learning

Time Guidelines:

Approximately 15-20 minutes

Teacher Actions

Provide time for students to create their pseudocode algorithm for making the best peanut butter and jelly sandwich. Keep your students’ learning needs in mind and consider options for small group support as described in the differentiation considerations section of this lesson plan.

Encourage students to talk through their steps with a peer to see if anything is missing or whether steps need to be tweaked to produce the intended outcome.

Students should complete their pseudocode algorithm for making the best peanut butter and jelly sandwich by the end of this lesson.

Closure

Time Guidelines:

Approximately 5-10 minutes

Teacher Actions

Return to the whole group setting and discuss the writing process. Consider asking questions such as:

  • • What was challenging about writing in pseudocode?
  • • What step was the simplest for you to write? Why?
  • • What step was the most exciting or fun to write? Why?
  • • Do you think any of your pseudocode contains bugs? Why or why not?

Explain to students that tomorrow we will have a chance to run our programs to see what, if any, bugs exist! Make sure to collect students’ writing before concluding this session so you can prepare for the second day of this lesson.

Next Steps and Reflection:

What went well?

What changes might be beneficial?

Reteaching Needs

Extension Needs

Introduction / Hook

Time Guidelines:

Approximately 5-10 minutes

Day 2: Lesson and Instruction:

Teacher Actions

Begin by reviewing the previous lesson’s work with pseudocode and explain that today students will have the opportunity to test their code! They will simulate debugging a program by looking for any errors and editing, or fixing, them.

Review pages 28-29 of the Debugging book and discuss self-talk phrases students can use if and when they find bugs in their pseudocode algorithms. Remind students that even the best programmers make mistakes, and those mistakes provide great opportunities to learn and improve.

Direct Instruction and Modeling

Time Guidelines:

Approximately 15-20 minutes

Teacher Actions

Use pages 12-25 of the Debugging text to review common types of programming errors:

  • • Syntax errors
  • • Token errors (a type of syntax error)
  • • Logic errors

Remind students that it is common to find bugs, or errors, in code and that good programmers develop ways to fix them so their programs run as intended.

Next, use the writing samples you prepared ahead of time to follow students’ algorithms for making the best peanut butter and jelly sandwich. Follow students’ directions exactly. Call on your rapport and relationships with students and have some fun here! If the algorithm says, “put the peanut butter on the bread,” literally place the jar of peanut butter on top of the loaf of bread. If the algorithm instructs you to “use the knife to cut the sandwich,” cut it into crazy shapes because the algorithm did not specify how the sandwich should be cut. Exaggerate a little and bring some theatrics! The goal here is twofold: 1. Students should realize that mistakes (bugs) happen frequently and should not cause bad feelings or stress and 2. Students should understand just how detailed, specific, and straightforward programmers must be when writing code. After watching you follow their algorithms, students should be motivated to fix any bugs they find within their pseudocode.

For an extension opportunity, or if your class is ready for the added rigor, see the Differentiation Consideration bullet point that encourages students to determine which type of bug (syntax, token, or logic) they identified.

Application Activity

Time Guidelines:

Approximately 15-20 minutes

Teacher Actions

Pair up students to apply the same process you modeled to their own writing. Students will read through each pseudocode line-by-line looking for and discussing potential fixes for any bugs. When explaining this portion of the task to students, draw attention to the connections between debugging a program and editing a piece of writing.

Provide students time to collaborate and edit with their peers.

Independent Application and Demonstration of Learning

Time Guidelines:

Approximately 15-20 minutes

Teacher Actions

Have students transition to the independent work setting to re-write their pseudocode algorithm with the bug fixes they discussed with their partner.

See the Differentiation Considerations section of this lesson plan for possible supports and extensions here.

Closure

Time Guidelines:

Approximately 5-10 minutes

Teacher Actions

Return to the whole group setting and discuss the process of debugging and fixing/editing their pseudocode algorithm. Consider asking questions such as:

  • • Which bugs were the easiest to identify? Why? Which were the most difficult to identify? Why?
  • • Which types of errors were most common in your work? What does this tell you to consider when writing your next algorithm?
  • • What did you learn about the debugging process?
  • • Why is it important to revise and edit our writing, not only in algorithms but also in other writing situations?

Review the objectives by explaining that students recalled prior experiences to create a pseudocode algorithm for making the best peanut butter and jelly sandwich. Students also engaged in the editing process when they “debugged” their algorithms in order to make them run smoothly.

Next Steps and Reflection:

What went well?

What changes might be beneficial?

Reteaching Needs

Extension Needs