Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Another way to sort a list by exchanging out-of-order keys is called Bubble Sort

ID: 3938314 • Letter: A

Question

Another way to sort a list by exchanging out-of-order keys is called Bubble Sort.    Bubble Sort scans adjacent pairs of records and exchanged those found to have out-of-order keys. After the first time though the list, the record with the largest key is moved to its proper position. This process is done repeatedly on the remaining, unsorted part of the list until the list is completely sorted. Write the Bubble Sort algorithm. Analyze your algorithm, and show the result using order notation. Compare with the performance of the Bubble Sort Algorithm against those of Insertion Sort, Exchange Sort, and Selection Sort.

Explanation / Answer

Bubble sort algorithm :

begin BubbleSort(arrlist)
for all elements of arrlist
if arrlist[i] > arrlist[i+1]
swap(arrlist[i], arrlist[i+1])
end if
end for
return arrlist
end BubbleSort

Best case complexities:

a) Bubble sort: O(n)

b) Insertion sort: O(n)

c) Selection sort: O(n^2)

Worst case complexitites:

a) Bubble sort: O(n^2)

b) Insertion sort: O(n^2)

c) Selection sort: O(n^2)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote