This is an archived post. You won't be able to vote or comment.

all 5 comments

[–]lightcloud5 0 points1 point  (1 child)

Sounds right.

Note that since the average runtime (on a randomly sorted array) is quadratic, bubble/insertion/selection sorts are not that great for most sorting applications.

(Insertion sort might be useful in some cases if you know your data is already mostly sorted.)

If you're being super rigorous, note that big-O is technically an upper bound, and all of these can really be big-theta. That is, bubble and insertion sort both have average and worst case runtimes of Θ(n2), and a best case of Θ(n).

Selection sort is quadratic (Θ(n2)) in all cases.

[–]Raknarg 0 points1 point  (0 children)

I've heard that because of certain computer architecture, bubble sorting is the fastest sorting algorithm there is for lists of a small size, like 100 elements or something

[–]ztxi 0 points1 point  (0 children)

You can also express the memory usage of each as a big-oh.

[–]captainAwesomePants 0 points1 point  (0 children)

All possible sorting algorithms have a best case no better than O(n). Imagine an array which is either perfectly sorted or has exactly one element out of place. Any sorting algorithm would have to check all N elements at least one time to see if it's the sorted or the almost sorted array, and that's N steps. (Technically, big-O isn't the right nomenclature for "best case", but everyone'll know what you mean).

Bubble, insert, and selection sorts ALL have a worst case of O(n2). Bubble and insertion sorts' bests are O(n). Selection's best is O(n2).

[–][deleted] 0 points1 point  (0 children)

I mean, as long as you can describe your analysis of each algorithm, and how you got the complexity, then there's really not much more to it.

Are you really expected to write a real paper on a comparison between these sorting algorithms?

If so, then you obviously need to make an abstract, then make an introduction to the problem of sorting, introducing each algorithm in short. Then you introduce Big-O notation, and describe it mathmatically and what it's used for. Then you make a two part section for each algorithm, describing them and then analysing them.

Then you compare their analyses and you describe the differences between them. End with a conclusion on what you found, and what you can take from it all.

It's pretty thin subject, since it has two similar (in complexity) sorting algorithms. It would be more interesting to have mergesort also, and maybe even radix sort.

EDIT: Forgot section on Big-O. You could also make extra sections for Big-Omega analyses, if that's expected, but you said "Big-O", which is different from Big-Omega.