THIS IS A JAVA QUESTION: [1] Find the number of comparisons needed when we apply
ID: 3733891 • Letter: T
Question
THIS IS A JAVA QUESTION:
[1] Find the number of comparisons needed when we apply Selection Sort to sort 100
distinct integers.
[2] Find the number of comparisons needed when we apply Selection Sort to sort n
distinct integers.
[3] Find the number of comparisons needed when we apply Selection Sort to sort n
distinct integers which are arranged in increasing order.
[4] Find the number of comparisons needed when we apply Selection Sort to sort n
distinct integers which are arranged in decreasing order.
Explanation / Answer
The number of comparisons for selection sort with 100 elements will be:
The first element will be compared with 99 elements, next element will be compared with 98
and so on...
99 + 98 + 97 + ....+ 1 = (99 * 100)/2 = 4950
As far as 2,3,4, are concerned the number of comparisons will be same as it doesn't matter
whether sorting is increasing or decreasing
The number of comparisons will be:
(n-1) + (n-2) + ......1 = (n-1)(n)/2
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.