Bird
Raised Fist0
EV Technologyknowledge~5 mins

Recycling and sustainability in EV Technology - Time & Space Complexity

Choose your learning style10 modes available
Time Complexity: Recycling and sustainability
O(n)
Understanding Time 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?

Scenario Under Consideration

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.

Identify Repeating Operations
  • Primary operation: Looping through each material in the list.
  • How many times: Once for each material, so as many times as the list length.
How Execution Grows With Input

As the number of materials grows, the work grows in a similar way because each item is checked once.

Input Size (n)Approx. Operations
10About 10 checks and possible processes
100About 100 checks and possible processes
1000About 1000 checks and possible processes

Pattern observation: The work grows steadily and directly with the number of materials.

Final Time Complexity

Time Complexity: O(n)

This means the effort increases in a straight line as more materials are added.

Common Mistake

[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.

Interview Connect

Understanding how work grows with input size helps you explain real-world processes clearly and shows you can think about efficiency in everyday tasks.

Self-Check

"What if the process function also loops through a fixed set of cleaning steps for each material? How would the time complexity change?"

Practice

(1/5)
1. What is the main goal of recycling in sustainability?
easy
A. To turn old materials into new products
B. To increase the use of plastic
C. To create more waste
D. To use more energy

Solution

  1. Step 1: Understand recycling purpose

    Recycling means reusing old materials to make new things.
  2. Step 2: Connect recycling to sustainability

    This reduces waste and saves resources, helping the environment.
  3. Final Answer:

    To turn old materials into new products -> Option A
  4. Quick Check:

    Recycling = reuse materials [OK]
Hint: Recycling means reusing old stuff [OK]
Common Mistakes:
  • Thinking recycling creates more waste
  • Believing recycling uses more energy
  • Confusing recycling with waste creation
2. Which of the following is a correct example of a sustainable action?
easy
A. Throwing all trash into one bin
B. Leaving lights on when not needed
C. Cutting down trees without planting new ones
D. Using reusable bags instead of plastic bags

Solution

  1. Step 1: Identify sustainable actions

    Sustainable actions save resources and reduce harm to nature.
  2. Step 2: Evaluate each option

    Using reusable bags reduces plastic waste, which is sustainable.
  3. Final Answer:

    Using reusable bags instead of plastic bags -> Option D
  4. Quick Check:

    Reusable bags = sustainable choice [OK]
Hint: Choose actions that save resources [OK]
Common Mistakes:
  • Thinking all trash in one bin is sustainable
  • Believing wasting electricity is sustainable
  • Ignoring tree planting importance
3. Consider this code snippet representing waste sorting:
bins = {'plastic': 5, 'paper': 3, 'glass': 2}
recycled = {k: v*2 for k, v in bins.items() if v > 2}
print(recycled)
What will be the output?
medium
A. {'plastic': 10, 'paper': 6}
B. {'plastic': 10, 'paper': 6, 'glass': 4}
C. {'plastic': 5, 'paper': 3}
D. {'glass': 4}

Solution

  1. Step 1: Understand dictionary comprehension with condition

    Only items with value > 2 are included and values doubled.
  2. Step 2: Apply condition to bins

    'plastic' (5) and 'paper' (3) qualify; 'glass' (2) does not.
  3. Step 3: Calculate new values

    'plastic': 5*2=10, 'paper': 3*2=6
  4. Final Answer:

    {'plastic': 10, 'paper': 6} -> Option A
  5. Quick Check:

    Filter >2 and double values = {'plastic':10,'paper':6} [OK]
Hint: Filter values >2, then double [OK]
Common Mistakes:
  • Including 'glass' which has value 2
  • Not doubling the values
  • Printing original dictionary
4. This code tries to calculate total recycled items but has an error:
items = {'plastic': 4, 'paper': 6, 'glass': 3}
total = 0
for item in items:
    total += items[item]
print(totall)
What is the error?
medium
A. Using += instead of =
B. Missing colon after for loop
C. Variable name typo in print statement
D. Incorrect dictionary syntax

Solution

  1. Step 1: Check variable names used

    Variable 'total' is defined, but 'totall' is printed (typo).
  2. Step 2: Identify impact of typo

    Printing 'totall' causes a NameError because it is undefined.
  3. Final Answer:

    Variable name typo in print statement -> Option C
  4. Quick Check:

    Print typo = NameError [OK]
Hint: Check variable names carefully [OK]
Common Mistakes:
  • Ignoring typo and assuming logic error
  • Thinking dictionary syntax is wrong
  • Confusing += with =
5. A community wants to reduce waste by recycling and composting. They have 100 kg of waste: 40 kg plastic, 30 kg food scraps, 20 kg paper, and 10 kg glass. If they recycle all plastic, paper, and glass, and compost all food scraps, how much waste is diverted from landfill?
hard
A. 70 kg
B. 100 kg
C. 60 kg
D. 90 kg

Solution

  1. Step 1: Identify recyclable and compostable waste

    Plastic (40 kg), paper (20 kg), glass (10 kg) are recycled; food scraps (30 kg) are composted.
  2. Step 2: Calculate total diverted waste

    Sum recycled and composted: 40 + 20 + 10 + 30 = 100 kg.
  3. Step 3: Confirm total waste and diversion

    Total waste is 100 kg; all waste is diverted from landfill.
  4. Final Answer:

    100 kg -> Option B
  5. Quick Check:

    All waste recycled or composted = 100 kg diverted [OK]
Hint: Add all recycled + composted weights [OK]
Common Mistakes:
  • Forgetting to include composted food scraps
  • Adding only recycled waste
  • Misreading total waste amount
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