Procedure: GM
Input: For each j ∈ {1 .. J}, a column {ai,j | i = TOPj .. BOTj} of nondecreasing elements, where TOPj <= BOTj are indexes of the column ranges under consideration. A number I between 1 and the total number of elements ∑j=1J(BOTj - TOPj + 1) in the columns.
Output: An Ith smallest element η, and, for each j ∈ {1..J}, a partition of each range {TOPj .. BOTj} into three new ranges, {TOPj1 .. BOTj1} with value less than η, {TOPj2 .. BOTj2} with value equal to η, {TOPj3 .. BOTj3} with value greater than η.
Set Tj = TOPj and Bj = BOTj for each j ∈ {1 .. J}.
Do forever
Set Mj = Bj - Tj + 1 for each j ∈ {1 .. J}. Set S = ∑j=1JMj.
For each j ∈ {1 .. J}, find the median element ηj of the set {ai,j | i = Tj .. Bj}. Sort the medians in nondecreasing order, so that ηj1 <= ηj2 <= .. <= ηjJ.
Compute the value k such that ∑j=1k-1Mj < S/2 <= ∑j=1kMj. Set η = ηk.
Compute for each j ∈ {1 .. J}, TTj = min{i | (TOPj <= i <= BOTj) ∧ (ai,j = η)}, and BBj = max{i | (TOPj <= i <= BOTj) ∧ (ai,j = η)}.
Set M1 = ∑j=1J(TTj - Tj) and M2 = ∑j=1J(BBj - Tj + 1).
If (M1 < I <= M2) then begin
η is an Ith smallest element. Set TOPj1 = TOPj, BOTj1 = TTj - 1, TOPj2 = TTj, BOTj2 = BBj, TOPj3 = BBj + 1, BOTj3 = BOTj.
Halt.
End
If (M1 >= I) then set Bj = TTj.
If (M2 < I) then set Tj = BBj + 1 and decrement I by M2.
End do
End GM
本文介绍了一种高效的分位数查找算法GM,该算法能在一组非递减排列的数据中找到第I小的元素,并对数据进行相应的划分。通过计算中间值、调整范围等步骤迭代实现目标元素的定位。
的列中寻找所有元素中第i小的元素&spm=1001.2101.3001.5002&articleId=5409906&d=1&t=3&u=1618ea20d78d4d6ea0af47e90a310cf3)
3880

被折叠的 条评论
为什么被折叠?



