6 kyu

Variance in a array of words

Description:

Consider X as the aleatory variable that count the number of letters in a word. Write a function that, give in input an array of words (strings), calculate the variance of X. Max decimal of the variance : 4.

Some wiki: Variance , Aleatory variable

Example:

Consider "Hello" and "World":

X is { 5 } with P(X = 5) = 1 because the two words have the same length.
So E[X] = 5 x 1 = 5 and the standard formula for variance is E[(X - u)^2] so 1 x (5-5)^2 = 0 or you can calculate with the other formula E[X^2] - E[X]^2 = 5^2 x 1 - 5^2 = 0

Consider "Hi" and "World":

X is { 2, 5 } with P(X = 5) = 1/2 and P(X = 2) = 1/2.
So E[X] = 5 x 1/2 + 2 x 1/2 = 3.5 and the standard formula for variance is E[(X - u)^2] so 1/2 x (2-3.5)^2 + 1/2 x (5 - 3.5)^2 = 2.25 or you can calculate with the other formula E[X^2] - E[X]^2 = (5^2 x 1/2 + 2^2 x 1/2) - 3.5^2 = 2.25

Statistics
Algorithms
Data Science

More By Author:

Check out these other kata created by MicheDev

Stats:

CreatedSep 11, 2015
PublishedSep 12, 2015
Warriors Trained862
Total Skips50
Total Code Submissions1931
Total Times Completed435
Python Completions435
Total Stars29
% of votes with a positive feedback rating87% of 76
Total "Very Satisfied" Votes59
Total "Somewhat Satisfied" Votes14
Total "Not Satisfied" Votes3
Total Rank Assessments14
Average Assessed Rank
6 kyu
Highest Assessed Rank
6 kyu
Lowest Assessed Rank
8 kyu
Ad
Contributors
  • MicheDev Avatar
  • raulbc777 Avatar
  • hobovsky Avatar
  • akar-0 Avatar
Ad