问题
Given an array of numbers find all such triplets that satisfy the given condition.
Condition: a[i] < a[j] < a[k]
where I < j < k
.
it is possible to solve this problem in O (n) time?
This is not home work !!!
回答1:
The size of the output (worst case) is a lower bound on the complexity.
Since there are possibly O(n^3) such triplets, the complexity cannot be O(n).
For example if the array is sorted from lowest to highest, you will have n choose 3 such triplets which is order of n^3.
If the question refers to finding the number of triplets, here is the most efficient solution I saw:
https://cs.stackexchange.com/questions/7409/count-unique-increasing-subsequences-of-length-3-in-on-log-n
来源:https://stackoverflow.com/questions/21532143/is-it-possible-to-find-all-the-triplets-in-the-given-array-for-the-o-n-time