Find the largest k numbers in k arrays stored across k machines

前端 未结 7 889
悲哀的现实
悲哀的现实 2020-12-28 19:34

This is an interview question. I have K machines each of which is connected to 1 central machine. Each of the K machines have an array of 4 byte numbers in file. You can use

7条回答
  •  没有蜡笔的小新
    2020-12-28 19:58

    1. Let the machines find the out k largest elements copy it into a datastructure (stack), sort it and pass it on to the Central machine.
    2. At the central machine receive the stacks from all the machine. Find the greatest of the elements at the top of the stacks.
    3. Pop out the greatest element form its stack and copy it to the 'TopK list'. Leave the other stacks intact.
    4. Repeat step 3, k times to get Top K numbers.

提交回复
热议问题