Professional Documents
Culture Documents
Suppose that we are given n integers and that we wish to sort them in, say,
increasing order of magnitude with the smallest number at the top of the list. The
straightforward approach is to scan the initial list of numbers in order to find the
smallest of them; this requires n - I comparisons. We make this smallest number the
first element of our sorted array. We then scan the list of the remaining n - I
numbers for the second smallest number in the initial list (thus performing n - 2
comparisons) and continue in this manner until all the numbers are sorted. This is,
then, a 0(n2) algorithm, since the total number of comparisons required is
A more subtle approach, however, leads to an algorithm which is 0(n· log2 n). This
approach is illustrated in Figure 7.13 for an array of 16 numbers involving the
integers I through 16.
To describe this approach, let us assume, at first, that it so happens that n = 2k,
https://web.mit.edu/urban_or_book/www/book/chapter7/7.2.1.html 1/2