Hello how to classify these names in alphabetical order?
I assume that you mean how can they be sorted into alphabetical order. Where should the sorted list be put ? Would it be good enough if an array of indices to the original array in alphabetical order was output ?
Not sure why bubble sort is the standard answer for first try at sorting algorithms. Inefficient, and minorly unintuitive. If you didn't know anything about sorting, and you had to come up with a sorting algorithm, would you come up with a bubble sort? Not me.
Insertion sort makes more sense. Plus, it's a lot more efficient.
Jimmus:
Not sure why bubble sort is the standard answer for first try at sorting algorithms. Inefficient, and minorly unintuitive. If you didn't know anything about sorting, and you had to come up with a sorting algorithm, would you come up with a bubble sort? Not me.
Insertion sort makes more sense. Plus, it's a lot more efficient.
Even selection sort makes more sense.
Nope.
All the sorting algorithms you mention are equally bad, O(n2) on average.
That is true. Theoretically the big O notation is the same, and their computational complexity is the same. However, look at the main Bubble Sort page. Specifically the In practice section. There are other issues at play here.
On random lists, insertion sort is 5 times faster than bubble sort?
I don't know about that, but my experience with implementing all three of those sorting algorithms has been that insertion sort was easier to understand, easier to write, and significantly faster executing.
I know it's not really relevant, but when I pick up ten cards and want to sort them, I instinctively use an insertion sort. I really can't see myself running a bubble sort on them. I've done it as an exercise, but it just seemed ridiculous.
Insertion sort makes more sense. Plus, it's a lot more efficient.
Nope.
All the sorting algorithms you mention are equally bad, O(n2) on average.
If you use a binary chop search to find the insertion point, insertion sort takes O(n log n) comparisons. If comparisons are relatively expensive (eg: long strings mostly having similar prefixes; anything needing a database fetch) and the insertions are relatively efficient (eg: memmove and an array of pointers), it's better than O(n2).
Picking a suitable sorting algorithm will always be more an art than a science, because performance depends on what is being sorted. Quicksort does poorly on lists in reverse order. Smoothsort does well on lists that are mostly already sorted; whereas heapsort in the same situation is inefficient, although otherwise its usually a good choice. Bubble sort is perfectly fine for small arrays, where the overhead is the code itself, but in this situation shellsort is a better choice (I like to use fibonnaci numbers, rather than simply dividing the shells by 2, because shellsort tends to works better where the shell sizes are relatively prime). Mergesort is appropriate for data on magnetic tape or things like magnetic tape.
All the sorting algorithms you mention are equally bad, O(n2) on average.
If you use a binary chop search to find the insertion point, insertion sort takes O(n log n) comparisons. If comparisons are relatively expensive (eg: long strings mostly having similar prefixes; anything needing a database fetch) and the insertions are relatively efficient (eg: memmove and an array of pointers), it's better than O(n2).
Picking a suitable sorting algorithm will always be more an art than a science, because performance depends on what is being sorted. Quicksort does poorly on lists in reverse order. Smoothsort does well on lists that are mostly already sorted; whereas heapsort in the same situation is inefficient, although otherwise its usually a good choice. Bubble sort is perfectly fine for small arrays, where the overhead is the code itself, but in this situation shellsort is a better choice (I like to use fibonnaci numbers, rather than simply dividing the shells by 2, because shellsort tends to works better where the shell sizes are relatively prime). Mergesort is appropriate for data on magnetic tape or things like magnetic tape.
etc, etc
maybe uploading to a Cray supercomputer would make it faster?
my gosh, OP's sorting a small array, he could use chisanbop and do it efficiently.