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
PayPal Gateway not configured
PayPal Gateway not configured