Why sensors provide situational awareness in Drone Programming - Performance Analysis
We want to understand how the time it takes for a drone to process sensor data changes as the number of sensors or data points grows.
How does adding more sensor inputs affect the drone's ability to stay aware of its surroundings?
Analyze the time complexity of the following code snippet.
function processSensors(sensorData) {
for (let i = 0; i < sensorData.length; i++) {
let reading = sensorData[i];
analyzeReading(reading);
}
}
function analyzeReading(reading) {
// simple check on reading
if (reading.value > threshold) {
alertObstacle(reading);
}
}
This code goes through each sensor reading one by one and checks if it detects an obstacle.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Looping through each sensor reading in the sensorData array.
- How many times: Once for every reading in the sensorData list.
As the number of sensor readings increases, the time to process them grows in a straight line.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 checks |
| 100 | 100 checks |
| 1000 | 1000 checks |
Pattern observation: Doubling the sensor readings roughly doubles the work done.
Time Complexity: O(n)
This means the time to process sensor data grows directly with the number of readings.
[X] Wrong: "Processing more sensors takes the same time no matter how many readings there are."
[OK] Correct: Each sensor reading needs to be checked, so more readings mean more work and more time.
Understanding how sensor data processing time grows helps you explain how drones stay aware in real time, a key skill in drone programming.
"What if analyzeReading also loops through a list of sub-readings for each sensor? How would the time complexity change?"