Common prompting mistakes to avoid in AI for Everyone - Time & Space Complexity
When working with AI prompts, it is important to understand how the complexity of your prompt affects the AI's processing time.
We want to know how the AI's work grows as prompts get longer or more complicated.
Analyze the time complexity of the following prompting approach.
prompt = "Tell me about cats."
response = AI.generate(prompt)
prompt = "Tell me about cats and dogs."
response = AI.generate(prompt)
prompt = "Tell me about cats, dogs, and birds."
response = AI.generate(prompt)
This code sends prompts of increasing length to the AI and gets responses.
Look for repeated actions that affect time.
- Primary operation: Sending the prompt to the AI and waiting for a response.
- How many times: Once per prompt, but prompt length grows.
As the prompt gets longer, the AI takes more time to process it.
| Input Size (words in prompt) | Approx. Operations |
|---|---|
| 3 | Small amount of processing |
| 6 | About twice the processing |
| 9 | About three times the processing |
Pattern observation: Processing time grows roughly in direct proportion to prompt length.
Time Complexity: O(n)
This means the AI's work grows linearly as the prompt gets longer.
[X] Wrong: "Adding more details to the prompt won't affect how long the AI takes to respond."
[OK] Correct: The AI reads and processes the entire prompt, so longer prompts take more time and resources.
Understanding how prompt length affects AI processing helps you design clear and efficient prompts, a useful skill when working with AI tools in real projects.
"What if we split a long prompt into several shorter prompts? How would that change the time complexity?"