ISRO | ISRO CS 2017 – May | Question 48
The number of swappings needed to sort the numbers 8, 22, 7, 9, 31, 5, 13 in ascending order, using bubble sort is
(A)
11
(B)
12
(C)
13
(D)
10
Answer: (D)
Explanation:
1: 8, 7, 9, 22, 5, 13, 31 = 4 swaps
2: 7, 8, 9, 5, 13, 22, 31 = 3 swaps
3: 7, 8, 5, 9, 13, 22, 31 = 1 swap
4: 7, 5, 8, 9, 13, 22, 31 = 1 swap
5: 5, 7, 8, 9, 13, 22, 31 = 1 swap
Total 10 swaps are required to sort the array.
Hence Option(D) is the correct answer.
Quiz of this Question
Please comment below if you find anything wrong in the above post
Last Updated :
21 Mar, 2018
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...