Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

35.what is the big-O notation in terms of i public static int compute(int n) f e

ID: 3912088 • Letter: 3

Question

35.what is the big-O notation in terms of i public static int compute(int n) f eter n, of the below method? int total 0; for (int i 1;i 1)k total++;) return total; 36.The following method finds the smallest factor above 1 for a given number n, tusing any division or multiplication. (A factor for a number n is an integen that divides into n exactly. Example: factors of 45 are 1, 3, 5, 9, 15, 45) Using big-O notation in terms of its parameter n, how much time does this method take? public static int findFactor(int n) ( inti 1; intj-n-1 int p-j;//invariant: p i*j while (p!- n&& i n) (j- p;) return pn?i:n;

Explanation / Answer

Q 36) In the given question the for loop runs n times where as while loop runs (n-1) times.

So time complexity is: x*(x-1) or O(x^2).

Q 37) In the given question the loop runs single time i.e it is not nested so big O is n

O(n)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote