Middle — Senior
Why is it not enough to just calculate the median on each worker and then combine?
sobes.tech AI
Answer from AI
The median is the value that divides an ordered data set into two equal parts. If you simply calculate the median on each worker (part of the data), and then combine these medians, the resulting value will not be the exact median of the entire set.
The reason is that the local median of a subset does not account for the data distribution in other parts. For example, if one worker's median is 10, and another's is 100, combining these two numbers does not reflect the median of the entire combined set.
To accurately compute the median in distributed systems, algorithms are usually used that:
- collect data distribution statistics (e.g., histograms or quantile slices);
- employ approximate median calculation algorithms (e.g., based on samples);
- or gather all data in one place for exact calculation (if possible).
Thus, simply merging local medians does not yield the correct result due to the lack of a global data distribution context.