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

Algorithm and Complexity Analysis For each of the program segment below, identif

ID: 3752482 • Letter: A

Question

Algorithm and Complexity Analysis For each of the program segment below, identify the time complexity in Big O notation (Make sure to complete all the calculations before drawing your conclusion on the final Big O. You may want to refer to the math equation sheet to do the calculation though. 1 point each): 7. a) II Fragment 1 Il Fragment 2 sum0 for (int i-1; iknA2; i-i*2) b) sum 0 for (#1 ; i-m i i*3) sum++; sum-sum++ for (int j=n; P0j--) sum-; c) I Fragment 3 d) Fragment 4 sum = 0; for (i-n; i-1; i-) sum0; for (i-n: i: 1 ; i--) for (j-i;jken; j++) for (j = 1;jc=100; j++) sum++ sum++; e) Il Fragment 5 sum = 0; for (i-1; c10; i++) for (int j=1 ; j

Explanation / Answer

Ans:

1) O(n)

2)O(n) (n*n in same loop, so loop excution like n only.complexity won't increase)

3O(nlogn)

4)O(nlogn)

5)O(nlogn) (n*n in same loop, so loop excution like n only.complexity won't increase)

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