Bird
Raised Fist0
Digital Marketingknowledge~5 mins

Referral program mechanics in Digital Marketing - Time & Space Complexity

Choose your learning style10 modes available
Time Complexity: Referral program mechanics
O(n)
Understanding Time Complexity

When running a referral program, it's important to understand how the effort or cost grows as more users join and refer others.

We want to know how the number of operations changes as the number of participants increases.

Scenario Under Consideration

Analyze the time complexity of the following referral program process.


// For each new user:
for each user in new_users:
    send_invite(user)
    for each referral in user.referrals:
        reward_user(referral)
        notify_user(referral)
    update_program_stats()
    

This code sends invites to new users, rewards and notifies their referrals, and updates stats.

Identify Repeating Operations

Look at the loops and repeated actions:

  • Primary operation: Looping through each new user and then through each referral they bring.
  • How many times: The outer loop runs once per new user; the inner loop runs once per referral of that user.
How Execution Grows With Input

As the number of new users and their referrals grow, the total work grows too.

Input Size (n)Approx. Operations
10 users with 2 referrals eachAbout 30 operations (10 invites + 20 rewards/notifications)
100 users with 2 referrals eachAbout 300 operations
1000 users with 2 referrals eachAbout 3000 operations

Pattern observation: The total operations increase roughly in direct proportion to the number of users and their referrals.

Final Time Complexity

Time Complexity: O(n)

This means the work grows linearly with the number of users and their referrals combined.

Common Mistake

[X] Wrong: "The program runs in constant time because each user is handled separately."

[OK] Correct: Even though users are handled one by one, the total work depends on how many users and referrals there are, so it grows as more join.

Interview Connect

Understanding how referral program operations grow helps you design scalable marketing strategies and shows you can think about efficiency in real-world systems.

Self-Check

"What if each user could have a varying number of referrals instead of a fixed number? How would the time complexity change?"

Practice

(1/5)
1. What is the main purpose of a referral program in digital marketing?
easy
A. To limit the number of customers
B. To increase the price of products
C. To encourage existing customers to bring in new customers
D. To reduce the quality of services

Solution

  1. Step 1: Understand referral program goal

    Referral programs aim to grow customer base by using existing customers as promoters.
  2. Step 2: Identify correct purpose

    The main goal is to encourage current customers to invite others, increasing new customers.
  3. Final Answer:

    To encourage existing customers to bring in new customers -> Option C
  4. Quick Check:

    Referral programs = customer growth [OK]
Hint: Referral programs reward sharing to grow customers fast [OK]
Common Mistakes:
  • Thinking referral programs increase prices
  • Believing referral programs reduce service quality
  • Assuming referral programs limit customers
2. Which of the following is a common reward given in referral programs?
easy
A. Free product or discount
B. Increased subscription fees
C. Delayed delivery times
D. Reduced customer support

Solution

  1. Step 1: Identify typical referral rewards

    Referral programs usually offer incentives like discounts or free products to motivate sharing.
  2. Step 2: Match reward type

    Free products or discounts are positive rewards, unlike fees or delays which discourage customers.
  3. Final Answer:

    Free product or discount -> Option A
  4. Quick Check:

    Referral rewards = discounts or freebies [OK]
Hint: Rewards are positive incentives like discounts, not penalties [OK]
Common Mistakes:
  • Confusing rewards with penalties
  • Thinking referral rewards increase costs
  • Assuming rewards reduce service quality
3. Consider this referral program rule: "For every 3 friends referred, the referrer gets a $10 credit." If a customer refers 7 friends, how much credit do they earn?
medium
A. $10
B. $30
C. $70
D. $20

Solution

  1. Step 1: Calculate full groups of 3 referrals

    7 friends referred means 2 full groups of 3 (since 3*2=6), with 1 leftover.
  2. Step 2: Multiply groups by credit

    2 groups x $10 credit = $20 total credit earned.
  3. Final Answer:

    $20 -> Option D
  4. Quick Check:

    Floor(7/3) x 10 = 20 [OK]
Hint: Divide referrals by 3, multiply by $10 credit [OK]
Common Mistakes:
  • Multiplying total referrals by $10 directly
  • Ignoring leftover referrals
  • Adding credit for incomplete groups
4. A referral program states: "Referrer and referee both get a 15% discount." A user tries to apply the discount twice on the same purchase and it fails. What is the likely issue?
medium
A. The program only allows one discount per purchase
B. The discount percentage is too high
C. The referee is not eligible for any discount
D. The referrer must pay extra fees

Solution

  1. Step 1: Understand discount application rules

    Most referral programs limit discounts to one per purchase to avoid stacking.
  2. Step 2: Identify why applying twice fails

    Trying to apply the same discount twice likely violates the one-discount-per-purchase rule.
  3. Final Answer:

    The program only allows one discount per purchase -> Option A
  4. Quick Check:

    One discount per purchase rule = failure on double apply [OK]
Hint: Check if multiple discounts are allowed per purchase [OK]
Common Mistakes:
  • Assuming referee gets no discount
  • Thinking discount percentage causes failure
  • Believing referrer pays extra fees
5. A company wants to design a referral program where the referrer earns $5 for each new customer, but only if the new customer spends at least $50. Which of these is the best way to ensure fairness and success?
hard
A. Give $5 to referrers immediately after referral regardless of purchase
B. Track new customer purchases and only reward referrers when spending meets $50
C. Reward referrers only after 10 referrals, ignoring purchase amounts
D. Offer rewards only to new customers, not referrers

Solution

  1. Step 1: Understand program goal

    The company wants to reward referrers only if new customers spend $50 or more.
  2. Step 2: Choose method ensuring fairness

    Tracking purchases and rewarding only when spending meets $50 ensures fairness and avoids wasted rewards.
  3. Final Answer:

    Track new customer purchases and only reward referrers when spending meets $50 -> Option B
  4. Quick Check:

    Purchase tracking ensures fair rewards [OK]
Hint: Reward only after verifying new customer spends $50+ [OK]
Common Mistakes:
  • Rewarding referrers without purchase verification
  • Ignoring purchase amount conditions
  • Rewarding only new customers, not referrers
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard