我在算法期末考试中遇到了这个问题(现在已经完成):
给定一个(x,y)点集P,令M(P)为给定以下P上的偏序关系时的maximal点集合:
(x,y) < (x',y') if and only if x < x' and y < y'.
因此:
M({(0,0),(1,1)})={(1,1)}
M({(0,0),(0,1),(1,0)})={(0,1),(1,0)}
提供计算M(P)的算法,时间复杂度为O(nh),O(n log n)和O(n log h)(其中n = |P|,h = |M(P)|)
我的O(nh)算法:
Declare M as a set of points
foreach p in P:
addP = true
foreach m in M:
if(p < m):
addP = false
break
if(m < p):
M.remove(m)
if(addP)
M.add(p) //doesn't add if M contains p
return M
我的O(n log n)算法:
Declare M as a set of points
Sort P in reverse lexicographic order
maxY := -inf
foreach p in P:
if(p.y > maxY):
M.add(p)
maxY = p.y
return M
什么是 O(n log h) 算法?
我的直觉是它是第一个算法的修改版,但使用了一些巧妙的数据结构(可能是二叉树的修改版),不需要为每个点扫描。
是否有这样的算法适用于一般的 偏序集?
这将在给定顶点列表和常量时间查找是否存在两个给定顶点之间的有向路径的情况下找到任何有向树的叶子。
p
。如果没有这样的点-结束算法。否则:将p
添加到最大集合中,并重复此过程。 - amit