Tracking keyword rankings in SEO Fundamentals - Time & Space Complexity
When tracking keyword rankings, it's important to understand how the time needed grows as you check more keywords or websites.
We want to know how the work increases when the number of keywords or pages grows.
Analyze the time complexity of the following code snippet.
// Pseudocode for tracking keyword rankings
for each keyword in keywordList:
for each website in websiteList:
check ranking position of keyword on website
store result
This code checks the ranking position of each keyword on every website and saves the results.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Checking the ranking position for each keyword on each website.
- How many times: The inner check runs once for every keyword and every website, so total checks equal keywords multiplied by websites.
As you add more keywords or websites, the total checks grow by multiplying these numbers.
| Input Size (keywords x websites) | Approx. Operations |
|---|---|
| 10 x 5 | 50 checks |
| 100 x 5 | 500 checks |
| 100 x 100 | 10,000 checks |
Pattern observation: Doubling either keywords or websites doubles the total work, so the growth is proportional to both.
Time Complexity: O(n * m)
This means the time needed grows proportionally to the number of keywords times the number of websites checked.
[X] Wrong: "Checking more keywords only adds a little extra time because each check is fast."
[OK] Correct: Each keyword must be checked on every website, so adding keywords multiplies the total checks, increasing time significantly.
Understanding how time grows when tracking keyword rankings helps you explain how your tools scale and handle more data efficiently.
"What if we only tracked rankings for a fixed number of websites but increased keywords greatly? How would the time complexity change?"