1 votes 1 votes Can anyone explain me the answer in detail? Algorithms ace-test-series time-complexity + – phaneendrababu asked Sep 20, 2018 retagged Jun 18, 2022 by makhdoom ghaya phaneendrababu 690 views answer comment Share Follow See all 18 Comments See all 18 18 Comments reply Show 15 previous comments phaneendrababu commented Sep 20, 2018 reply Follow Share In first two passes we will get the larger elements at the end of the array so it wil take (n-1)+(n-2) comparisons. (n-1)+(n-2)=O(n)+O(n). If the condition is not satisfying the first pair i.e last two elements after two passes then the condition wil never be satisfied for the remaining pairs .So we can stop the bubble sort after two passes. 1 votes 1 votes S Sarva Bhowma commented Sep 20, 2018 reply Follow Share for(i=0;i<2;i++){ for(j=0;j<n;j++){ ....... } } 1 votes 1 votes srestha commented Sep 20, 2018 reply Follow Share thanks 0 votes 0 votes Please log in or register to add a comment.
0 votes 0 votes The answer is O(n) as we just need to run one loop and check for condition x+y>100 condition.There is no need to sort the array we just need to meet the x+y>100 condition.Option A is correct.Please correct me if I am wrong. sripo answered Nov 10, 2018 sripo comment Share Follow See all 0 reply Please log in or register to add a comment.