git blame for line-by-line history - Time & Space Complexity
When using git blame, we want to know how the time it takes grows as the file size grows.
We ask: How does checking each line's history scale with the number of lines?
Analyze the time complexity of this git blame command:
git blame filename.txt
This command shows who last changed each line in the file.
Look at what repeats inside git blame:
- Primary operation: Checking each line's last change in the file.
- How many times: Once for every line in the file.
As the file gets bigger, the work grows with the number of lines.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 lines | About 10 checks |
| 100 lines | About 100 checks |
| 1000 lines | About 1000 checks |
Pattern observation: The work grows directly with the number of lines.
Time Complexity: O(n)
This means the time to run git blame grows in a straight line as the file gets longer.
[X] Wrong: "git blame runs instantly no matter the file size."
[OK] Correct: It actually checks each line, so bigger files take more time.
Understanding how commands like git blame scale helps you explain performance clearly and shows you think about real-world tool behavior.
"What if we run git blame on a file with many unchanged lines? Would the time complexity change?"