Bubble Sort
1. How many iterations of the outer loop and how many total iterations of the inner loop are required to sort the following array using the optimized Bubble Sort algorithm?
A = [-4, -9, -1, 8, -9, 4]
A = [-4, -9, -1, 8, -9, 4]
2. Consider the following array:
A = [8, 7, -2, 4, 1]
Which of the following represents the array after the 3rd iteration of the algorithm, assuming an ascending-order Bubble Sort?
A = [8, 7, -2, 4, 1]
Which of the following represents the array after the 3rd iteration of the algorithm, assuming an ascending-order Bubble Sort?
3. Consider the following array:
A = [8, 7, -2, 4, 1]
How many swaps occur during the 1st iteration of the outer loop?
A = [8, 7, -2, 4, 1]
How many swaps occur during the 1st iteration of the outer loop?
4. Consider the following array:
A = [-10, 100, -1000, 2, 0, -1]
How many iterations of the outer loop are required to sort this array using the optimized Bubble Sort algorithm?
A = [-10, 100, -1000, 2, 0, -1]
How many iterations of the outer loop are required to sort this array using the optimized Bubble Sort algorithm?
5. Consider the array A = [3, 1, 2]. How many comparisons and swaps occur during the first complete pass of ascending Bubble Sort?
6. Consider the array A = [4, 3, 2, 1]. What is the array after the second complete pass of ascending Bubble Sort?
7. Which condition correctly identifies when two adjacent elements should be swapped for an ascending Bubble Sort?
8. If a Bubble Sort pass makes no swaps, what can be concluded about the array for that pass?
9. Why does Bubble Sort require fewer comparisons in later passes when the sorted portion at the end is excluded?