next up previous index
Next: Binary search Up: Data Structures Previous: Code and demonstration   Index


Order

Many data structures provide sorting and searching routines. The idea of sorting presupposes that the data items are ordered in some way. Searching does not presuppose an order, but it is quicker to search for an item if the items have previously been sorted.

Many data types have an intrinsic ordering. This is obvious for the primitive numeric types. Characters are also ordered by their ASCII or Unicode values. This is the same as the usual alphabetic ordering for letters of the alphabet. The ordering of characters can be extended to the usual lexicographic ordering for strings.

When writing a sorting or searching algorithm, the nature of the elements sorted is usually unimportant. It is only necessary to refer to their ordering relation. Here is an example.



Subsections

Peter Williams 2005-06-07