Big-O You Can Feel: Complexity Through Re-renders and DOM Work
Algorithms for frontend engineers — taught entirely through the costs you actually pay in the browser, so you feel asymptotic complexity instead of memorizing it. Three connected arcs build the intuition: reading Big-O straight off real render code (a .find() inside a .map(), querySelectorAll in a loop, layout thrashing from interleaved reads and writes, and the best, worst, and amortized cases plus the constant factors that bite the main thread); why array.includes() inside a filter quietly turns a list quadratic and how a Set or Map collapses the same lookup to O(1); and the binary search hiding in plain sight behind virtualized lists, sorted inserts, and lower-/upper-bound queries. Aimed at frontend developers who want to connect classic algorithms and data structures to the React, DOM, and rendering work they already do every day — and finally read complexity off code instead of textbook pseudocode.
Questions
- Not answered. This list render runs one
.find()for every row it.map()s. It feels instant with 10 rows but freezes at 10,000. Why? - Not answered. Why is this loop slow even though it touches each element only once?
- Not answered. What is the running time of calling
document.querySelectorAll('.cell')once per row? - Not answered. For
array.find(predicate)on an unsorted array of n items, which best/worst-case description is correct? - Not answered. You
pushn items onto a JavaScript array one at a time. What is the amortized cost perpush? - Not answered. Two functions are both O(n) over the same list. Why might one still cause visible jank while the other does not?
- Not answered. Select every snippet whose running time is O(n²). Assume each array has length n.
- Not answered. Which statements about estimating complexity from real frontend code are true? Select all that apply.
- Not answered. Read the snippet and type its overall time-complexity class, for example
O(n). - Not answered. Read the snippet and type its worst-case time-complexity class, for example
O(n). - Not answered. What is the average time complexity of
arr.includes(x)for an array of n elements? - Not answered. A table renders n rows and stores the selected ids in an array
selectedIdsof length m. What is the cost ofrows.filter(r => selectedIds.includes(r.id))? - Not answered. What is the average time complexity of
set.has(x)for aSet? - Not answered. Which UI tasks get faster or simpler when backed by a
Setinstead of an array? - Not answered. By what rule does a
Setdecide that two values are the same, and therefore duplicates? - Not answered. Which expression removes duplicate primitives from
arrinO(n)average time? - Not answered. Which are genuine advantages of a
Mapover a plain{}object for anid → entitylookup table? - Not answered. Using a plain
{}as a string-keyed dictionary has footguns that aMapavoids. Which statements are true? - Not answered. You hold an array of n entities and must look many of them up by
id. Which statements are correct? - Not answered. In the worst case, how many element comparisons does
includesmake in total? Enter the number. - Not answered. A teammate runs a binary-search helper on an array that isn't actually sorted. The value is present. What's the most likely result?
- Not answered. With inclusive bounds (
hi = arr.length - 1), which loop condition correctly searches for an exact match? - Not answered. Filling the blank, why is
lo = mid + 1correct whilelo = midis a bug? - Not answered. What does a lower-bound binary search return for a target
xin a sorted array? - Not answered.
react-windowand@tanstack/virtualrender only the visible rows. With variable row heights, how do they find the first visible row for a givenscrollTop? - Not answered. You keep an array sorted by inserting each new item at the position a binary search finds, via
splice. What's the cost of one insertion, and what dominates? - Not answered. Select every task that is really a binary search over sorted data, even if it's never called that.
- Not answered. Which statements about binary search are true? Select all that apply.
- Not answered. Worst case, how many comparisons (halving steps) does binary search make on a sorted array of
n = 1,000,000items? Enter a whole number. - Not answered. The list grows from 1,000,000 to 2,000,000 items. How many additional worst-case comparisons does binary search now need? Enter a whole number.