0
0
Linux CLIscripting~5 mins

nslookup and dig for DNS in Linux CLI - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: nslookup and dig for DNS
O(n)
Understanding Time Complexity

When using commands like nslookup and dig to query DNS, it helps to understand how the time to get results grows as we ask for more information.

We want to know how the command's work changes when we query more domains or request more details.

Scenario Under Consideration

Analyze the time complexity of the following command sequence.


for domain in example.com example.org example.net; do
  dig +short $domain
  nslookup $domain
  sleep 1
 done
    

This script queries three domains using dig and nslookup, pausing briefly between each.

Identify Repeating Operations

Look for repeated actions that take time.

  • Primary operation: Running dig and nslookup commands for each domain.
  • How many times: Once per domain, so 3 times in this example.
How Execution Grows With Input

As the number of domains increases, the total time grows roughly in a straight line.

Input Size (n)Approx. Operations
1010 queries each for dig and nslookup
100100 queries each for dig and nslookup
10001000 queries each for dig and nslookup

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

Final Time Complexity

Time Complexity: O(n)

This means if you double the number of domains, the total time roughly doubles too.

Common Mistake

[X] Wrong: "Running dig or nslookup once takes the same time no matter how many domains I query."

[OK] Correct: Each domain query is a separate operation that takes time, so more domains mean more total time.

Interview Connect

Understanding how command execution time grows with input size helps you write scripts that scale well and avoid surprises when working with many domains.

Self-Check

What if we combined all domain queries into a single dig command? How would the time complexity change?