Using AI for health information (with caution) in AI for Everyone - Time & Space Complexity
When using AI to get health information, it is important to understand how the time it takes to get answers grows as the questions or data get bigger or more complex.
We want to know how the AI's response time changes when we ask more or harder health questions.
Analyze the time complexity of the following AI health information query process.
function getHealthInfo(questions) {
let answers = [];
for (let q of questions) {
let answer = aiModel.query(q); // AI processes each question
answers.push(answer);
}
return answers;
}
This code sends each health question to the AI model one by one and collects the answers.
Look for repeated steps that take time.
- Primary operation: Sending each question to the AI model for processing.
- How many times: Once for each question in the list.
As the number of questions grows, the total time grows roughly in the same way.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 AI queries |
| 100 | 100 AI queries |
| 1000 | 1000 AI queries |
Pattern observation: The time grows directly with the number of questions; double the questions, double the time.
Time Complexity: O(n)
This means the time to get answers grows in a straight line with the number of questions asked.
[X] Wrong: "The AI answers all questions instantly no matter how many there are."
[OK] Correct: Each question takes some time to process, so more questions mean more total time.
Understanding how AI response time grows with input size helps you explain system behavior clearly and shows you can think about performance in real-world AI applications.
"What if the AI could answer multiple questions at once? How would that change the time complexity?"