以下是Goodrich算法教材中的伪代码算法,用于在点集中查找支配2D点,也称为查找极大值集:
Algorithm MaximaSet(S):
Input: A set,S,of n points in the plane
Output: The set, M, of maxima points in S
if n ≤ 1
then return S
Let p be the median point in S, by lexicographic (x,y)-coordinates
Let L be the set of points lexicographically less than p in S
Let G be the set of points lexicographically greater than or equal to p in S
M1 ←MaximaSet(L)
M2 ←MaximaSet(G)
Let q be the lexicographically smallest point in M2
for each point, r, in M1 do
if x(r) ≤ x(q) and y(r) ≤ y(q)
then Remove r from M1
return M1 ∪ M2
我的问题在于第10、11行的两个递归调用。我理解的是,第一个调用在第10行呼叫M1将L侧分成另一个L和G集合,然后再将下一个L分成另一个L和G集合,直到只剩一个集合,接下来的一行会对M2的G侧做同样的事情,但现在它如何与q进行比较呢?能有人帮我追踪这个算法的征服部分吗?
给定 (1,4) (2,6), ( 3,1) (4,5) (5,7) (6,9) (7,2), (8,6) (9,3)
我知道最大值集合是(6,9) (8,6) (9,3),但我卡在了究竟是怎样运用这个算法得出答案。 我用暴力法解决了这个问题。 这开始作为一个作业问题,虽然我找到了答案,但我真的需要理解这个算法,我已经尝试了两本教科书和谷歌搜索,但我想这次我需要一个人的帮助。 预先感谢,并且由于这是我第一次在堆栈上,请不要犹豫(请友好地)向我提出任何关于我提问或呈现P代码的更正。