Image alt text and optimization in SEO Fundamentals - Time & Space Complexity
When we add images to a webpage, the way we write alt text and optimize images affects how fast the page loads.
We want to understand how the time to load changes as we add more images or bigger images.
Analyze the time complexity of loading images with alt text and optimization.
<img src='image1.jpg' alt='A sunny beach' width='300' height='200' loading='lazy' />
<img src='image2.jpg' alt='Mountain view' width='300' height='200' loading='lazy' />
<img src='image3.jpg' alt='City skyline' width='300' height='200' loading='lazy' />
// Images use optimized sizes and lazy loading to improve performance
This code loads three images with descriptive alt text and uses lazy loading to delay loading until needed.
Look at what repeats when loading images on a page.
- Primary operation: Loading each image file from the server.
- How many times: Once per image, so the number of images (n) times.
As you add more images, the total loading time grows roughly in direct proportion to the number of images.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | Loading 10 images |
| 100 | Loading 100 images |
| 1000 | Loading 1000 images |
Pattern observation: Doubling the number of images roughly doubles the loading work.
Time Complexity: O(n)
This means the loading time grows linearly with the number of images on the page.
[X] Wrong: "Adding alt text or optimizing images does not affect loading time."
[OK] Correct: Alt text itself is small but helps accessibility; optimization reduces image size, which directly speeds up loading.
Understanding how image loading scales helps you build faster websites and shows you care about user experience and performance.
What if we changed from lazy loading to eager loading for all images? How would the time complexity change?