Blockchain use cases beyond crypto - Time & Space Complexity
When using blockchain beyond cryptocurrency, it is important to understand how the time to process data grows as more information is added.
We want to know how the cost of operations changes as the blockchain handles more transactions or records.
Analyze the time complexity of the following code snippet.
function verifyRecords(records) {
for (let i = 0; i < records.length; i++) {
if (!verifySignature(records[i])) {
return false;
}
}
return true;
}
// This function checks each record's signature in a blockchain-based document system.
This code checks every record's signature one by one to ensure all are valid.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Loop through all records to verify signatures.
- How many times: Once for each record in the input list.
As the number of records grows, the time to verify all signatures grows too.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 signature checks |
| 100 | 100 signature checks |
| 1000 | 1000 signature checks |
Pattern observation: The time grows directly with the number of records; doubling records doubles work.
Time Complexity: O(n)
This means the time to verify grows in a straight line as the number of records increases.
[X] Wrong: "Verifying one record means all records are verified instantly."
[OK] Correct: Each record must be checked separately, so time adds up with more records.
Understanding how verification time grows helps you explain blockchain performance beyond crypto, showing you grasp real-world system behavior.
"What if we batch verify signatures instead of one by one? How would the time complexity change?"