Using AI to draft emails and messages in AI for Everyone - Time & Space Complexity
When using AI to draft emails and messages, it is important to understand how the time taken grows as the input text or request size increases.
We want to know how the AI's processing time changes when we ask it to write longer or more complex messages.
Analyze the time complexity of the following AI drafting process.
function draftEmail(inputText) {
let draft = "";
for (let i = 0; i < inputText.length; i++) {
draft += generateSentence(inputText[i]);
}
return draft;
}
function generateSentence(char) {
// Simulates AI generating a sentence based on one character
return "Sentence based on " + char + ". ";
}
This code simulates AI creating an email draft by generating a sentence for each character in the input text.
- Primary operation: Looping through each character of the input text.
- How many times: Once for every character in the input text.
As the input text gets longer, the AI generates more sentences, so the time grows in direct proportion to the input size.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 sentence generations |
| 100 | 100 sentence generations |
| 1000 | 1000 sentence generations |
Pattern observation: The time grows steadily and directly with the input size.
Time Complexity: O(n)
This means the time to draft the email grows in a straight line as the input text gets longer.
[X] Wrong: "The AI drafts the whole email instantly, no matter how long the input is."
[OK] Correct: In reality, the AI processes each part of the input, so longer inputs take more time to handle.
Understanding how AI processing time grows with input size helps you explain performance considerations clearly and confidently in real-world discussions.
"What if the AI generated multiple sentences per character instead of one? How would the time complexity change?"