Day 5 - Algorithm Design and Testing

Day 5: Algorithm Design and Testing

Learning Objectives

Essential Questions

Materials Needed

Vocabulary

Procedure (50 minutes)

Opening (8 minutes)

  1. Review and Connection (3 minutes)

    • Review string operations from previous lesson
    • Connect to today's focus on algorithm design and testing
  2. Warm-up Activity (5 minutes)

    • Present a simple problem (e.g., finding the maximum of three numbers)
    • Ask students to brainstorm different approaches to solve it
    • Discuss how we might verify that a solution is correct

Main Activities (32 minutes)

  1. Lecture: Algorithm Design Principles and Testing Strategies (12 minutes)

    • Explain key principles of algorithm design:
      • Understanding the problem requirements
      • Breaking down complex problems into steps
      • Identifying inputs and outputs
      • Considering different approaches
      • Choosing appropriate operations and structures
    • Introduce testing strategies:
      • Test cases with normal inputs
      • Edge cases and boundary conditions
      • Invalid inputs
      • Comprehensive testing
    • Discuss the importance of testing in algorithm development
    • Explain how testing helps identify errors and edge cases
    • Introduce the concept of algorithm correctness and verification
  2. Demo: Testing Algorithms with Different Inputs (8 minutes)

    • Show an algorithm for a specific task (e.g., calculating the average of a list of numbers)
    • Demonstrate how to test the algorithm with different inputs:
      • Normal case (several numbers)
      • Edge case (empty list)
      • Edge case (single number)
      • Edge case (very large numbers)
      • Invalid input (non-numeric values)
    • Show how testing reveals potential issues in the algorithm
    • Demonstrate how to refine the algorithm based on test results
  3. Activity: Design, Implement, and Test Algorithms (12 minutes)

    • Students work individually or in pairs
    • Assign mathematical operations for students to implement (e.g., calculating factorial, finding GCD, determining if a number is prime)
    • Students should:
      • Design an algorithm for their assigned operation
      • Implement the algorithm in code
      • Develop a set of test cases, including edge cases
      • Test their algorithm with these cases
      • Refine their algorithm based on test results
    • Circulate to provide guidance and feedback

Closing (10 minutes)

  1. Discussion: Importance of Testing Edge Cases (5 minutes)

    • Have students share their algorithms and testing strategies
    • Discuss common issues discovered during testing
    • Emphasize the importance of considering edge cases
    • Highlight how testing improves algorithm quality
    • Discuss real-world consequences of inadequate testing
  2. Exit Ticket and Preview (5 minutes)

    • Students design and test an algorithm that solves a specific problem
    • Preview that next class will focus on selection (conditionals)

Assessment

Differentiation

For Advanced Students

For Struggling Students

Homework/Extension

Teacher Notes