1,774 views
2 votes
2 votes

Consider the following code which sort all elements of an array ‘A’ in descending order.

Which of the following will represents correct value of X, Y, Z in above code for selection sort?
a.   i > 0, K > 0, a[K] > a[max]

b.   i > 0, K < 0, a[K] < a[max]

c.   i < 0, K > 0, a[K] > a[max]

d.   i > 0, K > 0, a[K] < a[max]
 

Answer is a

I think answer should be d. As it is given in the question that this algorithm will sort all the element of the array in the descending order but by using option a it is aranging in ascending order.

And option D is doing what question is saying.

2 Answers

0 votes
0 votes
Yes the answer should be D. According to A, If a[k] value is greater than a[max] then no swapping is needed as it indicates it is in descending order.
0 votes
0 votes
Answer is d as in every pass of selection sort we have to put one element in its correct place  BC!!!

Related questions

0 votes
0 votes
2 answers
1
naveen81 asked Jan 30, 2017
710 views
a. i>0,K>0, a[K] a[max]b. i>0,K<0, a[K]< a[max]c. i<0,K>0, a[K] a[max]d. i>0,K>0, a[K]< a[max]
7 votes
7 votes
3 answers
2
ajit asked Sep 20, 2015
9,697 views
How many comparisons are needed to sort an array of length $5$ if a straight selection sort is used and array is already in the opposite order?$1$$10$$15$$20$
1 votes
1 votes
1 answer
3
mcjoshi asked Aug 23, 2016
740 views
Why option (A) is not correct ?
3 votes
3 votes
2 answers
4