yum/dnf (RHEL/CentOS) basics in Linux CLI - Time & Space Complexity
When using yum or dnf to install or update packages, it's helpful to understand how the time taken grows as you manage more packages.
We want to know how the number of packages affects the time the commands take to run.
Analyze the time complexity of the following yum command sequence.
yum check-update
if [ $? -eq 100 ]; then
yum update -y
fi
This code checks for available updates and then updates all packages if any updates exist.
Look at what repeats as the number of packages grows.
- Primary operation: Checking each installed package against repository metadata.
- How many times: Once per installed package during the check-update and update steps.
As the number of installed packages increases, the time to check and update grows roughly in proportion.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | About 10 package checks |
| 100 | About 100 package checks |
| 1000 | About 1000 package checks |
Pattern observation: The work grows linearly as you add more packages.
Time Complexity: O(n)
This means the time to check and update packages grows directly with the number of packages installed.
[X] Wrong: "Running yum update takes the same time no matter how many packages I have."
[OK] Correct: The command checks each package, so more packages mean more work and longer time.
Understanding how commands scale with input size shows you can think about efficiency, a useful skill for scripting and automation tasks.
"What if we only update a single package instead of all? How would the time complexity change?"