At the 2020 Tokyo Olympics, there are n athletes competing in the 100m sprint. The organizers have planned for exactly 5 heats, with each heat containing n=5 athletes. The nish times of each heat will be stored in a min-heap: H1;H2;H3;H4;H5. For example, H1 is a min-heap containing the nish times of the athletes from the rst heat. Once the heats are complete, the organizers must determine the top 40 athletes who will continue to the quarter- nals. Design an algorithm that takes as input the ve heaps, and outputs the best 40 nish times, over all athletes, regardless of heat. Call your algorithm Top40(H1, H2, H3, H4, H5) and provide the pseudo-code. Justify the runtime of O(log n).
At the 2020 Tokyo Olympics, there are n athletes competing in the 100m sprint. The organizers
have planned for exactly 5 heats, with each heat containing n=5 athletes. The nish times of each heat will
be stored in a min-heap: H1;H2;H3;H4;H5. For example, H1 is a min-heap containing the nish times
of the athletes from the rst heat. Once the heats are complete, the organizers must determine the top 40
athletes who will continue to the quarter- nals. Design an
and outputs the best 40 nish times, over all athletes, regardless of heat. Call your algorithm Top40(H1,
H2, H3, H4, H5) and provide the pseudo-code. Justify the runtime of O(log n).
The logic is simple take the minimum element from each heap and then compare the values and whichever value minimum then remove the element from the heap and then reheap the remaining elements. Follow this process till you complete the all 40 member
Step by step
Solved in 2 steps