Question
The same function runs on `N` workers. Each worker can read only its local shard of signed integers and communicate using `send`, `recv`, and `barrier`. Worker 0 returns the final answer; other workers return `None`. ```python def mode() -> int: ... def median() -> float: ... ``` ## Required results - Mode: the globally most frequent value; break ties by choosing the smaller value. - Median: the middle value for odd cardinality and the mean of the two middle values for even cardinality. - Every worker must participate in a protocol that terminates without unmatched receives or barriers. - Avoid sending complete shards when a smaller exact representation is available. Assume at least one value globally, though individual shards may be empty. Values are signed 64-bit integers. Clarify whether approximate median is permitted; the base requirement is exact. ## Staged follow-ups 1. Produce a correct aggregation baseline and estimate bytes moved. 2. Implement mode as a map/shuffle/reduce where complete counts for one key meet at one owner. 3. Design exact median using range counts, distributed selection, or partition refinement. 4. Compare payload volume with synchronization rounds under slow networking. 5. Handle skew, an unresponsive worker, retry, and deterministic recomputation. 6. Describe when a mergeable quantile sketch is preferable.