0
0
Digital Marketingknowledge~5 mins

Building an email list in Digital Marketing - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Building an email list
O(n × m)
Understanding Time Complexity

When building an email list, it's important to understand how the time needed grows as you add more contacts.

We want to know how the effort or steps increase when the list gets bigger.

Scenario Under Consideration

Analyze the time complexity of the following process to add new emails to a list.


// Pseudocode for adding emails to a list
for each email in newEmails:
  if email not in existingList:
    add email to existingList

This code checks each new email and adds it only if it is not already in the list.

Identify Repeating Operations

Identify the loops, recursion, array traversals that repeat.

  • Primary operation: Checking if each new email is already in the existing list.
  • How many times: Once for each new email, and for each check, it may scan the existing list.
How Execution Grows With Input

As the number of new emails grows, the time to check each one grows too, especially if the existing list is large.

Input Size (n)Approx. Operations
10About 100 checks (10 new emails x 10 existing emails)
100About 10,000 checks (100 new emails x 100 existing emails)
1000About 1,000,000 checks (1000 new emails x 1000 existing emails)

Pattern observation: The number of checks grows much faster than the number of new emails because each new email is compared against all existing ones.

Final Time Complexity

Time Complexity: O(n × m)

This means the time grows roughly by multiplying the number of new emails (n) by the size of the existing list (m).

Common Mistake

[X] Wrong: "Adding emails one by one always takes the same time no matter how big the list is."

[OK] Correct: Each new email must be checked against the whole existing list, so as the list grows, the checking takes more time.

Interview Connect

Understanding how adding items to a list scales helps you design better marketing tools and shows you can think about efficiency in real projects.

Self-Check

"What if we used a special data structure that lets us check if an email exists instantly? How would the time complexity change?"