Capacity planning and pricing tiers in No-Code - Time & Space Complexity
When planning capacity and pricing tiers, it's important to understand how costs and resources grow as more users or data are added.
We want to know how the effort or cost changes when the number of customers or usage increases.
Analyze the time complexity of this simple pricing calculation:
function calculatePrice(users) {
let basePrice = 10;
let totalPrice = basePrice;
if (users > 100) {
totalPrice += (users - 100) * 0.1;
}
return totalPrice;
}
This code calculates the price based on the number of users, adding extra cost for users above 100.
Look for repeated steps that grow with input size.
- Primary operation: A simple calculation based on the number of users above 100.
- How many times: The calculation happens once, no loops or repeated steps.
The calculation does not repeat for each user; it just uses the number to compute the price.
| Input Size (users) | Approx. Operations |
|---|---|
| 10 | 3 operations |
| 100 | 3 operations |
| 1000 | 3 operations |
Pattern observation: The number of operations stays the same no matter how many users there are.
Time Complexity: O(1)
This means the calculation takes the same amount of time no matter how many users you have.
[X] Wrong: "The price calculation takes longer as the number of users grows because it must check each user."
[OK] Correct: The code does not loop through users; it uses a simple math formula, so time does not increase with users.
Understanding how pricing calculations scale helps you design systems that stay efficient as they grow, a key skill in many roles.
What if the pricing calculation included a loop that applied discounts to each user individually? How would the time complexity change?