0
0
Blockchain / Solidityprogramming~5 mins

Sending transactions in Blockchain / Solidity - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Sending transactions
O(n)
Understanding Time Complexity

When sending transactions on a blockchain, it's important to understand how the time needed grows as more transactions are processed.

We want to know how the cost changes when sending many transactions one after another.

Scenario Under Consideration

Analyze the time complexity of the following code snippet.


function sendTransactions(transactions) {
  for (let i = 0; i < transactions.length; i++) {
    blockchain.send(transactions[i]);
  }
}
    

This code sends each transaction one by one to the blockchain network.

Identify Repeating Operations

Identify the loops, recursion, array traversals that repeat.

  • Primary operation: Sending a single transaction to the blockchain.
  • How many times: Once for each transaction in the input list.
How Execution Grows With Input

As the number of transactions increases, the total sending time grows in direct proportion.

Input Size (n)Approx. Operations
1010 sends
100100 sends
10001000 sends

Pattern observation: Doubling the number of transactions doubles the total sending time.

Final Time Complexity

Time Complexity: O(n)

This means the time to send transactions grows linearly with the number of transactions.

Common Mistake

[X] Wrong: "Sending multiple transactions at once takes the same time as sending one."

[OK] Correct: Each transaction requires its own processing time, so more transactions mean more total time.

Interview Connect

Understanding how sending transactions scales helps you explain performance in blockchain apps clearly and confidently.

Self-Check

"What if we batch multiple transactions into one send call? How would the time complexity change?"