10 10 votes The number of swappings needed to sort the numbers $8 , 22, 7, 9, 31, 5, 13$ in ascending order using bubble sort is $11$ $12$ $13$ $10$ Algorithms isro2017 algorithms sorting + – sh!va 13.3k views answer comment Share Follow Print See 1 comment 1 1 comment reply chetan_raghav-1995 commented May 7, 2017 reply Follow flag answer to this question is 10 0 0 replyShare Please log in or register to add a comment.
Best answer 20 20 votes Answer is 10. All swaps are in following order: 8,7,22,9,31,5,13 8,7,9,22,31,5,13 8,7,9,22,5,31,13 8,7,9,22,5,13,31 7,8,9,22,5,13,31 7,8,9,5,22,13,31 7,8,9,5,13,22,31 7,8,5,9,13,22,31 7,5,8,9,13,22,31 5,7,8,9,13,22,31 Rahul Jain25 answered May 7, 2017 Rahul Jain25 comment Share Follow See 1 comment 1 1 comment reply joshi_nitish commented May 7, 2017 reply Follow flag thanks for posting earlier otherwise i have to work on it again. 2 2 replyShare Please log in or register to add a comment.
6 6 votes if we try to simulate the array with given elements then number of swappings by applying Bubble sort =10 akash.dinkar12 answered May 7, 2017 akash.dinkar12 comment Share Follow 0 reply Please log in or register to add a comment.
5 5 votes Ans.(D)In Bubble sort, largest element moves to right. So a swapping is done, when a smaller element is found on right side.So to count number of swaps for an element, just count number of elements on right side which are smaller than it.Array is [8, 22, 7, 9, 31, 5, 13].Number of elements smaller than 8 on right side:- 2Number of elements smaller than 22 on right side:- 4Number of elements smaller than 7 on right side:- 1Number of elements smaller than 9 on right side:- 1Number of elements smaller than 31 on right side:- 2Number of elements smaller than 5 on right side:- 0Number of elements smaller than 13 on right side:- 0 Total number of swappings required is : 10Credits:Happy Mittalhttps://gateoverflow.in/14398/number-swappings-bubble-least-possible-shortcut-available?show=14400#a14400 ritiksri8 answered Jun 25, 2024 ritiksri8 comment Share Follow See all 2 Comments 2 2 Comments reply Rohit0911 commented Nov 19, 2024 reply Follow flag Does it work all time by this method?? 0 0 replyShare en23cs3011055 commented Nov 7, 2025 reply Follow flag AND this method is known as inversion of array 0 0 replyShare Please log in or register to add a comment.
3 3 votes refer https://gateoverflow.in/14398/number-swappings-bubble-least-possible-shortcut-available Azeem answered Nov 27, 2017 Azeem comment Share Follow See 1 comment 1 1 comment reply Sahil1994 commented Dec 8, 2017 reply Follow flag thx a lot 0 0 replyShare Please log in or register to add a comment.
0 0 votes d.... joshi_nitish answered May 7, 2017 joshi_nitish comment Share Follow See all 5 Comments 5 5 Comments reply Show 2 previous comments joshi_nitish commented May 7, 2017 reply Follow flag hope you got. 0 0 replyShare Rahul-gupta commented May 7, 2017 reply Follow flag 14 but not in the list 0 0 replyShare princeit07 commented Jun 26, 2021 i edited by princeit07 Jun 26, 2021 reply Follow flag ANSWER is 10. 1 1 replyShare Please log in or register to add a comment.
0 0 votes ans 14 but not in option cseBiswajit answered May 7, 2017 cseBiswajit comment Share Follow 0 reply Please log in or register to add a comment.