In the bubble sort algorithm larger values gradually "bubble" their way upward to the top of the array while the smaller
Posted: Sun May 15, 2022 11:51 am
In the bubble sort algorithm larger values gradually "bubble" their way upward to the top of the array while the smaller values sink to the bottom. The bubble sort makes several passes through the array. On each pass, successive pairs of elements are compared. If a pair is in increasing order (or the values are identical), we leave the values as they are. If a pair is not in order, their values are swapped in the array. You can use the swap function we did in class. a. Write a program that bubble sorts an array of 20 random integers from 0 - 100. The bubble sort procedure should be performed within a regular function that takes the array as an argument, and either returns the sorted array or replaces (with pass by reference) the original array. b. Keep track of the number of swaps made to sort the array. Part II: Use the Law of Large Numbers (run the game 50,000 times). c. Calculate the average number of swaps it takes to sort a 20-element array using the law of large numbers.