CodePudding user response: Before the bubble sort k loops CodePudding user response:
Tree, can consider to use KD - first pretreatment, get the maximum value, and the complexity of O (n), and then, its K neighbor, because is one-dimensional, complexity of O (LGN * K) CodePudding user response:
Incomplete fast line can be not? CodePudding user response:
Can consider after discretization is mapped to the 1-100000, and then use the first K persistable line query tree big (persistable segment tree introduction to the first K big range) CodePudding user response:
Big tree divided into interval query and the first k value problem, logN time complexity CodePudding user response:
I don't know what is the good q ~ chairman tree naked? CodePudding user response:
The reference 3 floor yyfhz response: incomplete fast row can not? Yes, I probably have done the experiment, millions more than the amount of data, change the row after the fastest (i.e., said on the third floor of the incomplete fast row), faster than President tree (method) of 6th floor, more quickly than the heap sort (surprise unexpectedly a few floor before no one mentioned the heap sort), may be because the chairman tree space complexity is higher, so time consuming, Method is fast row about cut in half and time complexity LogN * Log (N - K), space complexity is O (1) Was fast row is: The first step, grouping, the second step, the recursive row on the left, the third step, recursive row right, 3/f said that: The first step, grouping, the second step, points, if the grouping that number & lt; K, only the left recursion to find; If the group that number & gt; K, recursive only to find the right, Look and fast row about, but in fact time complexity is far less than fast row, because after every group will be cut in half and cut half ah, every time is not a time of 1/2, In addition, in addition to the modified fast, faster method, chairman of the trees and quickly cut almost half time complexity theory, and heap sort, Heap sort built reactor or faster, the key is to heap the front k sorted, after buying, she doesn't need but also waste a lot of time, the larger the k the more time to waste, CodePudding user response:
refer to 7th floor lx3275852 response: Quote: reference yyfhz reply: 3/f Incomplete fast line can be not? Yes, I probably have done the experiment, millions more than the amount of data, change the row after the fastest (i.e., said on the third floor of the incomplete fast row), faster than President tree (method) of 6th floor, more quickly than the heap sort (surprise unexpectedly a few floor before no one mentioned the heap sort), may be because the chairman tree space complexity is higher, so time consuming, Method is fast row about cut in half and time complexity LogN * Log (N - K), space complexity is O (1) Was fast row is: The first step, grouping, the second step, the recursive row on the left, the third step, recursive row right, 3/f said that: The first step, grouping, the second step, points, if the grouping that number & lt; K, only the left recursion to find; If the group that number & gt; K, recursive only to find the right, Look and fast row about, but in fact time complexity is far less than fast row, because after every group will be cut in half and cut half ah, every time is not a time of 1/2, In addition, in addition to the modified fast, faster method, chairman of the trees and quickly cut almost half time complexity theory, and heap sort, Heap sort built reactor or faster, the key is to heap the front k sorted, buy after ordering, she doesn't need but also waste a lot of time, the larger the k waste time more, Carefully wanted to think, time complexity may be wrong, not O (logN * log (N - K)), the time complexity is O (N) probably, First traversal n, n/2 for the second time, third time n/4, for the fourth time n/8, the fifth time n/16... Added up to approximately equal to 2 * n, and k value has little to do, Fast row of the first n, n, n for the third time...