Privacy rules and data access in No-Code - Time & Space Complexity
When managing privacy rules and data access, it is important to understand how the time to check permissions grows as more rules or data increase.
We want to know how the system's work changes when the number of privacy rules or data items grows.
Analyze the time complexity of the following code snippet.
for each data_item in data_list:
for each rule in privacy_rules:
if rule applies to data_item:
check permission
if permission denied:
block access
break
allow access if no rule denies
This code checks each data item against all privacy rules to decide if access is allowed or blocked.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Checking each data item against every privacy rule.
- How many times: For each data item, all privacy rules are checked until a denial is found or all rules pass.
As the number of data items or privacy rules grows, the checks increase accordingly.
| Input Size (data items n, rules m) | Approx. Operations |
|---|---|
| 10 data, 5 rules | About 50 checks |
| 100 data, 5 rules | About 500 checks |
| 100 data, 50 rules | About 5,000 checks |
Pattern observation: The total checks grow roughly by multiplying the number of data items by the number of rules.
Time Complexity: O(n x m)
This means the time to check permissions grows proportionally with both the number of data items and the number of privacy rules.
[X] Wrong: "Checking privacy rules takes the same time no matter how many data items or rules there are."
[OK] Correct: Each data item must be checked against each rule, so more data or rules means more work and longer time.
Understanding how privacy checks scale helps you design systems that handle data securely and efficiently, a valuable skill in many roles.
"What if the system stopped checking rules after the first allowed permission instead of the first denial? How would the time complexity change?"