State of Health (SOH) monitoring in EV Technology - Time & Space Complexity
We want to understand how the time to check the battery's health grows as we get more data.
How does the monitoring process scale when the amount of battery data increases?
Analyze the time complexity of the following code snippet.
function calculateSOH(batteryData) {
let totalCapacity = 0;
for (let i = 0; i < batteryData.length; i++) {
totalCapacity += batteryData[i].capacity;
}
return totalCapacity / batteryData.length;
}
This code calculates the average capacity from a list of battery data points to estimate the State of Health.
- Primary operation: Looping through each battery data point once.
- How many times: Exactly once for each data point in the list.
As the number of battery data points grows, the time to calculate SOH grows proportionally.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 additions |
| 100 | 100 additions |
| 1000 | 1000 additions |
Pattern observation: Doubling the data doubles the work needed.
Time Complexity: O(n)
This means the time to calculate SOH grows in direct proportion to the number of data points.
[X] Wrong: "Calculating SOH takes the same time no matter how many data points there are."
[OK] Correct: The code must look at each data point once, so more data means more time.
Understanding how your monitoring scales helps you design systems that stay fast as data grows.
"What if we stored a running total and updated SOH incrementally instead of recalculating from all data each time? How would the time complexity change?"
Practice
Solution
Step 1: Understand SOH definition
SOH measures how much battery capacity remains compared to its original capacity.Step 2: Differentiate from other metrics
Speed, temperature, and distance are unrelated to SOH's main purpose.Final Answer:
The remaining battery capacity compared to when it was new -> Option BQuick Check:
SOH = Remaining capacity % [OK]
- Confusing SOH with vehicle speed
- Mixing SOH with battery temperature
- Thinking SOH measures distance traveled
Solution
Step 1: Calculate SOH as a percentage
SOH is the ratio of current to original capacity multiplied by 100 to get a percentage.Step 2: Check formula correctness
Only soh = (battery_capacity / original_capacity) * 100 correctly multiplies the ratio by 100 to express percentage.Final Answer:
soh = (battery_capacity / original_capacity) * 100 -> Option AQuick Check:
Percentage = ratio * 100 [OK]
- Forgetting to multiply by 100
- Using subtraction instead of division
- Adding capacities instead of dividing
original_capacity = 100
battery_capacity = 85
soh = (battery_capacity / original_capacity) * 100
print(f"SOH: {soh:.1f}%")Solution
Step 1: Calculate SOH value
85 divided by 100 equals 0.85, multiplied by 100 equals 85.0.Step 2: Format output string
The print statement formats SOH to one decimal place, showing '85.0%'.Final Answer:
SOH: 85.0% -> Option AQuick Check:
0.85 * 100 = 85.0 [OK]
- Misreading decimal as percent
- Adding capacities instead of dividing
- Ignoring formatting precision
original_capacity = 100
battery_capacity = 90
soh = battery_capacity / original_capacity * 100
print("SOH is " + soh + "%")Solution
Step 1: Analyze SOH calculation
The formula is correct; division and multiplication order is fine without extra parentheses.Step 2: Check print statement
Concatenating string and float without conversion causes a TypeError.Final Answer:
Type error when concatenating string and float -> Option DQuick Check:
Convert float to string before concatenation [OK]
- Assuming formula is wrong
- Ignoring type conversion in print
- Thinking print syntax is incorrect
soh = 65
if soh < 70:
print("Alert: Battery SOH is low!")
else:
print("Battery SOH is healthy.")Solution
Step 1: Understand the condition
The if statement checks if SOH is less than 70, which is true for 65.Step 2: Verify output behavior
Since 65 < 70, it prints the alert message correctly.Final Answer:
The code correctly alerts when SOH is below 70% -> Option CQuick Check:
soh < 70 triggers alert [OK]
- Using <= instead of < causing off-by-one
- Confusing alert condition direction
- Assuming syntax error due to < symbol
Ready to prove it?
Pass the test and this pattern moves unknown
