AI for comparison shopping and research in AI for Everyone - Time & Space Complexity
When AI helps with comparison shopping and research, it processes many product options to find the best deals. Understanding how the time it takes grows as more products are added helps us see how efficient the AI is.
We want to know: How does the AI's work increase when the number of products to compare grows?
Analyze the time complexity of the following AI process for comparison shopping.
products = get_all_products()
best_deal = None
for product in products:
score = evaluate_product(product)
if best_deal is None or score > best_deal_score:
best_deal = product
best_deal_score = score
return best_deal
This code looks at each product, scores it, and keeps track of the best one found.
Here, the AI checks every product one by one.
- Primary operation: Looping through each product to evaluate it.
- How many times: Once for every product in the list.
As the number of products grows, the AI spends more time checking each one.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 evaluations |
| 100 | 100 evaluations |
| 1000 | 1000 evaluations |
Pattern observation: The work grows directly with the number of products; doubling products doubles the work.
Time Complexity: O(n)
This means the AI's time to find the best deal grows in a straight line with the number of products.
[X] Wrong: "The AI only needs to check a few products to find the best deal quickly."
[OK] Correct: To be sure of the best deal, the AI must look at every product at least once; skipping products risks missing better options.
Understanding how AI scales with more data is a key skill. It shows you can think about efficiency and real-world limits, which is valuable in many tech roles.
"What if the AI used a pre-sorted list of products by price? How would the time complexity change?"