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) : Combined Medical Herbal Center Wants Create Prescription Database Keep Track Medics Patien Q31072715 . . . .(Solved) : Combined Medical Herbal Center Wants Create Prescription Database Keep Track Medics Patien Q31072715 . . . .

<p>A combined medical and herbal center wants to create a<em>Prescription</em> database to keep track of its medics,patients, herbal medicine, diagnosis, and herbal prescriptions. Forsimplicity, both a herbal <strong>medic</strong> and a<strong>patient</strong>