passwd (change password) in Linux CLI - Time & Space Complexity
When using the passwd command to change a password, it's helpful to understand how the time it takes grows with input size.
We want to know how the command's work changes as the password length or system size changes.
Analyze the time complexity of the passwd command process.
# User runs passwd to change password
passwd
# System prompts for current password
# User enters current password
# System prompts for new password
# User enters new password
# System verifies and updates password
This snippet shows the typical steps when changing a password using passwd.
Look for any repeated actions or checks during the password change.
- Primary operation: Password verification and update steps.
- How many times: Each step happens once per password change attempt.
The time to change a password grows mostly with the length of the password entered.
| Input Size (password length) | Approx. Operations |
|---|---|
| 10 characters | Small number of checks and updates |
| 100 characters | More checks proportional to length |
| 1000 characters | Much longer verification and update time |
Pattern observation: The work grows roughly in proportion to the password length.
Time Complexity: O(n)
This means the time to change a password grows linearly with the length of the password.
[X] Wrong: "Changing a password always takes the same time no matter how long it is."
[OK] Correct: The system must check every character, so longer passwords take more time to process.
Understanding how commands like passwd scale helps you think about efficiency in real systems.
This skill shows you can reason about how user input size affects system work.
"What if the system added extra password strength checks that scan the password multiple times? How would the time complexity change?"