Given N and Standard deviation find the N elements.
Mean is average of element.
Mean of arr[0..n-1] = Σ(arr[i]) / n
where 0 <= i < n
Variance is sum of squared differences from the mean divided by number of elements.
Variance = Σ(arr[i] – mean)2 / n
Standard Deviation is square root of variance
Standard Deviation = Σ(variance)
Please refer Mean, Variance and Standard Deviation for details.
Input: 6 0 Output: 0 0 0 0 0 0 Explanation: The standard deviation of 0, 0, 0, 0, 0, 0 is 0. Also the standard deviation of 4, 4, 4, 4, 4, 4 is 0, we print any of the possible N elements. Input: 3 3 Output: 0 -3.67423 3.67423 Explanation: On calculating SD of these N elements, we get standard deviation to be 3.
If we look at the formula, we have two unknown terms one is xi and the other is mean. The main motive is to make the mean 0 so that we can get the formula for X elements. There will be two cases, one for even and one for odd.
When N is even:
To make mean of N elements 0, best way is to express N elements as -X +X -X +X …. Formula will be sqrt(summation of (x^2)/n), x2+x^2+x^2+………N terms, so formula turns out to be sqrt (N*(x^2)/N). N cancel out each other, so sqrt (x^2) turns out to be SD. So, we get the N elements as -SD +SD -SD +SD…… to get the mean 0. We need to print -SD +SD -SD +SD……
When N is odd:
The mean of N elements will be 0. So, one element will be 0 and other N-1 elements will be -X +X -X …. Formula will be sqrt(summation of (x^2)/n), x2+x^2+x^2+………N-1 terms, so formula turns out to be sqrt((N-1)*(x^2)/N), so
X= SD * sqrt(n/(n-1)). The n elements are 0 -X +X -X +X …
When SD is 0 then all elements will be same, so we can print 0 for it.
Below is the implementation of the above approach:
0 -3.67423 3.67423
- Program to find whether a no is power of two
- Program to find parity
- Find minimum number to be divided to make a number a perfect square
- Find whether a given number is a power of 4 or not
- Find Union and Intersection of two unsorted arrays
- To find sum of two numbers without using any operator
- Find day of the week for a given date
- Given a number, find the next smallest palindrome
- Find the element that appears once
- Find the largest multiple of 2, 3 and 5
- Program to find amount of water in a given glass
- Print all possible combinations of r elements in a given array of size n
- Find the maximum distance covered using n bikes
- Find if two rectangles overlap
- Find the smallest number whose digits multiply to a given number n
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.
Improved By : vt_m