AI for exam preparation and practice questions in AI for Everyone - Time & Space Complexity
When AI generates exam practice questions, it processes input data to create useful outputs. Understanding time complexity helps us see how the AI's work grows as the number of questions or topics increases.
We want to know how the AI's processing time changes when it handles more exam topics or questions.
Analyze the time complexity of the following AI process for generating practice questions.
function generatePracticeQuestions(topics) {
let questions = [];
for (let topic of topics) {
let generated = aiGenerateQuestions(topic);
questions.push(...generated);
}
return questions;
}
// aiGenerateQuestions creates a list of questions for one topic
This code loops through each exam topic and uses AI to create practice questions for that topic, collecting all questions together.
- Primary operation: Looping through each topic and generating questions for it.
- How many times: Once for each topic in the input list.
As the number of topics increases, the AI generates questions for each one, so the total work grows steadily with the number of topics.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 topics | 10 question generations |
| 100 topics | 100 question generations |
| 1000 topics | 1000 question generations |
Pattern observation: The work grows directly in proportion to the number of topics.
Time Complexity: O(n)
This means the time to generate questions grows in a straight line as the number of topics increases.
[X] Wrong: "Generating questions for multiple topics takes the same time as for one topic because AI is fast."
[OK] Correct: Even if AI is fast, it still needs to process each topic separately, so more topics mean more total work and time.
Understanding how AI processing time grows with input size shows you can think about efficiency in real-world AI applications, a useful skill for many tech roles.
What if the AI generated a fixed number of questions regardless of topic count? How would the time complexity change?