Given an array arr[] consisting of N integers, the duty is to seek out the mean of the array fashioned by the merchandise of unordered pairs of the given array.
Examples:
Enter: arr[] = {2, 5, 7}
Output: 19.67
Clarification:
Product of unordered pairs of array arr[] are 2 * 5 = 10, 2 * 7 = 14 and 5 * 7 = 35.
Subsequently, the resultant array of product of pairs is {10, 14, 35}.
Imply of the array of product of pairs is 59/3 = 19.67Enter: arr[] = {1, 2, 4, 8}
Output: 11.67
Clarification:
Product of unordered pairs of array arr[] are 1 * 2 = 2, 1 * 4 = 4, 1 * 8 = 8, 2 * 4 = 8, 2 * 8 = 16, 4 * 8 = 32.
Subsequently, the resultant array of product of pairs is {2, 4, 8, 8, 16, 32}.
Imply of the array of product of pairs is 70/6 i.e., 11.67
Naive Strategy: The best strategy to unravel the issue is to generate all possible pairs of array pairProductArray[] i.e., array fashioned by the product of unordered pairs of the array arr[]. Then, discover the mean of the pairProductArray[]. Observe the steps under to unravel the issue:
 Generate all doable pairs of the array arr[] and retailer their merchandise in pairProductArray[].
 Initialize a variable sum to retailer the sum of the weather of pairProductArray[].
 Divide the variable sum with the dimension of pairProductArray[] to get the required imply.
 Lastly, print the worth of the sum because the resultant imply.
Under is the implementation of the above strategy:
C++

Time Complexity: O(N^{2})
Auxiliary House: O(N^{2})
Environment friendly Strategy: The thought is to make use of the truth that each ingredient arr[i] is multiplied with each ingredient arr[j] which is on the appropriate aspect of the ingredient arr[i], extra formally ingredient at index i is multiplied to all the weather positioned at index j such that j > i. Observe the steps under to unravel the issue:
 Create a suffix sum array suffixSumArray[] for the given array arr[].
 Initialize variable res to retailer the sum of product pairs of array arr[].
 Iterate array arr[] and for every place i incrementing res with arr[i]*suffixSumArray[i+1].
 Divide the variable res with N*(N – 1)/ 2 which is the variety of doable merchandise.
 Lastly, print the worth of res because the resultant imply.
Under is the implementation of the above strategy:
C++

Time Complexity: O(N)
Auxiliary House: O(N)
Consideration reader! Don’t cease studying now. Pay money for all of the essential DSA ideas with the DSA Self Paced Course at a studentfriendly worth and grow to be trade prepared.
When you like GeeksforGeeks and wish to contribute, you may as well write an article utilizing contribute.geeksforgeeks.org or mail your article to [email protected] See your article showing on the GeeksforGeeks foremost web page and assist different Geeks.
Please Enhance this text when you discover something incorrect by clicking on the “Enhance Article” button under.