Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started