Sending transactions in Blockchain / Solidity - Time & Space 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.
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 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.
As the number of transactions increases, the total sending time grows in direct proportion.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 sends |
| 100 | 100 sends |
| 1000 | 1000 sends |
Pattern observation: Doubling the number of transactions doubles the total sending time.
Time Complexity: O(n)
This means the time to send transactions grows linearly with the number of transactions.
[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.
Understanding how sending transactions scales helps you explain performance in blockchain apps clearly and confidently.
"What if we batch multiple transactions into one send call? How would the time complexity change?"