AI in everyday life (recommendations, maps, voice assistants) in AI for Everyone - Time & Space Complexity
We want to understand how the time AI systems take to give results changes as they handle more data or users.
How does the work grow when AI helps with recommendations, maps, or voice assistants?
Analyze the time complexity of the following AI task example.
function getRecommendations(userPreferences, items) {
let recommended = [];
for (let item of items) {
if (matchesPreferences(item, userPreferences)) {
recommended.push(item);
}
}
return recommended;
}
// This function filters items based on user preferences to recommend relevant ones.
This code checks each item to see if it fits what the user likes, then collects those items.
Look for repeated steps that take most time.
- Primary operation: Checking each item against user preferences.
- How many times: Once for every item in the list.
As the number of items grows, the time to check them grows too.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 checks |
| 100 | 100 checks |
| 1000 | 1000 checks |
Pattern observation: The work grows directly with the number of items. Double the items, double the checks.
Time Complexity: O(n)
This means the time to get recommendations grows in a straight line as the number of items grows.
[X] Wrong: "AI recommendations happen instantly no matter how many items there are."
[OK] Correct: The system must check each item, so more items mean more work and more time.
Understanding how AI tasks scale with data size shows you can think about real-world problems clearly and explain them simply.
"What if the AI used a pre-sorted list or index to find matches instead of checking every item? How would the time complexity change?"