Algorithms and Data Structures · Senior · Question 37 of 75

A virtualized list renders only visible rows of 100,000 items with different heights. How does it find the first visible row quickly?

Explanation

Prefix sums of row heights are sorted, so binary search finds the row at scrollTop in O(log n). Walking is O(n) per scroll; dividing by an average drifts when heights vary.

Further reading

Problem with a question

Algorithms and Data Structures · Senior · question 37

Test yourself

Take the Algorithms and Data Structures · Senior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz