Cody Problem 1401 asks us to sort a vector with the bubble sort algorithm and count the number of swaps needed. For example, to sort the vector [4 3 2 1] in increasing order, bubble sort requires six swaps. However, the vector can be sorted in only two swaps (4 & 1 and 3 & 2).
Write a function to determine the minimum number of swaps needed to sort a vector
Solution Stats
Problem Comments
Solution Comments
Show comments
Loading...
Problem Recent Solvers6
Suggested Problems
-
Return unique values without sorting
1026 Solvers
-
Return the first and last characters of a character array
12453 Solvers
-
Test if two numbers have the same digits
267 Solvers
-
Sum the elements in either diagonal of a square matrix
223 Solvers
-
2348 Solvers
More from this Author329
Problem Tags
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!