计算点集中最大点的算法

发布于 2024-12-21 14:26:14 字数 1234 浏览 2 评论 0原文

我将这个作为算法决赛的最后一个问题(现已完成):

给定一组 (x,y) 点 P,让 M(P) 为集合给定 P 上的以下部分排序的 最大

(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) 算法?
我的直觉是,它是第一个算法的修改,但使用了一些巧妙的数据结构(可能是二叉树的修改),不需要扫描每个点。

对于一般poset是否有这样的算法?
这将在给定顶点列表的情况下找到任何有向树的叶子,并以恒定时间查找两个给定顶点之间是否存在有向路径。

I had this as the final question on an algorithms final (now completed):

Given a set of (x,y) points P, let M(P) be the set of maximal points given the following partial ordering on P:

(x,y) < (x',y') if and only if x < x' and y < y'.

Thus:

M({(0,0),(1,1)})={(1,1)}
M({(0,0),(0,1),(1,0)})={(0,1),(1,0)}

Give algorithms that compute M(P) with time complexity O(nh), O(n log n), and O(n log h) (where n = |P| and h=|M(P)|)

My O(nh) algorithm:

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

My O(n log n) algorithm:

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

What is an O(n log h) algorithm?
My intuition is that it is a modification of the first algorithm, but using some clever data structure (perhaps a modification of a binary tree) that doesn't need to be scanned through for each point.

Is there such an algorithm for a general poset?
This would find the leaves of any directed tree given a list of vertices and constant time lookup of whether there is a directed path between two given vertices.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

风透绣罗衣 2024-12-28 14:26:14

这是一个非常非常邪恶的考试问题(除非你的老师告诉你关于凸包的 O(n log h) 算法之一,在这种情况下它只是邪恶)。

该问题称为 2D MAXIMA,通常是计算几何学家的领域,因为它与计算凸包密切相关。我找不到关于最大值问题的 O(n log h) 算法的良好描述,但是 Timothy Chan 的 2D CONVEX HULL O(n log h) 算法 应该会给您带来启发。

That's a really really evil exam question (unless your instructor told you about one of the O(n log h) algorithms for convex hull, in which case it's merely evil).

The problem is called 2D MAXIMA and is the typically the domain of computational geometers because of its close relationship to computing convex hulls. I can't find a good description of a O(n log h) algorithm for the maxima problem, but Timothy Chan's O(n log h) algorithm for 2D CONVEX HULL should give you the flavor.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文