in Programming in C edited by
601 views
0 votes
0 votes

Consider the following code segment:

int j, k,n;

for(j=1;j<=n-1;j++){

   for(k=j+1;k<n;k++){

      if(A[j]> A[k]){

        A[j]=A[j+2];

      }

   }

}

(Where is the size of array A[ ] and starting index is 1)
Number of comparison made by the above code when = 84 ________.

 

given answer is 84*83/2 =3486

shouldn’t it be 83*82/2 = 3403 

in Programming in C edited by
601 views

4 Comments

I guess that we shouldnt consider only the comparisons performed by A[j]> A[k] .

What about the comparisons made in the inner and outer for loops?shouldnt we consider them too?

pls verify

 

0
0
According  to question feel it seems to get  A[j] > A[k] comparison. but if e go on language we need to calculate all .
0
0
I think, if we consider comparison in for loops, then it will be more than 84*83/2 =3486

with only considering comparison within for loops then answers will be  83*82/2 = 3403
0
0

Please log in or register to answer this question.

Related questions

0 votes
0 votes
1 answer
2