Given an array, we need to calculate the variance and standard deviation of the elements of the array.
Input : arr = [1, 2, 3, 4, 5] Output : Variance = 2 Standard Deviation = 1 Input : arr = [7, 7, 8, 8, 3] Output : Variance = 3 Standard Deviation = 1
We have discussed program to find mean of an array.
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.
Below is the implementation of above approach:
Variance: 21704 Standard Deviation: 147.323
Time complexity of the program is O(n).
This article is contributed by Himanshu Ranjan. 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 write comments if you find anything incorrect, or you want to share more information about the topic discussed above.
- Variance and standard-deviation of a matrix
- Program to implement standard deviation of grouped data
- Program for Mean Absolute Deviation
- Program to implement standard error of mean
- Find combined mean and variance of two series
- Program for product of array
- Program for array rotation
- Program to check if an Array is Palindrome or not
- Program to reverse an array using pointers
- Program to print Sum of even and odd elements in an array
- C++ Program to print an Array using Recursion
- Program to calculate Bitonicity of an Array
- Program for multiplication of array elements
- Program to check if an array is bitonic or not
- Program to print Sum Triangle for a given array