0
0
Firebasecloud~5 mins

Custom domain configuration in Firebase - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Custom domain configuration
O(n)
Understanding Time Complexity

When setting up a custom domain in Firebase Hosting, it's important to understand how the time to complete the setup grows as you add more domains.

We want to know how the number of steps or API calls changes when configuring multiple domains.

Scenario Under Consideration

Analyze the time complexity of adding multiple custom domains to Firebase Hosting.


const admin = require('firebase-admin');
const hosting = admin.hosting();

async function addCustomDomains(domains) {
  for (const domain of domains) {
    await hosting.sites().addDomain({siteId: 'my-site', domainName: domain});
  }
}
    

This code adds each custom domain one by one to a Firebase Hosting site.

Identify Repeating Operations

Look at what repeats as the input grows.

  • Primary operation: API call to add a domain to the hosting site.
  • How many times: Once per domain in the input list.
How Execution Grows With Input

Each domain requires one API call, so the total calls grow directly with the number of domains.

Input Size (n)Approx. API Calls/Operations
1010 API calls
100100 API calls
10001000 API calls

Pattern observation: The number of API calls increases one-to-one with the number of domains.

Final Time Complexity

Time Complexity: O(n)

This means the time to configure domains grows directly in proportion to how many domains you add.

Common Mistake

[X] Wrong: "Adding multiple domains happens all at once, so time stays the same no matter how many domains."

[OK] Correct: Each domain requires a separate API call and processing step, so time grows with the number of domains.

Interview Connect

Understanding how operations scale with input size helps you design efficient cloud setups and explain your reasoning clearly in interviews.

Self-Check

"What if the API allowed adding multiple domains in a single call? How would the time complexity change?"