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?"
Practice
Solution
Step 1: Understand blockchain beyond money
Blockchain is used to keep safe and clear records, not just for digital money.Step 2: Identify common non-crypto uses
Tracking goods in supply chains is a popular use case to ensure transparency and trust.Final Answer:
Tracking the origin and movement of goods in supply chains -> Option CQuick Check:
Blockchain use beyond crypto = Tracking goods [OK]
- Thinking blockchain only creates cryptocurrencies
- Confusing blockchain with regular databases
- Assuming blockchain replaces all internet servers
Solution
Step 1: Recognize smart contract syntax
Smart contracts are written like small programs with a contract keyword and functions.Step 2: Check syntax correctness
contract SmartContract { function run() public {} } uses correct syntax with 'contract' keyword and function declaration.Final Answer:
contract SmartContract { function run() public {} } -> Option AQuick Check:
Correct smart contract syntax = contract SmartContract { function run() public {} } [OK]
- Missing 'contract' keyword
- Using assignment instead of declaration
- Incorrect function declaration syntax
mapping(address => uint) public votes;
function vote() public {
votes[msg.sender] += 1;
}
vote() called twice by same address.
Solution
Step 1: Understand the vote function
Each call to vote() increases the caller's vote count by 1 in the votes mapping.Step 2: Calculate votes after two calls
Calling vote() twice adds 1 twice, so votes[msg.sender] becomes 2.Final Answer:
votes[msg.sender] = 2 -> Option BQuick Check:
Two votes increment count to 2 [OK]
- Assuming only one vote allowed
- Thinking votes reset after each call
- Confusing mapping with array
mapping(address => bool) public voted;
function vote() public {
require(!voted[msg.sender]);
voted[msg.sender] = true;
votes += 1;
}
Solution
Step 1: Check variable declarations
The code uses 'votes += 1' but 'votes' is not declared anywhere.Step 2: Verify other parts
require syntax and voted mapping type are correct; vote() functions in Solidity do not need return type.Final Answer:
votes variable is not declared -> Option AQuick Check:
Undeclared variable 'votes' causes error [OK]
- Assuming require syntax is wrong
- Thinking bool mapping is incorrect
- Expecting return type in void functions
Solution
Step 1: Understand digital rights management needs
Managing rights requires automatic, trustworthy payment distribution to artists.Step 2: Identify blockchain feature for automation
Smart contracts can run code to automate royalty payments when music is used or sold.Step 3: Evaluate other options
Cryptocurrency tokens and voting are unrelated; centralized database loses blockchain benefits.Final Answer:
Smart contracts to automate royalty payments -> Option DQuick Check:
Automate payments with smart contracts [OK]
- Choosing cryptocurrency token instead of automation
- Using centralized database losing blockchain trust
- Confusing voting with rights management
Ready to prove it?
Pass the test and this pattern moves unknown
