0
0
SEO Fundamentalsknowledge~5 mins

Mapping keywords to pages in SEO Fundamentals - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Mapping keywords to pages
O(n x m)
Understanding Time Complexity

When mapping keywords to pages, it's important to understand how the effort grows as the number of keywords and pages increases.

We want to know how much work is needed to assign keywords to the right pages as the site grows.

Scenario Under Consideration

Analyze the time complexity of the following keyword-to-page mapping process.


for each keyword in keywords:
  for each page in pages:
    if page is relevant to keyword:
      assign keyword to page

This code checks every keyword against every page to find the best matches.

Identify Repeating Operations

Look at what repeats in the code.

  • Primary operation: Checking if a page is relevant to a keyword.
  • How many times: For every keyword, it checks all pages.
How Execution Grows With Input

As the number of keywords and pages grows, the number of checks grows quickly.

Input Size (keywords x pages)Approx. Operations
10 keywords x 10 pages100 checks
100 keywords x 100 pages10,000 checks
1000 keywords x 1000 pages1,000,000 checks

Pattern observation: The work grows by the product of the input sizes, meaning doubling keywords and pages quadruples the checks.

Final Time Complexity

Time Complexity: O(n x m)

This means the time needed grows proportionally to the number of keywords times the number of pages.

Common Mistake

[X] Wrong: "Checking keywords against pages only takes time proportional to the number of keywords or pages alone."

[OK] Correct: Because each keyword must be compared to every page, the total work depends on both numbers multiplied, not just one.

Interview Connect

Understanding how work grows when matching keywords to pages helps you explain how to handle large websites efficiently.

Self-Check

What if we indexed pages by keyword categories first? How would that change the time complexity?