Warm Up (5 minutes)
Activity (35 minutes)
Activity 2 (30 minutes)
Wrap Up (10 minutes)
Understanding the lines of code activity sheet
Key Take-Aways:
We use a for loop to traverse a list, visiting each element one at a time.
Each pass through the loop, the counting variable changes - usually by one. We can access each element by evaluating list[i] in the for loop.
Once we know the element at each spot in a list, we can do different things with it:
Filter (create a subset of elements from the original list)
Reduce (reduce the list down to a single element, for example: the smallest number in the list)
Traversal: the process of accessing each item in a list one at a time
List - an ordered sequence of elements.
Element - an individual value in a list that is assigned a unique index.
Index - a common method for referencing the elements in a list or string using natural numbers.
Iteration - a repetitive portion of an algorithm. Iteration repeats until a given condition is met.
The lesson begins with a quick review of lists and loops before moving into the main activity. Here students explore the concept with the Traversal Machine, a physical model of traversal using a for loop.
In the investigate students work with partners to investigate three different apps that use traversal to access items in a lists. Students first explore all three apps without seeing the code to notice similarities and predict how they will work. Then they explore the code itself and make additions and modifications to the apps. To conclude the lesson, students review and discuss common programming patterns with traversals.
Students are introduced to the concept of traversal using the Traversal Machine. This unplugged lessons provides students a physical mental model they will be able to use when they transition to programming traversals in App Lab.
In the investigage after building a conceptual model using a for loop to traverse a list in the previous lesson, this lesson allows students to see how this is actually implemented in code. This lesson also introduces common programming patterns when using lists and traverals. Students will have some opportunities to modify working code in this lesson, but the most significant practice with lists and traversals will come in the following lesson.
CSP Conceptual Framework
AAP-2 - The way statements are sequenced and combined in a program determines the computed result. Programs incorporate iteration and selection constructs to represent repetition and make decisions to handle varied input values.
AAP-2.O - For algorithms involving elements of a list: a. Represent using iterative statements to traverse a list. b. Determine the result of an algorithm with list traversals.
AAP-2.O.1 - Traversing a list can be a complete traversal, where all elements in the list are accessed, or a partial traversal, where only a portion of elements are accessed. EXCLUSION STATEMENT (EK AAP-2.O.1): Traversing multiple lists at the same time using the same index for both (parallel traversals) is outside the scope of this course and the AP Exam.
AAP-2.O.2 - Iteration statements can be used to traverse a list.
AAP-2.O.4 - Knowledge of existing algorithms that use iteration can help in constructing new algorithms. Some examples of existing algorithms that are often used with lists include:● determining a minimum or maximum value in a list● computing a sum or average of a list of numbers
AAP-3 - Programmers break down problems into smaller and more manageable pieces. By creating procedures and leveraging parameters, programmers generalize processes that can be reused. Procedures allow programmers to draw upon existing code that has already been tested, allowing programmers to write programs more quickly and with more confidence.
AAP-3.F - For simulations: a. Explain how computers can be used to represent real-world phenomena or outcomes. b. Compare the use of simulations with real-world contexts.
AAP-3.F.1 - Simulations are abstractions of more complex objects or phenomena for a specific purpose.
AAP-3.F.2 - A simulation is a representation that uses varying sets of values to reflect the changing state of a phenomenon.
AAP-3.F.3 - Simulations often mimic real-world events with the purpose of drawing inferences, allowing investigation of a phenomenon without the constraints of the real world.
AAP-3.F.4 - The process of developing an abstract simulation involves removing specific details or simplifying functionality.
AAP-3.F.5 - Simulations can contain bias derived from the choices of real-world elements that were included or excluded.
AAP-3.F.6 - Simulations are most useful when real-world events are impractical for experiments (e.g., too big, too small, too fast, too slow, too expensive, or too dangerous).
AAP-3.F.7 - Simulations facilitate the formulation and refinement of hypotheses related to the objects or phenomena under consideration.
DAT-2 - Programs can be used to process data, which allows users to discover information and create new knowledge.
DAT-2.D - Extract information from data using a program.
DAT-2.D.6 - Some processes that can be used to extract or modify information from data include the following:
transforming every element of a data set, such as doubling every element in a list, or extracting the parent’s email from every student record
filtering a data set, such as keeping only the positive numbers from a list, or keeping only students who signed up for band from a record of all the students
combining or comparing data in some way, such as adding up a list of numbers, or finding the student who has the highest GPA
visualizing a data set through a chart, graph, or other visual representation
CSTA K-12 Computer Science Standards (2017)
AP - Algorithms & Programming
3A-AP-14 - Use lists to simplify solutions, generalizing computational problems instead of repeated use of simple variables.
3B-AP-10 - Use and adapt classic algorithms to solve computational problems.
3B-AP-23 - Evaluate key qualities of a program through a process such as a code review.