1 votes 1 votes Algorithms algorithms identify-function made-easy-test-series + – Himanshu1 asked Dec 4, 2015 • retagged Jul 7, 2022 by Lakshman Bhaiya Himanshu1 643 views answer comment Share Follow See all 0 reply Please log in or register to add a comment.
Best answer 3 votes 3 votes From i=1 to n "if(j<i)" this condition true till only for every j=i-1 times So, P=0+1+2....+(n-1)=n(n-1)/2 and for i=(n+1) to (2n-1) "if(j<i)" This will true n-1 times P= n(n-1) Total value of P=n(n-1)+(n(n-1))/2=3(n2-n)/2 Avdhesh Singh Rana answered Dec 4, 2015 • selected Dec 4, 2015 by Himanshu1 Avdhesh Singh Rana comment Share Follow See all 2 Comments See all 2 2 Comments reply Gate Mm commented Dec 17, 2015 reply Follow Share p=p+1 runs 0,1,2,3,3 which is close to B bt not exactly B plz chck n=6 i=1 2 3 4 5 j always runs 1 to 3 for each val of i 0 votes 0 votes Avdhesh Singh Rana commented Dec 19, 2015 reply Follow Share All options are wrong. I'm not saying B option is correct. 0 votes 0 votes Please log in or register to add a comment.
0 votes 0 votes Let's calculate number of pairs (j,i) such that j<i. (1,2),(1,3),...,(1,2n) = Total 2n-1 pairs. (2,3),(2,4),...,(2,2n) = Total 2n-2 pairs. . . . (n,n+1)(n,n+2),...,(n,2n) = Total 2n-n = n pairs. Therefore Total pairs overall = n(n+2n-1)/2. Aghori answered Dec 12, 2016 • edited Dec 13, 2016 by Aghori Aghori comment Share Follow See all 4 Comments See all 4 4 Comments reply Rajesh Raj commented Dec 13, 2016 reply Follow Share i think u calculated it for (i<j) isn't it ? 0 votes 0 votes Aghori commented Dec 13, 2016 reply Follow Share I've edited. I calculated j<i only. 0 votes 0 votes Rajesh Raj commented Dec 13, 2016 reply Follow Share but in the code for each i<2n, j is running till n so for i=1 , j should be vary upto n plss correct me if i m wrong ? 0 votes 0 votes Aghori commented Dec 13, 2016 reply Follow Share Bro, I've written (j,i) j before i. And j is UpTo n. Yes. Right. i<2n I've taken I<=2n. 0 votes 0 votes Please log in or register to add a comment.