Recycling and sustainability in EV Technology - Time & Space Complexity
We want to understand how the effort to recycle and sustain resources grows as more materials are involved.
How does the work needed change when the amount of waste increases?
Analyze the time complexity of the following process.
function recycleMaterials(materials) {
for (let i = 0; i < materials.length; i++) {
if (materials[i].isRecyclable) {
process(materials[i]);
}
}
}
function process(material) {
// Steps to clean and prepare material for reuse
}
This code checks each material in a list and processes it if recyclable.
- Primary operation: Looping through each material in the list.
- How many times: Once for each material, so as many times as the list length.
As the number of materials grows, the work grows in a similar way because each item is checked once.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | About 10 checks and possible processes |
| 100 | About 100 checks and possible processes |
| 1000 | About 1000 checks and possible processes |
Pattern observation: The work grows steadily and directly with the number of materials.
Time Complexity: O(n)
This means the effort increases in a straight line as more materials are added.
[X] Wrong: "Processing recyclable materials takes the same time no matter how many there are."
[OK] Correct: Each material must be checked and processed individually, so more materials mean more work.
Understanding how work grows with input size helps you explain real-world processes clearly and shows you can think about efficiency in everyday tasks.
"What if the process function also loops through a fixed set of cleaning steps for each material? How would the time complexity change?"