Why waypoint navigation enables autonomous missions in Drone Programming - Performance Analysis
We want to understand how the time a drone takes to complete a mission grows as we add more waypoints.
How does adding more waypoints affect the drone's navigation steps?
Analyze the time complexity of the following code snippet.
function navigateWaypoints(waypoints) {
for (let i = 0; i < waypoints.length; i++) {
flyTo(waypoints[i]);
waitUntilArrived();
}
}
This code makes the drone fly to each waypoint one by one, waiting to arrive before moving to the next.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: The loop that sends the drone to each waypoint.
- How many times: Once for each waypoint in the list.
Each new waypoint adds one more fly-and-wait step, so the total steps grow directly with the number of waypoints.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 fly-and-wait steps |
| 100 | 100 fly-and-wait steps |
| 1000 | 1000 fly-and-wait steps |
Pattern observation: The total time grows steadily as we add more waypoints, increasing in a straight line.
Time Complexity: O(n)
This means the time to complete the mission grows directly in proportion to the number of waypoints.
[X] Wrong: "Adding more waypoints won't affect mission time much because the drone flies fast."
[OK] Correct: Even if flying is fast, the drone must still visit each waypoint one after another, so more waypoints mean more steps and more total time.
Understanding how mission time grows with waypoints shows you can think about how programs scale, a key skill in real-world drone programming and automation.
"What if the drone could visit multiple waypoints at the same time? How would that change the time complexity?"