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

Can someone help me with this Exception question >>>ITS URGENT PLZZZ!!! CSC 162

ID: 3827305 • Letter: C

Question

Can someone help me with this Exception question >>>ITS URGENT PLZZZ!!!

CSC 162 lecture 18: Big-O Worksheet 2 1. using big-o notation, describe the order of magnitude for each of the following segments of code. Rules Always go with the WORST if or else case. If a loop increases or decreases by a constant MULTIPLICATIVE factor for each iteration, then it is oolog2 no, i e., the update part of the for loop has a or If a loop increases or decreases by a CONSTANT AMOUNT for each iteration then its growth rate is o(n) i.e., the update part of the for loop has a or a. for(int i 1: i n: i++) b, if(happy Dog) nPartialSum i i print( bow-wow"): else if(happyCat) for (int i 1: i n: i++) for int i 1; ik 35 i++) for (int j 1 j n: j print("meow") nPartialSum +z i j; c. public int bruteForcesearch(int k, int[ array) d. for (int i 1; i n: i 37) total for (int i 0: i array length: it return i: //found it! return -1; //didn't find in array e, for (float x 27.2; x n; x log(1.3)) f. for (int i 1: i n: i for (int j 1. J n j 2) total++; total

Explanation / Answer

a)

                This for loop starting with i=1 and ends with when i=n , for every iteration it will incrementing by constant value 1,

                So, this segment of code will take O(n)

b)

                If we take worst case, it will go to else part.

                There we have a loop starting with i=1, and incrementing by constant value 1.

                This loop will iterate 34 times, at 35th time I value will become 35, where condition fails.

                So, the order is O(n), n=35 therefore O(35)

c)

                This segment have a function with parameters k and array.

There is a for loop, starting with 0 and iterate up to array’s length with incrementing by constant value 1.

If we consider array’s length is n, then the order is O(n)

d)

                This loop starting with i=1 and iterate up to where I become n.

                This loop incrementing by a constant Multiplicative factor i=i*37, that means every iteration I values like this

                First iteration – i=1

                Second iteration – i=37

                Third iteration – i=37*37 (i.e 37^2)

                Forth iteration – i=37*37*37 (i.e 37^3)

Therefor the order is O(log n) (as said in rules)