0
0
SEO Fundamentalsknowledge~5 mins

Image alt text and optimization in SEO Fundamentals - Time & Space Complexity

Choose your learning style9 modes available
Time Complexity: Image alt text and optimization
O(n)
Understanding Time 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.

Scenario Under Consideration

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.

Identify Repeating Operations

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.
How Execution Grows With Input

As you add more images, the total loading time grows roughly in direct proportion to the number of images.

Input Size (n)Approx. Operations
10Loading 10 images
100Loading 100 images
1000Loading 1000 images

Pattern observation: Doubling the number of images roughly doubles the loading work.

Final Time Complexity

Time Complexity: O(n)

This means the loading time grows linearly with the number of images on the page.

Common Mistake

[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.

Interview Connect

Understanding how image loading scales helps you build faster websites and shows you care about user experience and performance.

Self-Check

What if we changed from lazy loading to eager loading for all images? How would the time complexity change?