140 Intermediate C Programming
means that no matter how fast a computer is, if an array is sufficiently large then selection
sort will behave poorly when compared to quick sort. Selection sort can be faster for small
arrays. This is because the logic of selection sort is simpler. What counts as “small” or
“large” may be empirically determined for a given computer.
(a)
(b)
FIGURE 9.1: (a) Execution time for selection sort and quick sort. (b) The ratio of the
execution time. Please note that both axes use a logarithmic scale.
To summarize, selection sort is an algorithm that selects the smallest value among the
remaining unsorted array elements in each iteration. C has a built-in function called qsort
and it can sort arrays of different types. It knows how to sort elements because programmers
tell qsort the size of each element and provide functions that compares the elements.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset