Every computer science curriculum in the world includes a course on data structures and algorithms. Data structures are that important; they improve our quality of life and even save lives on a regular basis. Many multi-million and several multi-billion dollar companies have been built around data structures.
How can this be? If we think about it for even a few minutes, we realize that we interact with data structures constantly.
In the next section, we look at the operations supported by the most commonly used data structures. Anyone with even a little bit of programming experience will see that these operations are not hard to implement correctly. We can store the data in an array or a linked list and each operation can be implemented by iterating over all the elements of the array or list and possibly adding or removing an element.
This kind of implementation is easy, but not very efficient. Does it really matter? Computers are getting faster and faster. Maybe the obvious implementation is good enough. Let's do some back-of-the-envelope calculations to find out.
 ), items.  It is
reasonable, in most applications, to assume that the application will
want to look up each item at least once.  This means we can expect to do
at least one million (
), items.  It is
reasonable, in most applications, to assume that the application will
want to look up each item at least once.  This means we can expect to do
at least one million ( ) lookups in this data.  If each of these
) lookups in this data.  If each of these
 lookups inspects  each of the
 lookups inspects  each of the  items, this gives a total
of
 items, this gives a total
of 
 (one thousand billion) inspections.
 (one thousand billion) inspections.
 ) operations per
second.1.1This means that this application will take at least
) operations per
second.1.1This means that this application will take at least 
 seconds, or roughly 16 minutes and 40 seconds.  16 minutes is an
eon in computer time, but a person might be willing to put up with it
(if they were headed out for a coffee break).
 seconds, or roughly 16 minutes and 40 seconds.  16 minutes is an
eon in computer time, but a person might be willing to put up with it
(if they were headed out for a coffee break).
 queries per second,
meaning that they would require at least
 queries per second,
meaning that they would require at least 
 very
fast servers just to keep up.
 very
fast servers just to keep up.
 , in the data structure
and the number of operations,
, in the data structure
and the number of operations,  , performed on the data structure
are both large.  In these cases, the time (measured in, say, machine
instructions) is roughly
, performed on the data structure
are both large.  In these cases, the time (measured in, say, machine
instructions) is roughly 
 .
.
The solution, of course, is to carefully organize data within the data
structure so that not every operation requires inspecting every data item.
Although it sounds impossible at first, we will see data structures
where a search requires looking at only 2 items on average, independent
of the number of items stored in the data structure.  In our billion
instruction per second computer it takes only 
 seconds to
search in a data structure containing a billion items (or a trillion,
or a quadrillion, or even a quintillion items).
 seconds to
search in a data structure containing a billion items (or a trillion,
or a quadrillion, or even a quintillion items).
We will also see implementations of data structures that keep the
items in sorted order, where the number of items inspected during an
operation grows very slowly as a function of the number of items in
the data structure.  For example, we can maintain a sorted set of one
billion items while inspecting at most 60 items during any operation.
In our billion instruction per second computer, these operations take
 seconds each.
 seconds each.
The remainder of this chapter briefly reviews some of the main concepts used throughout the rest of the book. Section 1.1 describes the interfaces implemented by all the data structures described in this book and should be considered required reading. The remaining sections discuss: