Question: What is the worst-case complexity of the sumUp function? class OddSum { private: int* counts; int nC; public: NameCounter (int nCounts, int nNames); int sumUp()

What is the worst-case complexity of the sumUp function?

class OddSum { private: 
 int* counts; int nC; public: 
 NameCounter (int nCounts, int nNames); 
 int sumUp() const; 
 ... 
}; 
int NameCounter::sumUp () { int sum = 0; for (int i = 1; i < nC-1; ++i) 
 for (int j = i-1; j <= i+1; ++j) sum += counts[j]; return sum; } 

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!