Skip to main content

Input data size

1. The core idea

The more input data, the longer the code takes to run, unless the algorithm scales efficiently.

The size of the input directly affects:

  • execution time (CPU load);
  • memory usage;
  • the number of input/output (I/O) operations;
  • the number of iterations and recursion depth.

This dependency is usually expressed through asymptotic complexity (Big O), how fast the execution time grows as the input grows.


2. A simple visualization

AlgorithmComplexityWhat it meansExample
O(1)constantdoesn't depend on data sizeindex access arr[0]
O(log n)logarithmicgrows slowlybinary search
O(n)lineartime grows proportionally to the number of elementsa for loop over an array
O(n log n)quasi-linearmoderate growthArray.sort()
O(n²)quadraticexplosive growth with large datanested loops
O(2ⁿ)exponentialgrows catastrophicallyrecursive Fibonacci
O(n!)factorialinfeasible for large npermutations

3. Examples in JavaScript

O(1) - independent of size

javascript
const arr = [1, 2, 3, 4, 5]; console.log(arr[3]); // instant, whether it's 5 or 5 million elements

O(n) - linear dependency

javascript
function sum(arr) { return arr.reduce((acc, num) => acc + num, 0); } sum([1, 2, 3]); // ~3 operations sum(new Array(1000000)); // ~1,000,000 operations

The bigger the array, the more time it takes.


O(n²) - quadratic growth

javascript
function allPairs(arr) { for (let i = 0; i < arr.length; i++) { for (let j = 0; j < arr.length; j++) { // some operation } } }

If n = 1000, that's roughly 1,000,000 operations. If n = 10,000, it's already 100,000,000.


O(2ⁿ) - exponential growth

javascript
function fib(n) { if (n <= 1) return n; return fib(n - 1) + fib(n - 2); } fib(30); // fine fib(45); // already slow!

The growth is explosive. At 100 elements, it's simply infeasible to compute.


4. How growing input affects performance

Input sizeO(1)O(log n)O(n)O(n²)O(2ⁿ)
10fastfastfastfastfast
100fastfastfastmoderateslow
1,000fastfastmoderateslowcritical
100,000fastfastslowcriticalcritical

Conclusion: with small data everything "flies", but as the volume grows, "inefficient" code starts to explode in execution time.


5. Performance in different scenarios

Task typeExampleHow data size affects it
Iterating an arraymap, filter, reducelinear
Searching an arrayarr.includes()linear
Looking up an object / Mapobj[key], map.get()almost O(1)
Sortingarr.sort()O(n log n)
Comparing nested structuresdeep object comparisoncan be O(n²)
Rendering in Reactlarge lists, tablestime grows with DOM size
Database querieswithout an index -> O(n)more rows means slower

6. Practical effects

  • CPU load grows - operations take longer;
  • memory usage increases - especially when copying or storing large structures;
  • the event loop gets blocked - the UI "hangs";
  • FPS drops - animations get choppy;
  • the GC (garbage collector) runs more often -> lag.

7. How to improve performance as data grows

ProblemSolution
Loops take too longBreak into chunks (setTimeout, requestIdleCallback)
Complex filters/searchesUse Set, Map, indexes
Frequent repeated computationsMemoization
Too many elements in the DOMVirtualization (react-window, infinite scroll)
Frequent array re-creationUse mutations carefully
Large JSONStream reading (ReadableStream)

Summary

The larger the input data, the more the asymptotic complexity of the algorithm and the load on memory/CPU show up.

Data size grows-> Affects
Number of iterationsExecution time
Recursion depthRisk of stack overflow
Number of objectsMemory usage
List / array lengthNumber of re-renders (in React)
Volume of I/ODelay from network / disk

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.