Identifying tasks where AI adds value in AI for Everyone - Time & Space Complexity
We want to understand how the effort to identify tasks where AI adds value changes as we look at more tasks.
How does the work grow when the number of tasks increases?
Analyze the time complexity of the following code snippet.
function findAITasks(tasks) {
let valuableTasks = [];
for (let task of tasks) {
if (task.isRepetitive && task.hasClearRules) {
valuableTasks.push(task);
}
}
return valuableTasks;
}
This code checks each task to see if AI can add value by looking for repetitive tasks with clear rules.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Looping through each task once.
- How many times: Once for every task in the list.
As the number of tasks grows, the work grows at the same rate because each task is checked once.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 checks |
| 100 | 100 checks |
| 1000 | 1000 checks |
Pattern observation: The work grows directly with the number of tasks.
Time Complexity: O(n)
This means the time to identify valuable AI tasks grows in direct proportion to how many tasks there are.
[X] Wrong: "Checking one task means the whole process is instant no matter how many tasks there are."
[OK] Correct: Each task must be checked individually, so more tasks mean more work.
Understanding how work grows with input size helps you explain your approach clearly and shows you think about efficiency in real situations.
"What if we added a nested check inside the loop that looks at every subtask for each task? How would the time complexity change?"