【问题标题】:is it possible to find all the triplets in the given array for the O (n) time?是否有可能在 O (n) 时间内找到给定数组中的所有三元组?
【发布时间】:2014-02-03 16:09:58
【问题描述】:

给定一个数字数组,找出所有满足给定条件的三元组。

条件:a[i] < a[j] < a[k] 其中I < j < k

有可能在O(n)时间内解决这个问题吗?

这不是家庭作业!!!

【问题讨论】:

  • 找他们还是算他们? (我相信在 O(n) 中找到它们是不可能的,因为在最坏的情况下有 O(n^3) 这样的三元组)

标签: arrays algorithm find triplet


【解决方案1】:

输出的大小(最坏情况)是复杂度的下限。

由于可能有O(n^3)个这样的三元组,复杂度不可能是O(n)。

例如,如果数组从低到高排序,您将有 n 选择 3 个这样的三元组,其顺序为 n^3。

如果问题是指找到 number 三元组,这是我看到的最有效的解决方案:

https://cs.stackexchange.com/questions/7409/count-unique-increasing-subsequences-of-length-3-in-on-log-n

【讨论】:

  • 如何计算给定数组中三元组的数量?
  • 问题的根源geeksforgeeks.org/amazon-interview-set-60-internship 问题1:给定一个数字数组,找出所有满足给定条件的三元组。问题没有正确表述?
  • 我认为它的表述不正确。 “find all the triplets”应该是“count all the triplets”或者“find the number of triplets”
  • 以及如何找到三胞胎的数量?
猜你喜欢
  • 1970-01-01
  • 2013-05-02
  • 1970-01-01
  • 2013-02-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多