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?
- ✓Correct answer: Binary search over cumulative row offsets
- 2Walk the rows from the top on every scroll
- 3Divide scrollTop by the average row height
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.