Question

Differentiate between Selection Sort and Bubble Sort algorithms. Explain your answer by providing Best, Average, and...

Differentiate between Selection Sort and Bubble Sort algorithms. Explain your answer by providing Best, Average, and Worst Case scenarios.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Selection Sort

Scan all items and find the smallest. Swap it into position as the first item. Repeat the selection sort on the remaining N-1 items.

I found this the most intuitive and easiest to implement — you always iterate forward (i from 0 to N-1), and swap with the smallest element (always i). Time complexity in all cases best, average and worst is O(n2) and space complexity is O(1).

Bubble Sort

Starting on the left, compare adjacent items and keep “bubbling” the larger one to the right (it’s in its final place). Bubble sort the remaining N -1 items.

Though “simple” I found bubble sort nontrivial. In general, sorts where you iterate backwards (decreasing some index) were counter-intuitive for me. With bubble-sort, either you bubble items “forward” (left-to-right) and move the endpoint backwards (decreasing), or bubble items “backward” (right-to-left) and increase the left endpoint. Either way, some index is decreasing.
You also need to keep track of the next-to-last endpoint, so you don’t swap with a non-existent item.

Time complexity in all best case is O(n), and average and worst is O(n2) and space complexity is O(1).

Add a comment
Know the answer?
Add Answer to:
Differentiate between Selection Sort and Bubble Sort algorithms. Explain your answer by providing Best, Average, and...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT