Practice question · Multiple choice
Summing a million floating-point numbers from smallest to largest is more accurate than from largest to smallest. Why does order affect a sum?
Hints
- The gap between representable floats grows with magnitude. Ask what that does to a small addend.
- Add 1 to 10¹⁷ in floating point. What do you get?
Show the answer
C. Because adding a tiny number to a huge total can round away entirely
Why
Once the total is large, the spacing between representable values exceeds the small addends and they vanish on contact. Ascending order keeps the accumulator small for as long as possible, and Kahan summation goes further by tracking the discarded remainder explicitly.
Practise Searching and Sorting
The app has 6 more questions on this lesson, and keeps your place in the course. Mathematics I is free to start.
More questions on Searching and Sorting
- Complete the reason binary search is fast.
- Floating-point arithmetic gives 0.1 + 0.2 ≠ 0.3 on essentially every computer. Why does a well-designed…
- A sorted list holds 1,048,576 items, which is 2 to the power 20. How many halvings does binary search need to…
- A sorted list holds 64 items. Binary search halves the range at each comparison. In the worst case, how many…
- Order the steps of merge sort on a list.
- Sort each situation by the search method it calls for.