π· WEEK 1 Lesson 5
Title: Data Structures & Algorithms (AI-Relevant Only)
Lesson Objective
By the end of this lesson, learners will:
Understand core Python data structures used in AI
Use lists, dictionaries, and sets effectively
Understand why computational efficiency matters
Build intuition for time complexity
Understand searching & sorting concepts
Develop a large-dataset engineering mindset
This lesson is about performance awareness.
1. Why Data Structures Matter in AI
AI systems handle:
Thousands
Millions
Sometimes billions of data points
Inefficient code may:
Slow training
Crash systems
Increase cloud costs
Delay production deployment
AI Engineers think about:
βHow does this scale?β
Not just:
βDoes this work?β
3. Lists β Ordered Collections
Lists are:
Ordered
Mutable
Indexed
Example:
Python
features = [1200, 3, 8, 10]
Common AI usage:
Storing feature vectors
Collecting predictions
Tracking losses during training
But caution:
Appending inside huge loops can become expensive.
Engineers monitor growth patterns.
3. Dictionaries β Fast Lookup
Dictionaries store:
Key β Value pairs
Example:
Python
student_scores = {
"Alice": 85,
"John": 90
}
Why important in AI?
Mapping IDs to features
Storing label encodings
Tracking vocabulary indices in NLP
Fast retrieval of metadata
Dictionaries allow near-instant lookup.
That matters when dataset size increases.
4. Sets β Uniqueness & Speed
Sets:
Store unique values
Provide fast membership checking
Example:
Python
unique_labels = {"spam", "ham"}
Use cases in AI:
Removing duplicates
Checking if value already exists
Efficient filtering
Membership checking in sets is much faster than lists.
This matters at scale.
5. Complexity Basics β Why Efficiency Matters
Every operation has a cost.
Engineers measure cost using:
Time Complexity (Big-O intuition)
You do not need heavy theory.
Just intuition.
Examples:
Accessing an element in a list β Fast
Searching entire list β Slower
Dictionary lookup β Very fast
Nested loops β Potentially expensive
If you loop through a million rows inside another million loop:
Thatβs dangerous.
AI engineers avoid unnecessary nested loops.
6. Searching & Sorting Intuition
Searching:
Finding a value inside data.
Naive search: Loop through entire dataset.
Efficient mindset: Use structures that allow fast lookup.
Sorting:
Arranging values in order.
Why sorting matters in AI:
Ranking predictions
Selecting top-k results
Evaluating thresholds
Organizing batches
Python has efficient built-in sorting.
Use it instead of reinventing algorithms.
7. Working With Large Datasets Mindset.
Beginner mindset: βIβll just loop over everything.β
Engineer mindset: βCan this handle 10 million rows?β
Key principles:
Avoid unnecessary loops
Prefer vectorized operations (NumPy/Pandas)
Use proper data structures
Monitor memory usage
Break tasks into batches
Efficiency is not optional in production AI.
It directly affects:
Cost
Speed
Reliability
Mini Practical Exercise
Create:
A list of 1000 numbers.
Convert it to:
A set.
Time:
Searching for a value in the list
Searching in the set
Observe the difference.
Write a short explanation:
Why would this matter in a real AI system?
Week 1 β Lesson 5 Outcome
Students now:
β Understand lists, dictionaries, sets
β Understand efficiency mindset
β Understand complexity intuition
β Understand search & sort relevance
β Think about scaling systems
β Begin writing performance-aware code
Week 1 is almost complete.
Next:
π· Lesson 6 β Git & GitHub Workflow + Mini Engineering Setup Project.
This is where we formalize professional workflow.
Powered by Soft AI Africa | Training the Next Generation of AI Leaders in Africa.