thanks, 总之,这个是要 extra memory, 这里有人提过不用extra memory ,我想了半 天也没想 出来,
【在 D***h 的大作中提到】 : tournament tree
x*p
7 楼
It only need two extra-memory. Start with (a1,a2) with a1>a2. Then for each a3, ..., an, compare at most twice to (a1,a2) and do corresponding replacement. So the total comparison is at most 1 + 2(n-2) = 2n - 3 = O(n).
i*9
8 楼
using tournament tree only n+ lgn -2 times of comparison are needed
each O(n).
【在 x*****p 的大作中提到】 : It only need two extra-memory. Start with (a1,a2) with a1>a2. Then for each : a3, ..., an, compare at most twice to (a1,a2) and do corresponding : replacement. So the total comparison is at most 1 + 2(n-2) = 2n - 3 = O(n).
P*l
9 楼
What is the memory requirement of your tournament? If it is n, why not use heap? It just requires n times comparison.
【在 i**9 的大作中提到】 : using tournament tree only n+ lgn -2 times of comparison are needed : : each : O(n).
g*s
10 楼
2n -3 could be 33% slower than 1.5n solution, although both O(N).
each O(n).
【在 x*****p 的大作中提到】 : It only need two extra-memory. Start with (a1,a2) with a1>a2. Then for each : a3, ..., an, compare at most twice to (a1,a2) and do corresponding : replacement. So the total comparison is at most 1 + 2(n-2) = 2n - 3 = O(n).
P*l
11 楼
Compare one round for the largest, n-1. Compare another round for the second largest, n-2.