Common cron expressions in Linux CLI - Time & Space Complexity
We want to understand how the time it takes to run cron jobs grows as we schedule more tasks or more frequent jobs.
How does the number of cron expressions affect the system's work over time?
Analyze the time complexity of checking and running cron jobs with these expressions.
* * * * * /path/to/script1.sh
0 * * * * /path/to/script2.sh
0 0 * * * /path/to/script3.sh
*/15 * * * * /path/to/script4.sh
0 0 1 * * /path/to/script5.sh
This snippet shows common cron expressions that schedule scripts at different intervals: every minute, hourly, daily, every 15 minutes, and monthly.
Each cron expression causes the system to check if it should run a job at each minute.
- Primary operation: Checking each cron expression every minute.
- How many times: Once per minute for each expression.
As the number of cron expressions (n) grows, the system checks each one every minute.
| Input Size (n) | Approx. Checks per hour |
|---|---|
| 10 | 600 |
| 100 | 6000 |
| 1000 | 60000 |
Pattern observation: The number of checks grows directly with the number of cron expressions.
Time Complexity: O(n)
This means the work grows linearly with the number of cron expressions to check each minute.
[X] Wrong: "Cron jobs run only when scheduled, so adding more jobs doesn't increase checking work."
[OK] Correct: The system checks all cron expressions every minute to decide which jobs to run, so more jobs mean more checks.
Understanding how scheduled tasks scale helps you design systems that stay efficient as they grow. This skill shows you can think about system workload over time.
What if cron expressions were grouped and checked in batches instead of individually? How would the time complexity change?