Course Solutions Uncategorized (Solved) : Need Know Time Complexity Space Complexity Following Algorithm O Notation Function Findval Q28127443 . . . .

(Solved) : Need Know Time Complexity Space Complexity Following Algorithm O Notation Function Findval Q28127443 . . . .

 

I need to know the time complexity and space complexity of thefollowing algorithm, in O NOTATION:

function findValues(double[] stack, intelementSize)
{
double[] returnVal = new double[stack.Count]

if ((stack.Count == 0) || (elementSize <=0)) {

return returnVal

} else {

int step = 0
double valuesSum = 0
  

for (int i = 0; i < stack.Count; ++i)
{
valuesSum += stack[i]

if (i >= elementSize)
{
valuesSum -= stack[step]
++step

returnVal[i] = (valuesSum / elementSize)
}
else
{
returnVal[i] = (valuesSum / (i + 1))
}

}
}

return returnVal
}

Time complexity, I came up with O(n) for worst-case and O(1) forbest-case. Space complexity, I have no idea how to find, I believeit may be O(1) but I’m not sure about the array declaration in thebegnning

OR

PayPal Gateway not configured

OR

PayPal Gateway not configured

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

(Solved) : Normal Ethernet Header Contains Following Address Source Destination Mac B Source Destinat Q29804870 . . . .(Solved) : Normal Ethernet Header Contains Following Address Source Destination Mac B Source Destinat Q29804870 . . . .

<p>A normal Ethernet header contains the following address</p><p>A) source and destination MAC only</p><p>B)source and destination ports, source and destinationIP,  source and destination MAC</p><p>C)source and destination ports, source and destination IP,source and