Sending custom MAVLink commands in Drone Programming - Time & Space Complexity
When sending custom MAVLink commands, it's important to know how the time to send commands grows as you send more commands.
We want to understand how the program's work changes when the number of commands increases.
Analyze the time complexity of the following code snippet.
for command in commands_list:
mavlink_message = create_custom_command(command)
send_mavlink_message(mavlink_message)
wait_for_acknowledgment()
This code sends each custom MAVLink command one by one, waiting for an acknowledgment before sending the next.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Loop over each command in the list.
- How many times: Once for every command in the commands_list.
Each command requires creating, sending, and waiting for acknowledgment, so the total work grows directly with the number of commands.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 command sends and waits |
| 100 | 100 command sends and waits |
| 1000 | 1000 command sends and waits |
Pattern observation: The total time grows in a straight line as the number of commands increases.
Time Complexity: O(n)
This means the time to send commands grows directly in proportion to how many commands you have.
[X] Wrong: "Sending multiple commands at once will take the same time as sending one command."
[OK] Correct: Each command needs time to be created, sent, and acknowledged, so more commands mean more total time.
Understanding how sending commands scales helps you design efficient drone control programs and shows you can think about program speed clearly.
"What if we sent all commands without waiting for acknowledgment? How would the time complexity change?"