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.
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
- Variance and standard-deviation of a matrix
- Program to implement standard deviation of grouped data
- Program for Mean Absolute Deviation
- Find combined mean and variance of two series
- Program to implement standard error of mean
- Program to find if two numbers and their AM and HM are present in an array using STL
- Maximize sum of array by reducing array elements to contain no triplets (i, j, k) where a[i] < a[j] and a[i] < a[k] and j <i < k
- Program for average of an array (Iterative and Recursive)
- Program to print Sum of even and odd elements in an array
- Program for Mean and median of an unsorted array
- Program to print product of even and odd indexed elements in an Array
- C program to count Positive and Negative numbers in an Array
- C program to find the maximum and minimum element of the array
- Program to check if an array is sorted or not (Iterative and Recursive)
- Find original array from encrypted array (An array of sums of other elements)
- Find Array formed by adding each element of given array with largest element in new array to its left
- Find an element in array such that sum of left array is equal to sum of right array
- Given a sorted array and a number x, find the pair in array whose sum is closest to x
- Split an Array A into Subsets having equal Sum and sizes equal to elements of Array B
- Program for array rotation