0
0
IOT Protocolsdevops~5 mins

QoS levels (0, 1, 2) in IOT Protocols - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: QoS levels (0, 1, 2)
O(n)
Understanding Time Complexity

We want to understand how the work done by different QoS levels changes as the number of messages grows.

How does the effort to deliver messages grow when more messages are sent?

Scenario Under Consideration

Analyze the time complexity of the following QoS message delivery logic.

// Pseudocode for QoS message delivery
function deliverMessages(messages, qos) {
  for (let msg of messages) {
    if (qos === 0) {
      sendOnce(msg);
    } else if (qos === 1) {
      sendAndWaitAck(msg);
    } else if (qos === 2) {
      sendWithTwoStepHandshake(msg);
    }
  }
}

This code sends each message differently based on QoS level: once, with one acknowledgment, or with a two-step handshake.

Identify Repeating Operations

Look at what repeats as messages increase.

  • Primary operation: Loop over all messages to send them.
  • How many times: Once per message, so number of messages times.
How Execution Grows With Input

As the number of messages grows, the sending steps grow too.

Input Size (n)Approx. Operations
1010 sends (each with steps depending on QoS)
100100 sends (each with steps depending on QoS)
10001000 sends (each with steps depending on QoS)

Pattern observation: The total work grows directly with the number of messages.

Final Time Complexity

Time Complexity: O(n)

This means the work to deliver messages grows in a straight line as you add more messages.

Common Mistake

[X] Wrong: "QoS 2 takes much longer time because of the handshake, so its time complexity is higher than QoS 0 or 1."

[OK] Correct: While QoS 2 has more steps per message, the number of messages still controls the total work linearly. The extra steps are a constant factor, not a change in growth rate.

Interview Connect

Understanding how message delivery scales helps you explain system behavior clearly and shows you can think about efficiency in real-world IoT systems.

Self-Check

"What if we added retries for failed messages in QoS 1 and 2? How would the time complexity change?"