Data access logs in GCP - Time & Space Complexity
When we collect data access logs in cloud systems, we want to know how the time to gather these logs changes as more data is accessed.
We ask: How does the number of log entries affect the time to process or retrieve them?
Analyze the time complexity of retrieving data access logs from a cloud storage bucket.
// Pseudocode for fetching logs
logs = storageClient.listLogs(bucketName)
for log in logs:
process(log)
This sequence lists all access logs in a bucket and processes each one.
Look at what repeats as the logs grow.
- Primary operation: Listing and processing each log entry.
- How many times: Once per log entry in the bucket.
As the number of logs increases, the time to list and process them grows in a straight line.
| Input Size (n) | Approx. API Calls/Operations |
|---|---|
| 10 | 10 list and process operations |
| 100 | 100 list and process operations |
| 1000 | 1000 list and process operations |
Pattern observation: Doubling the logs doubles the work needed.
Time Complexity: O(n)
This means the time grows directly with the number of logs; more logs take more time.
[X] Wrong: "Retrieving logs always takes the same time no matter how many logs there are."
[OK] Correct: Each log entry must be read and processed, so more logs mean more work and more time.
Understanding how log retrieval time grows helps you design systems that handle monitoring and auditing efficiently.
"What if we only retrieve logs from the last hour instead of all logs? How would the time complexity change?"