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)
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...
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....
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.
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.
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-
C++ Program (Using 2D array and bubble sort to sort data) A company pays its salespeople...
C++ Program (Using 2D array and bubble sort to sort data) A company pays its salespeople on a commission basis.  The salespeople each receive $250 per week plus 11 percent of their gross sales for the sales period.  For example, a salesperson who grosses $5000 in sales in the period receives $250 plus 11 percent of $5000, or a total of $812.21.  Write a program (using an array of counters) determines for each salesperson their total sales, their salary and additional data points.  There...
(code in C++ language) [Code Bubble sort, Insertion sort Create a Big array with random numbers....
(code in C++ language) [Code Bubble sort, Insertion sort Create a Big array with random numbers. Record the time. Run Bubble Check time (compute the processing time) do it 100 times (random numbers) Take the average Insertion: Compare] (some explanations please)
Single data values (in hours): 3, 1, 4, 5, 5, 2, 2.5, 3.5, 4, 4.5, 0,...
Single data values (in hours): 3, 1, 4, 5, 5, 2, 2.5, 3.5, 4, 4.5, 0, 2, 2, 2.5, 3.5, 4, 4, 4, 4, 2, 3.5, 3.5, 2, 3, 4, 4, 3, 3, 3, 1 Claim: It was found that the mean time spent watching TV daily was 4 hours. A researcher claims that he believes the mean time spent watching TV is truly lower. The mean time spent watching TV daily is less than 4 hours.                                                                                          Null Hypothesis:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT