Why drones solve real industry problems in Drone Programming - Performance Analysis
We want to see how the time a drone program takes grows as it handles more tasks.
How does adding more work affect the drone's operation time?
Analyze the time complexity of the following code snippet.
function inspectFields(fields) {
for (let i = 0; i < fields.length; i++) {
flyTo(fields[i].location);
scanCrop(fields[i]);
}
}
This code makes the drone visit each field and scan the crops there.
Look for repeated actions in the code.
- Primary operation: The loop that visits and scans each field.
- How many times: Once for every field in the list.
As the number of fields grows, the drone must do more visits and scans.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 visits and scans |
| 100 | 100 visits and scans |
| 1000 | 1000 visits and scans |
Pattern observation: The work grows directly with the number of fields.
Time Complexity: O(n)
This means the time grows in a straight line as more fields are added.
[X] Wrong: "The drone can scan all fields instantly, so time does not increase with more fields."
[OK] Correct: Each field requires a separate visit and scan, so more fields always mean more time.
Understanding how work grows with input helps you explain how drones handle bigger tasks efficiently.
"What if the drone could scan multiple fields without flying to each one separately? How would the time complexity change?"