Question: Please see below for my question and answer. Please correct me if I'm wrong What is the big-O performance estimate of the following function? int

Please see below for my question and answer. Please correct me if I'm wrong

What is the big-O performance estimate of the following function? int f (n) { int sum = 0; --------------------> Setting sum to "0" with a 1-time operation. So, O(1) for (i = 0; i < n; i = i + 10) --------------------> i = 0 = O(1), i < n = O(n), i = i + 10 = O(1). Since O(1) < O(n), = O(n) sum += i; --------------------> Every loop produces this iteration. So, O(1) return sum; -------------------> O(1) } // end f

Since O(1) < O(n) = total time is O(n)

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!