Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Essentials of Database Management

Authors: Jeffrey A. Hoffer, Heikki Topi, Ramesh Venkataraman

1st edition

133405680, 9780133547702 , 978-0133405682

More Books

Students also viewed these Databases questions