Day 20 - Other Collection Types
Day 20: Other Collection Types
Learning Objectives
- AAP-1.C: Represent a list or string using a variable.
- AAP-1.D: For data abstraction: Develop data abstraction using lists to store multiple elements.
Essential Questions
- What other data structures can we use to organize and store collections of data?
- How do we choose the appropriate collection type for different problems?
Materials Needed
- Presentation slides on collection types
- Programming environment
- Collection type comparison worksheet
- Problem scenarios for different collection types
- Exit ticket templates
Vocabulary
- Collection
- Dictionary
- Key-value pair
- Set
- Hash table
- Map
- Associative array
- Data structure
- Lookup
Procedure (50 minutes)
Opening (8 minutes)
-
Review and Connection (3 minutes)
- Review 2D lists and nested loops from previous lesson
- Connect to today's focus on other ways to organize collections of data
-
Warm-up Activity (5 minutes)
- Present a problem that's awkward to solve with lists (e.g., storing student grades by name)
- Ask students how they might approach this with what they know so far
- Discuss limitations of lists for certain types of data organization
Main Activities (32 minutes)
-
Lecture: Other Collection Types (12 minutes)
- Introduce dictionaries/maps as key-value collections:
- Structure: mapping keys to values
- Purpose: fast lookup by key
- Common uses: name-value associations, property lists
- Operations: creating, accessing by key, modifying, checking existence
- Introduce sets as unordered collections of unique elements:
- Structure: collection with no duplicates
- Purpose: membership testing, eliminating duplicates
- Common uses: unique items, set operations
- Operations: adding, removing, checking membership
- Compare different collection types:
- Lists: ordered collections, access by position
- Dictionaries: key-value pairs, access by key
- Sets: unique elements, membership testing
- Discuss when to use each collection type:
- Lists: when order matters, when duplicates are allowed
- Dictionaries: when you need to look up values by a key
- Sets: when you only care about membership, not order or count
- Explain how these collections provide data abstraction
- Introduce dictionaries/maps as key-value collections:
-
Demo: Using Different Collection Types (8 minutes)
- Walk through examples of different collection types:
- Creating and using dictionaries for name-value associations
- Using sets for membership testing and duplicate elimination
- Converting between collection types
- Demonstrate solving problems with appropriate collections:
- Student grade tracker using dictionaries
- Unique visitor tracker using sets
- Frequency counter using dictionaries
- Show how to choose the right collection for different scenarios
- Highlight the advantages of each collection type
- Walk through examples of different collection types:
-
Hands-on: Choosing Appropriate Collections for Different Problems (12 minutes)
- Students work in the programming environment
- Present several problem scenarios
- Students determine which collection type is most appropriate for each
- Have students implement solutions using the chosen collection types
- Problem ideas:
- Word frequency counter
- Contact list manager
- Inventory system
- Unique item tracker
- Encourage students to explain their choice of collection type
Closing (10 minutes)
-
Activity: Converting Between Collection Types (5 minutes)
- Provide students with data in one collection format
- Students convert it to another format to solve a specific problem
- Examples:
- Converting a list to a set to find unique elements
- Converting a list to a dictionary for faster lookup
- Creating a frequency dictionary from a list
- Share and discuss different approaches
- Highlight the strengths of each collection type
-
Exit Ticket and Preview (5 minutes)
- Students create a program that uses appropriate collection types
- Preview that next class will focus on algorithm efficiency
Assessment
- Formative: Quality of collection type selection and implementation
- Exit Ticket: Appropriateness of collection type choices in the program
Differentiation
For Advanced Students
- Challenge them with more complex problems requiring multiple collection types
- Introduce more specialized collection types (priority queues, etc.)
- Have them implement custom collection behaviors
For Struggling Students
- Provide clearer guidelines for when to use each collection type
- Focus on one new collection type at a time
- Use visual aids to illustrate different collection structures
Homework/Extension
- Complete a worksheet comparing collection types
- Create a program that uses multiple collection types appropriately
- Research how collection types are implemented in different languages
Teacher Notes
- Emphasize that choosing the right data structure is a key programming skill
- Watch for confusion about when to use each collection type
- Make connections to real-world scenarios requiring different organizations
- Consider using physical analogies (dictionary = phone book, set = stamp collection)
- Remind students that the AP exam may ask about appropriate data structures
- This concludes Week 4 of the unit