0
0
Digital Marketingknowledge~5 mins

Data-driven budget allocation in Digital Marketing - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Data-driven budget allocation
O(n)
Understanding Time Complexity

When allocating budgets based on data, it is important to understand how the time to calculate allocations grows as the number of campaigns increases.

We want to know how the work needed changes when more campaigns or data points are involved.

Scenario Under Consideration

Analyze the time complexity of the following code snippet.


// Assume campaigns is a list of campaign data
// totalBudget is the total amount to allocate

function allocateBudget(campaigns, totalBudget) {
  let totalScore = 0;
  for (let campaign of campaigns) {
    totalScore += campaign.performanceScore;
  }
  let allocations = [];
  for (let campaign of campaigns) {
    let share = (campaign.performanceScore / totalScore) * totalBudget;
    allocations.push({campaignId: campaign.id, budget: share});
  }
  return allocations;
}
    

This code calculates the total performance score of all campaigns, then allocates the budget proportionally to each campaign based on its score.

Identify Repeating Operations

Identify the loops, recursion, array traversals that repeat.

  • Primary operation: Two separate loops over the list of campaigns.
  • How many times: Each loop runs once over all campaigns, so twice in total.
How Execution Grows With Input

As the number of campaigns increases, the time to process grows roughly in direct proportion.

Input Size (n)Approx. Operations
10About 20 operations (2 loops x 10 campaigns)
100About 200 operations
1000About 2000 operations

Pattern observation: Doubling the number of campaigns roughly doubles the work needed.

Final Time Complexity

Time Complexity: O(n)

This means the time to allocate budget grows linearly with the number of campaigns.

Common Mistake

[X] Wrong: "Because there are two loops, the time complexity is squared (O(n²))."

[OK] Correct: The loops run one after another, not nested inside each other, so their times add up, not multiply.

Interview Connect

Understanding how time grows with input size helps you explain your approach clearly and shows you can think about efficiency in real-world marketing tools.

Self-Check

"What if the budget allocation was done inside a nested loop comparing each campaign to every other campaign? How would the time complexity change?"