Open In App
Related Articles

ISRO | ISRO CS 2008 | Question 75

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report
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? (A) 1 (B) 5 (C) 10 (D) 20

Answer: (C)

Explanation: Consider the array: 5 4 3 2 1 1st iteration will compare 4 numbers with the 5 2nd iteration will compare 3 numbers with the 4 3rd iteration will compare 2 numbers with the 3 4th iteration i will compare 1 number with the 2 So, the total number of comparisons is 4 + 3 + 2 + 1 = 10 It can be viewed as the sum of the sequence of the first (n-1) numbers starting by 1 S = ((1 + (n-1) )*(n-1) )/2 S = 10 Option (C) is correct.

Quiz of this Question

Last Updated : 13 Jun, 2018
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads