Total number of possible triangles from n numbers
If n numbers are given, how would I find the total number of possible triangles? Is there any method that does this in less than O(n^3) time? I am considering a+b>c , b+c>a and a+c>b conditions for being a triangle. Assume there is no equal numbers in given n and it's allowed to use one number more than once. For example, we given a numbers {1,2,3}, so we can create 7 triangles: 1 1 1 1 2 2 1 3 3 2 2 2 2 2 3 2 3 3 3 3 3 If any of those assumptions isn't true, it's easy to modify algorithm. Here I present algorithm which takes O(n^2) time in worst case: Sort numbers (ascending order). We will