Day 18 - Traversing Lists

Day 18: Traversing Lists

Learning Objectives

Essential Questions

Materials Needed

Vocabulary

Procedure (50 minutes)

Opening (8 minutes)

  1. Review and Connection (3 minutes)

    • Review list operations from previous lesson
    • Connect to today's focus on systematically processing list elements
  2. Warm-up Activity (5 minutes)

    • Present a list and a task requiring processing each element
    • Ask students to write pseudocode for processing the entire list
    • Discuss different approaches to visiting each element

Main Activities (32 minutes)

  1. Lecture: Traversing Lists with Loops (12 minutes)

    • Define list traversal as visiting each element in a list
    • Explain types of traversals:
      • Complete traversal: accessing all elements
      • Partial traversal: accessing only some elements
    • Introduce traversal methods:
      • Index-based traversal using REPEAT n TIMES
      • Element-based traversal using FOR EACH
    • Explain the FOR EACH loop syntax:
      • FOR EACH item IN aList
      • How the variable item takes on each value in the list
      • Order of traversal (first to last element)
    • Discuss common traversal patterns:
      • Processing each element
      • Transforming elements
      • Filtering elements
      • Searching for elements
    • Explain linear/sequential search algorithm:
      • Checking each element in order
      • Stopping when the desired value is found or all elements are checked
      • Efficiency considerations
  2. Demo: Different Traversal Patterns (8 minutes)

    • Walk through examples of list traversals:
      • Using FOR EACH to process every element
      • Using index-based loops for more control
      • Implementing linear search
      • Transforming list elements
      • Filtering elements based on conditions
    • Demonstrate when to use each traversal approach
    • Show how to combine traversal with other operations
    • Highlight common patterns and techniques
    • Discuss potential errors and edge cases
  3. Hands-on: Writing List Traversal Code (12 minutes)

    • Students work in the programming environment
    • Guide students through implementing different traversal patterns
    • Have students create programs that:
      • Process all elements in a list using FOR EACH
      • Implement linear search for a value
      • Transform list elements (e.g., doubling all numbers)
      • Filter elements based on conditions
      • Count elements meeting certain criteria
    • Encourage students to test their traversals with different inputs
    • Challenge students to handle edge cases (empty lists, not found, etc.)

Closing (10 minutes)

  1. Activity: Processing Data in Lists (5 minutes)

    • Provide students with a real-world dataset as a list
    • Students write code to analyze the data using list traversal
    • Tasks might include:
      • Finding patterns in the data
      • Calculating statistics
      • Identifying outliers
      • Transforming the data
    • Share and discuss different approaches
    • Highlight effective traversal techniques
  2. Exit Ticket and Preview (5 minutes)

    • Students create a program that traverses and processes list data
    • Preview that next class will focus on 2D lists and nested loops

Assessment

Differentiation

For Advanced Students

For Struggling Students

Homework/Extension

Teacher Notes