Operating system setup (Raspberry Pi OS) - Time & Space Complexity
When setting up an operating system on a Raspberry Pi, it helps to understand how the time needed grows as the tasks increase.
We want to know how the setup time changes when we add more steps or devices.
Analyze the time complexity of the following setup script snippet.
# Install multiple packages
packages=("python3" "git" "vim" "curl")
for pkg in "${packages[@]}"; do
sudo apt-get install -y "$pkg"
done
# Enable services
services=("ssh" "bluetooth")
for service in "${services[@]}"; do
sudo systemctl enable "$service"
sudo systemctl start "$service"
done
This script installs several packages and enables some services on the Raspberry Pi OS.
Look at the loops that repeat commands for each item.
- Primary operation: Installing packages and enabling services inside loops.
- How many times: Once per package and once per service, repeating for each item in the lists.
As the number of packages or services grows, the total commands run grow in a similar way.
| Input Size (n) | Approx. Operations |
|---|---|
| 4 packages + 2 services | 6 install/enable commands |
| 10 packages + 5 services | 15 install/enable commands |
| 100 packages + 50 services | 150 install/enable commands |
Pattern observation: The total steps increase directly with the number of packages and services.
Time Complexity: O(n)
This means the setup time grows in a straight line as you add more packages or services.
[X] Wrong: "Adding more packages won't affect setup time much because each install is fast."
[OK] Correct: Each package install takes time, so more packages mean more total time, growing linearly.
Understanding how setup steps add up helps you explain how scripts scale and manage resources in real projects.
"What if we combined all package installs into one command? How would the time complexity change?"