HW2 1. Give the Big-Oh Complexity of the following code fragments (2 pts) a. for( int i = 0; i

1 answer below »
Look at attached file


HW2 1. Give the Big-Oh Complexity of the following code fragments (2 pts) a. for( int i = 0; i < n;="" i++="" )="" for(="" int="" j="0;" j="">< i;="" j++="" )="" sum++;="" b.="" for(="" int="" i="0;" i="">< n;="" i++="" )="" sum++;="" for(="" int="" j="0;" j="">< n; j++ ) sum++; 2. write a recursive function that models the following recurrence relation (1.5pt) t( n ) = t( n / 2 ) + n, t(0)=t(1)=1 3. write a recursive method that returns the number of 1s in the binary representation of n. use the fact that this number equals the number of 1s in the representation of n/ 2, plus 1, if n is odd. (1.5pt) n;="" j++="" )="" sum++;="" 2.="" write="" a="" recursive="" function="" that="" models="" the="" following="" recurrence="" relation="" (1.5pt)="" t(="" n="" )="T(" n="" 2="" )="" +="" n,="" t(0)="T(1)=1" 3.="" write="" a="" recursive="" method="" that="" returns="" the="" number="" of="" 1s="" in="" the="" binary="" representation="" of="" n.="" use="" the="" fact="" that="" this="" number="" equals="" the="" number="" of="" 1s="" in="" the="" representation="" of="" n/="" 2,="" plus="" 1,="" if="" n="" is="" odd.="">
Answered Same DayFeb 23, 2021

Answer To: HW2 1. Give the Big-Oh Complexity of the following code fragments (2 pts) a. for( int i = 0; i

Sonu answered on Feb 23 2021
150 Votes
1. Solution 1
a. We need to find how many times the value of sum is changing and that would be our
answer.
0 + 1 + 2 + 3 + ………. + n-1 = n(n-1)/2
If we now take Asymptotic notation of the above term
O((n^2 - n)/2) ⇒ O(n^2)
Ans: O(n^2)
b. We need to find how many times the value of sum is...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here