Question
Your statistician friend wants to implement an algorithm for computing the standard deviation = of a dataset of n real-valued numbers a0,a1,... ,an 1. Your
Your statistician friend wants to implement an algorithm for computing the standard deviation
=
of a dataset of n real-valued numbers a0,a1,...,an1. Your friend, having found the following two algorithms, StandardDeviation1 and StandardDeviation2, that perform the task correctly but not knowing which one to implement, is asking for your recommendation. Both algorithms take as input an n-element array A such that each element A[i] = ai for all i = 0,1,...,n1, and output a real-value v with the corresponding standard-deviation evaluation. Assume that the sqrt function takes constant time and space.
Algorithm 1 StandardDeviation1(A)
1: v 0
2: for i 0 to n1 do
3: z 0
4: for j 0 to n1 do
5: z z + A[j]
6: z z
7: d A[i]z
8: v v + dd
9: v sqrt(v/(n1))
10: return v
...............................................................
Algorithm 2 StandardDeviation2(A)
1: z 0
2: for i 0 to n1 do
3: z z + A[i]
4: z z
5: v 0
6: for i 0 to n1 do
7: d A[i]z
8: v v + dd
9: v sqrt(v/(n1))
10: return v
.................................................
(a) Give the tightest/best time characterization, Big-Oh, Big-Theta, or Big-Omega, in terms of n, of StandardDeviation1. Justify your answer.
(b) Give the tightest/best time characterization, Big-Oh, Big-Theta, or Big-Omega, in terms of n, of StandardDeviation2. Justify your answer.
(c) Which algorithm do you recommend your friend to implement? Justify your answer
i-0 j=0
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started