This lesson will probably take two days to complete. It introduces students to algorithms that process lists of data. The students will do two unplugged activities related to algorithms and program some of them themselves in App Lab. The for loop is re-introduced to implement these algorithms because it’s straightforward to use to process all the elements of a list. The lesson begins with an unplugged activity in which students write an algorithm to find the minimum value in a hand of cards. Students then move to Code Studio to write programs that use loops and arrays. Students are shown how to use a for loop to visit every element in an array. Students use this pattern to process an array in increasingly complex ways. At the end of the progression, students will write functions which process arrays to find or alter information, including finding the minimum value - a problem they worked on in the unplugged activity. Finally, an unplugged activity has students reason about linear vs. binary search and attempt to write pseudocode for a binary search.
Students will be able to:
- use a for loop in a program to implement an algorithm that processes all elements of an array.
- write code that implements a linear search on an unsorted array of numbers.
- write code to find the minimum value in an unsorted list of numbers.
- explain how binary search is more efficient than linear search but can only be used on sorted lists.
Note: You will need to create a free account on code.org before you can view this resource.