AI in healthcare and drug discovery in AI for Everyone - Time & Space Complexity
When AI helps in healthcare and drug discovery, it processes lots of data to find useful patterns.
We want to understand how the time AI takes grows as the data size increases.
Analyze the time complexity of the following AI data processing snippet.
for patient in patients_data:
for gene in patient.genes:
analyze_gene(gene)
update_model(patient)
final_results = summarize_all(patients_data)
This code looks at each patient and their genes, analyzes each gene, updates a model per patient, then summarizes all results.
Look for loops or repeated steps that take most time.
- Primary operation: The inner loop analyzing each gene for every patient.
- How many times: For each patient, it runs once for every gene they have.
As the number of patients or genes grows, the work grows too.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 patients, 100 genes each | About 1,000 gene analyses |
| 100 patients, 100 genes each | About 10,000 gene analyses |
| 1000 patients, 100 genes each | About 100,000 gene analyses |
Pattern observation: The total work grows roughly by multiplying patients and genes, so doubling patients doubles work.
Time Complexity: O(p × g)
This means the time grows in proportion to the number of patients times the number of genes per patient.
[X] Wrong: "The time only depends on the number of patients, not genes."
[OK] Correct: Each gene for every patient is analyzed, so genes add to the total work, not just patients.
Understanding how AI processing time grows helps you explain efficiency in real healthcare projects.
"What if the AI analyzed only a fixed number of genes per patient regardless of total genes? How would the time complexity change?"