Question

In: Computer Science

Sort 33, 77, 22, 11, 34, 21, 88, 90, 42 using Bubble sort, show work. Write...

Sort 33, 77, 22, 11, 34, 21, 88, 90, 42 using Bubble sort, show work. Write the algorithm.

Solutions

Expert Solution

Algorithm:
-----------
begin BubbleSort(list)
   for all elements of list
      if list[i] > list[i+1]
         swap(list[i], list[i+1])
      end if
   end for
   return list
end BubbleSort

Sorting:
---------
Bubble sort
Original list is [33, 77, 22, 11, 34, 21, 88, 90, 42]
Iteration: 1
   > Swap 77 and 22, since they are not in correct order. Now, the list becomes [33, 22, 77, 11, 34, 21, 88, 90, 42]
   > Swap 77 and 11, since they are not in correct order. Now, the list becomes [33, 22, 11, 77, 34, 21, 88, 90, 42]
   > Swap 77 and 34, since they are not in correct order. Now, the list becomes [33, 22, 11, 34, 77, 21, 88, 90, 42]
   > Swap 77 and 21, since they are not in correct order. Now, the list becomes [33, 22, 11, 34, 21, 77, 88, 90, 42]
   > Swap 90 and 42, since they are not in correct order. Now, the list becomes [33, 22, 11, 34, 21, 77, 88, 42, 90]
   > 5 swaps happened in this iteration
   > List after iteration 1 is [33, 22, 11, 34, 21, 77, 88, 42, 90]

Iteration: 2
   > Swap 33 and 22, since they are not in correct order. Now, the list becomes [22, 33, 11, 34, 21, 77, 88, 42, 90]
   > Swap 33 and 11, since they are not in correct order. Now, the list becomes [22, 11, 33, 34, 21, 77, 88, 42, 90]
   > Swap 34 and 21, since they are not in correct order. Now, the list becomes [22, 11, 33, 21, 34, 77, 88, 42, 90]
   > Swap 88 and 42, since they are not in correct order. Now, the list becomes [22, 11, 33, 21, 34, 77, 42, 88, 90]
   > 4 swaps happened in this iteration
   > List after iteration 2 is [22, 11, 33, 21, 34, 77, 42, 88, 90]

Iteration: 3
   > Swap 22 and 11, since they are not in correct order. Now, the list becomes [11, 22, 33, 21, 34, 77, 42, 88, 90]
   > Swap 33 and 21, since they are not in correct order. Now, the list becomes [11, 22, 21, 33, 34, 77, 42, 88, 90]
   > Swap 77 and 42, since they are not in correct order. Now, the list becomes [11, 22, 21, 33, 34, 42, 77, 88, 90]
   > 3 swaps happened in this iteration
   > List after iteration 3 is [11, 22, 21, 33, 34, 42, 77, 88, 90]

Iteration: 4
   > Swap 22 and 21, since they are not in correct order. Now, the list becomes [11, 21, 22, 33, 34, 42, 77, 88, 90]
   > 1 swaps happened in this iteration
   > List after iteration 4 is [11, 21, 22, 33, 34, 42, 77, 88, 90]

Iteration: 5
   > 0 swaps happened in this iteration
   > List after iteration 5 is [11, 21, 22, 33, 34, 42, 77, 88, 90]

Sorted list is [11, 21, 22, 33, 34, 42, 77, 88, 90]

Related Solutions

Sort 33, 77, 22, 11, 34, 21, 88, 90, 42 using Quick sort. Write the algorithm....
Sort 33, 77, 22, 11, 34, 21, 88, 90, 42 using Quick sort. Write the algorithm. show work
Sort 33, 77, 22, 11, 34, 21, 88, 90, 42 using Selection sort and shell sort....
Sort 33, 77, 22, 11, 34, 21, 88, 90, 42 using Selection sort and shell sort. Write the algorithms. show work. please
Sort the following set of numbers using bubble sort, insertion sort, and selection sort. Show the...
Sort the following set of numbers using bubble sort, insertion sort, and selection sort. Show the process step-by-step, and find the time complexity in Big-O notation for each method. For sorting, use ascending order. 49, 7, 60, 44, 18, 105
1. Insertion sort for 12, 2, 3, 21, 11, 10,8 2. Bubble sort for 12, 2,...
1. Insertion sort for 12, 2, 3, 21, 11, 10,8 2. Bubble sort for 12, 2, 3, 21, 11, 10,8 3. selection sort for 12, 2, 3, 21, 11, 10,8 analysis of algorithm
For the given array, simulate the working operation of Bubble Sort. Show your work at each...
For the given array, simulate the working operation of Bubble Sort. Show your work at each step. Make sure to show the status of the array after every swap. [ 28, 13, 22, 7, 34, 2 ]
Write a MIPS program using the Bubble Sort algorithm, that sorts an input list of integers...
Write a MIPS program using the Bubble Sort algorithm, that sorts an input list of integers by repeatedly calling a “swap” subroutine. The original unsorted list of integers should be received from the keyboard input. Your program should first prompt the user “Please input an integer for the number of elements:”. After the user enters a number and return, your program outputs message “Now input each element and then a return:”. For example, if the user enters 5 as the...
Given the following data set 11 20 33 45 52 30 27 21 38 42 28...
Given the following data set 11 20 33 45 52 30 27 21 38 42 28 25 79 60 14 35 100 23 88 58 A. Find the quartiles B. Determine if there are any outliers C. Draw a box plot (exclude outliers but plot them as well).
please write all formulas and show your work without using excel Using the information in Question...
please write all formulas and show your work without using excel Using the information in Question 1, what is the break-even market size for the project? Show your work, and round to the nearest unit. Refer to question 1: Consider a project with annual expected income based on approximately $125 million in revenue and approximately $77.5 million in total variable cost. You realize that both of these numbers are projected, and that your projections may be incorrect. Your boss wants...
Show ALL work including steps used during computations using formulas and diagrams when appropriate. Write a...
Show ALL work including steps used during computations using formulas and diagrams when appropriate. Write a statement explaining the meaning of your computations (conclusions) for all problems- hypothesis tests and confidence intervals. A researcher studied whether pregnant women who consumed more than 800 mg of caffeine per day had babies with a lower birth weight (in lbs). The results are in the table below: Caffeinated women’s babies weights 7.5 6.7 5.2 6.8 7.4 7.7 5.6 6.9 Non-caffeinated women’s babies weights...
Show ALL work including steps used during computations using formulas and diagrams when appropriate. Write a...
Show ALL work including steps used during computations using formulas and diagrams when appropriate. Write a statement explaining the meaning of your computations (conclusions) for all problems- hypothesis tests and confidence intervals. Given below are the birth weights of babies born to mothers who took special vitamin supplements while pregnant: 3.53    4.57    3.93    4.33    3.39    3.68    4.68    3.52     3.84 3.12    4.29    2.27    4.13    4.47    3.22    3.43    2.64      3.40 a. Make a 95% confidence interval for the mean weight of babies...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT