Quality Score and ad rank in Digital Marketing - Time & Space Complexity
When managing ads, it is important to understand how the time to calculate Quality Score and ad rank changes as you add more ads or keywords.
We want to know how the work grows when the number of ads increases.
Analyze the time complexity of the following process.
for each ad in campaign:
calculate expected click-through rate (CTR)
check ad relevance
check landing page experience
compute Quality Score
calculate ad rank using Quality Score and bid
display ad position
This code calculates Quality Score and ad rank for each ad in a campaign to decide its position.
Look for repeated steps that take most time.
- Primary operation: Looping through each ad to calculate Quality Score and ad rank.
- How many times: Once for every ad in the campaign.
As the number of ads grows, the total work grows too.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 calculations |
| 100 | 100 calculations |
| 1000 | 1000 calculations |
Pattern observation: The work grows directly with the number of ads. Double the ads, double the work.
Time Complexity: O(n)
This means the time to calculate Quality Score and ad rank grows in a straight line as you add more ads.
[X] Wrong: "Calculating Quality Score for many ads takes the same time as for one ad."
[OK] Correct: Each ad needs its own calculation, so more ads mean more work and more time.
Understanding how work grows with more ads helps you explain efficiency and scaling in real marketing systems.
"What if the Quality Score calculation also checked competitor ads for each ad? How would the time complexity change?"