0 votes 0 votes Consider this array [ 2,2,2,1,1,1,1,1,0,0,0 ]. Find the min. no. of swaps needed for this array to be sorted in asc. order using: a) bubble sort b) insertion sort Algorithms algorithms sorting + – Tuhin Dutta asked Dec 6, 2017 Tuhin Dutta 523 views answer comment Share Follow See all 3 Comments See all 3 3 Comments reply Ashwin Kulkarni commented Dec 6, 2017 reply Follow Share is it 39? I got 39 in both. solved roughly. 0 votes 0 votes Tuhin Dutta commented Dec 6, 2017 reply Follow Share no 47 0 votes 0 votes raja11sep commented Aug 13, 2021 reply Follow Share Number of swaps = Number of inversions = (3*8+5*3) = 39. For both. 0 votes 0 votes Please log in or register to add a comment.
0 votes 0 votes Number of swaps in both case will be always same, as the idea is the same in both of the case, the difference lies in how it is implemented. A detailed explanation can be found here: https://stackoverflow.com/questions/17270628/insertion-sort-vs-bubble-sort-algorithms Execution to count the swaps: Insertion Sort: https://ide.geeksforgeeks.org/lSl4Y8miIS Bubble Sort run: https://ide.geeksforgeeks.org/SbwqkTU2d1 sandeep007734 answered Dec 6, 2017 sandeep007734 comment Share Follow See 1 comment See all 1 1 comment reply suvradip das commented Jan 13, 2020 reply Follow Share Bubble Sort : 47 Insertion Sort : 39 0 votes 0 votes Please log in or register to add a comment.