You are on page 1of 1

21/11/2020 UOR_7.2.

7.2.1 Efficient Sorting and Searching

In simulating urban systems it is often necessary to sort long arrays of numbers


such as the coordinates of incidents, the addresses of mail recipients, or the times at
which requests for service occurred. Equally important, sorting algorithms play a
central role as "building blocks" in techniques aimed at resolving several important
geometrical problems, as we shall see shortly. It is therefore important to develop a
sorting algorithm that is as efficient as possible.

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

You might also like