Public vs private blockchains - Performance Comparison
When we compare public and private blockchains, it's important to see how their operations grow as more users or transactions join the network.
We want to understand how the time to process or verify transactions changes with the size of the network.
Analyze the time complexity of transaction verification in public and private blockchains.
// Pseudocode for transaction verification
function verifyTransaction(transaction, blockchain) {
for (const block of blockchain) {
for (const tx of block.transactions) {
if (tx.id === transaction.id) {
return true;
}
}
}
return false;
}
This code checks if a transaction already exists by scanning all blocks and their transactions.
Look at the loops that repeat work:
- Primary operation: Nested loops scanning all blocks and their transactions.
- How many times: Outer loop runs once per block, inner loop runs once per transaction in each block.
As the blockchain grows, the number of blocks and transactions increases, so the verification work grows too.
| Input Size (n = total transactions) | Approx. Operations |
|---|---|
| 10 | About 10 checks |
| 100 | About 100 checks |
| 1000 | About 1000 checks |
Pattern observation: The work grows roughly in direct proportion to the number of transactions.
Time Complexity: O(n)
This means the time to verify a transaction grows linearly as more transactions are added.
[X] Wrong: "Private blockchains always verify transactions faster because they have fewer users."
[OK] Correct: The number of transactions matters more than users; if a private blockchain has many transactions, verification time still grows linearly.
Understanding how verification time grows helps you explain blockchain performance clearly and confidently in real-world discussions.
"What if we used an index to track transactions instead of scanning all blocks? How would the time complexity change?"
Practice
Solution
Step 1: Understand public blockchain access
Public blockchains are open networks where anyone can join and participate without needing permission.Step 2: Compare with private blockchain features
Private blockchains restrict access to trusted members, unlike public ones.Final Answer:
Anyone can join and participate without permission. -> Option AQuick Check:
Public blockchain = open access [OK]
- Confusing public with private blockchain access
- Thinking public blockchains are controlled by one entity
- Assuming private keys limit public blockchain access
Solution
Step 1: Identify private blockchain access rules
Private blockchains restrict access to selected participants, unlike public blockchains.Step 2: Eliminate incorrect options
Private blockchains do not necessarily use proof-of-work or are always slower; these are unrelated to access control.Final Answer:
It restricts access to selected participants only. -> Option CQuick Check:
Private blockchain = restricted access [OK]
- Assuming private blockchains allow anyone to validate
- Confusing consensus methods with access control
- Believing private blockchains are always slower
def can_access(user, blockchain_type):
if blockchain_type == 'public':
return True
elif blockchain_type == 'private':
return user in ['Alice', 'Bob']
else:
return False
print(can_access('Alice', 'public'))
print(can_access('Eve', 'private'))
print(can_access('Bob', 'private'))
What is the output?Solution
Step 1: Evaluate access for 'Alice' on public blockchain
Public blockchain always returns True, so can_access('Alice', 'public') is True.Step 2: Evaluate access for 'Eve' on private blockchain
'Eve' is not in ['Alice', 'Bob'], so can_access('Eve', 'private') returns False.Step 3: Evaluate access for 'Bob' on private blockchain
'Bob' is in the allowed list, so can_access('Bob', 'private') returns True.Final Answer:
True False True -> Option BQuick Check:
Public always True, private checks user list [OK]
- Assuming private blockchain allows all users
- Mixing up True/False return values
- Ignoring the user list check for private blockchains
def check_access(user, blockchain):
if blockchain == 'private':
if user == ['Alice', 'Bob']:
return True
else:
return False
else:
return True
print(check_access('Alice', 'private'))Solution
Step 1: Analyze user comparison in private blockchain check
The code uses 'user == ['Alice', 'Bob']' which compares a string to a list, always False.Step 2: Identify correct way to check user membership
It should use 'user in ['Alice', 'Bob']' to check if user is in the allowed list.Final Answer:
The user comparison uses == with a list instead of membership check. -> Option AQuick Check:
Use 'in' to check list membership, not '==' [OK]
- Using '==' to compare a string with a list
- Forgetting to handle public blockchain case
- Syntax errors in print statement
Solution
Step 1: Identify who can add transactions
The company wants only employees to add transactions, so write access must be restricted.Step 2: Identify who can view the ledger
Anyone can view the ledger, so read access is open to the public.Step 3: Match blockchain type to requirements
Private blockchains restrict write access to trusted members but can allow public read access, fitting the need.Final Answer:
Private blockchain, because it restricts who can add transactions but allows public viewing. -> Option DQuick Check:
Restrict writes, allow public reads = Private blockchain [OK]
- Choosing public blockchain for restricted write access
- Thinking private blockchain hides ledger from public
- Confusing read and write permissions
Ready to prove it?
Pass the test and this pattern moves unknown
