Question

In: Computer Science

Bubble Sort is performed on an array with values [6, 1, 2, 0, 5, 4]. What...

Bubble Sort is performed on an array with values [6, 1, 2, 0, 5, 4]. What are the array values after two passes of the Bubble Sort? The largest value in the array is moved to the correct location after each pass.

Solutions

Expert Solution

[1, 0, 2, 4, 5, 6]

Explanation:
-------------
Bubble sort
Original list is [6, 1, 2, 0, 5, 4]
Iteration: 1
   > Swap 6 and 1, since they are not in correct order. Now, the list becomes [1, 6, 2, 0, 5, 4]
   > Swap 6 and 2, since they are not in correct order. Now, the list becomes [1, 2, 6, 0, 5, 4]
   > Swap 6 and 0, since they are not in correct order. Now, the list becomes [1, 2, 0, 6, 5, 4]
   > Swap 6 and 5, since they are not in correct order. Now, the list becomes [1, 2, 0, 5, 6, 4]
   > Swap 6 and 4, since they are not in correct order. Now, the list becomes [1, 2, 0, 5, 4, 6]
   > 5 swaps happened in this iteration
   > List after iteration 1 is [1, 2, 0, 5, 4, 6]

Iteration: 2
   > Swap 2 and 0, since they are not in correct order. Now, the list becomes [1, 0, 2, 5, 4, 6]
   > Swap 5 and 4, since they are not in correct order. Now, the list becomes [1, 0, 2, 4, 5, 6]
   > 2 swaps happened in this iteration
   > List after iteration 2 is [1, 0, 2, 4, 5, 6]

so, list after two passes of bubble sort is [1, 0, 2, 4, 5, 6]

Related Solutions

6 5 4 5 0 0 13 48 6 1 0 7 2 0 1 1...
6 5 4 5 0 0 13 48 6 1 0 7 2 0 1 1 0 2 11 5 11 27 4 0 6 Create Standard Deviation Chart (Normal Distribution Curve)
Use counting sort, sort the following numbers: 4, 2, 5, 4, 2, 3, 0, 2, 4,...
Use counting sort, sort the following numbers: 4, 2, 5, 4, 2, 3, 0, 2, 4, 3
5. (20 marks) Write a recursive Bubble Sort algorithm that takes an array A of n...
5. Write a recursive Bubble Sort algorithm that takes an array A of n numbers as input. Analyze its time complexity using a recursion tree. Implement your algorithm in Java
x (Bins) frequency 0 0 1 0 2 0 3 2 4 5 5 8 6...
x (Bins) frequency 0 0 1 0 2 0 3 2 4 5 5 8 6 13 7 33 8 42 9 66 10 77 11 105 12 103 13 110 14 105 15 84 16 70 17 51 18 40 19 27 20 27 21 15 22 5 23 7 24 2 25 2 26 1 27 0 28 0 29 0 30 0 (7) On the Histogram worksheet, calculate all frequencies of the distribution using the table shown....
exampleInput.txt 1 2 3 0 2 3 4 0 1 3 5 0 1 2 6...
exampleInput.txt 1 2 3 0 2 3 4 0 1 3 5 0 1 2 6 1 5 6 8 2 4 6 7 3 4 5 9 10 5 8 9 4 7 9 6 7 8 6 How can I detect when 'cin' starts reading from a new line. The amount of numbers in each row is unknown. I need them in type 'int' to use the data.
Given the unordered array: [0] [1] [2] [3] [4] [5] [6] [7] [8] P E R...
Given the unordered array: [0] [1] [2] [3] [4] [5] [6] [7] [8] P E R Y I H J L S Suppose this array were being sorted using the quick sort algorithm from the course content, into ASCENDING order, with the left-most item as the pivot value. List the letters in the resulting array, in order AFTER the FIRST PARTITIONING. [0] [1] [2] [3] [4] [5] [6] [7] [8]
out of the following four: 1.Bubble sort 2. Insertion sort 3. Quicksort 4. Mergesort a. Which...
out of the following four: 1.Bubble sort 2. Insertion sort 3. Quicksort 4. Mergesort a. Which sorting methods perform best and worst for data sizes ≥ 25,000 when the input data is random? b. Which sorting methods perform best and worst for data sizes ≥ 25,000 when the input data is 90% sorted? c. Which sorting methods perform best and worst for data sizes ≥ 25,000 when the input data is reverse sorted? d. Which sorting methods perform best and...
out of the following four: 1.Bubble sort 2. Insertion sort 3. Quicksort 4. Mergesort a. Which...
out of the following four: 1.Bubble sort 2. Insertion sort 3. Quicksort 4. Mergesort a. Which sorting methods perform best and worst for data sizes ≥ 25,000 when the input data is random? b. Which sorting methods perform best and worst for data sizes ≥ 25,000 when the input data is 90% sorted? c. Which sorting methods perform best and worst for data sizes ≥ 25,000 when the input data is reverse sorted? d. Which sorting methods perform best and...
What are the values ​​of Raysut Cement Company? 1- 2- 3- 4- 5- 6- The direct...
What are the values ​​of Raysut Cement Company? 1- 2- 3- 4- 5- 6- The direct beneficiaries or customers and their needs? 1- 2- 3- 4- 5- 6-
ASSEMBLY PROGRAM!!! QtSpim Sorting Data Add the Bubble Sort to minMaxArray.asm to sort the array into...
ASSEMBLY PROGRAM!!! QtSpim Sorting Data Add the Bubble Sort to minMaxArray.asm to sort the array into ascending order. Use the Bubble Sort algorithm from the lecture. You can use either Base Addressing or Indexed Addressing for the arrays. For this assignment, make sure you prompt the user for the numbers. Do not hard-code them in the data section. NOTE: Declare the array last in the Data section.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT