Question: A friend majoring in finance wants to implement an algorithm for computing the prefix variance of a sequence dataset of n real - valued numbers

A friend majoring in finance wants to implement an algorithm for computing the
prefix variance of a sequence dataset of n real-valued numbers a0,a1,dots,an-1, defined as the
sequence of n real-valued numbers widehat()02,widehat()12,dots,widehat()n-12 such that t=0,1,dots,n-1,
widehat()t2=1t+1i=0t(ai-(1t+1j=0taj))2.
Our friend, having found the following two algorithms, PREFIXVARIANCE1 and PREFIXVARIANCE2,
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,dots,n-1, and output an n-element array B such that each element
B[i]=widehat()i2 for all i=0,1,dots,n-1 with the corresponding prefix variance evaluation of the
sequence in A.
Algorithm 1 PREFIXVARIANCE1(A)
Blarr new array of n numbers
for tlarr0 to n-1 do
vlarr0
for ilarr0 to t do
zlarr0
for jlarr0 to t do
zlarrz+A[j]
zlarrzt+1
dlarrA[i]-z
vlarrv+d**d
B[t]larrvt+1
return B
Algorithm 2 PREFIXVARIANCE2(A)
Blarr new array of n numbers
for tlarr0 to n-1 do
zlarr0
for ilarr0 to t do
zlarrz+A[i]
zlarrzt+1
vlarr0
for ilarr0 to t do
dlarrA[i]-z
vlarrv+d**d
B[t]larrvt+1
return B
1) Give time and space characterization using big-oh for prefixvariance1
2) Give time and space characterization using big -oh for prefixvariance 2
3) which one do you reccomend based on this and why
 A friend majoring in finance wants to implement an algorithm for

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!