Mission upload and execution in Drone Programming - Time & Space Complexity
Start learning this pattern below
Jump into concepts and practice - no test required
When a drone uploads and executes a mission, it processes a list of commands step by step.
We want to understand how the time it takes grows as the mission gets longer.
Analyze the time complexity of the following code snippet.
function uploadAndExecuteMission(mission) {
for (let i = 0; i < mission.length; i++) {
uploadCommand(mission[i]);
}
executeMission();
}
This code uploads each command in the mission one by one, then starts the mission execution.
- Primary operation: Looping through each command in the mission array.
- How many times: Once for every command in the mission.
As the mission gets longer, the number of commands to upload grows, so the time grows too.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | About 10 uploads + 1 execute |
| 100 | About 100 uploads + 1 execute |
| 1000 | About 1000 uploads + 1 execute |
Pattern observation: The time grows roughly in direct proportion to the number of commands.
Time Complexity: O(n)
This means the time to upload and start the mission grows linearly with the number of commands.
[X] Wrong: "Uploading commands happens all at once, so time stays the same no matter how many commands there are."
[OK] Correct: Each command must be sent one by one, so more commands mean more time.
Understanding how mission upload time grows helps you explain how drones handle tasks efficiently as missions get bigger.
"What if the uploadCommand function itself had a loop inside? How would that affect the overall time complexity?"
Practice
Solution
Step 1: Understand mission upload meaning
Uploading a mission means sending the flight plan to the drone's system.Step 2: Identify what happens after upload
The drone receives the plan but does not start flying until commanded.Final Answer:
It sends the flight plan to the drone for automatic flying. -> Option DQuick Check:
Uploading mission = send flight plan [OK]
- Confusing upload with starting the drone
- Thinking upload charges the battery
- Assuming upload returns drone home
Solution
Step 1: Identify method to start mission
The method to start flying the uploaded mission is usually named startMission().Step 2: Differentiate from upload method
uploadMission() uploads the plan but does not start flight.Final Answer:
drone.startMission() -> Option AQuick Check:
Start mission method = startMission() [OK]
- Using uploadMission() to start flight
- Confusing method names like beginFlight() which is invalid
- Assuming executePlan() is standard method
drone.uploadMission(missionPlan) drone.startMission() print(drone.status())
What is the expected output if the mission starts successfully?
Solution
Step 1: Analyze code sequence
The mission is uploaded first, then started, so the drone should be flying.Step 2: Check status output meaning
Calling drone.status() after startMission() should return "Mission started" indicating flight began.Final Answer:
"Mission started" -> Option AQuick Check:
Status after startMission() = "Mission started" [OK]
- Confusing upload status with start status
- Expecting "Mission completed" immediately
- Assuming error without upload
drone.startMission() drone.uploadMission(missionPlan)
Solution
Step 1: Check order of operations
Mission must be uploaded before starting; here startMission() is called first.Step 2: Understand consequence
Starting mission without upload means no flight plan, causing an error.Final Answer:
Starting mission before uploading causes an error. -> Option CQuick Check:
Upload before startMission() [OK]
- Calling startMission() before uploadMission()
- Assuming no initialization error
- Thinking multiple uploads cause error here
1. drone.uploadMission(plan)
2. drone.startMission()
3. while not drone.isMissionComplete():
print(drone.getProgress())
4. print("Mission complete!")Solution
Step 1: Verify mission upload and start
Uploading the plan then starting the mission is the correct order.Step 2: Confirm monitoring loop logic
The loop checks if mission is complete and prints progress until done, then confirms completion.Final Answer:
This sequence correctly uploads, starts, monitors, and confirms mission completion. -> Option BQuick Check:
Upload -> start -> monitor -> complete [OK]
- Trying to monitor before starting mission
- Checking wrong status in loop
- Assuming mission can't be monitored
