18.04.2013 Views

The.Algorithm.Design.Manual.Springer-Verlag.1998

The.Algorithm.Design.Manual.Springer-Verlag.1998

The.Algorithm.Design.Manual.Springer-Verlag.1998

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Data Structures and Sorting<br />

Next: Fundamental Data Types Up: Techniques Previous: Implementation Challenges<br />

Data Structures and Sorting<br />

When things go right, changing a data structure in a slow program works the same way an organ<br />

transplant does in a sick patient. For several classes of abstract data types, such as containers,<br />

dictionaries, and priority queues, there exist many different but functionally equivalent data structures<br />

that implement the given data type. Changing the data structure does not change the correctness of the<br />

program, since we presumably replace a correct implementation with a different correct implementation.<br />

However, because the new implementation of the data type realizes different tradeoffs in the time to<br />

execute various operations, the total performance of an application can improve dramatically. Like a<br />

patient in need of a transplant, only one part might need to be replaced in order to fix the problem.<br />

It is obviously better to be born with a good heart than have to wait for a replacement. Similarly, the<br />

maximum benefit from good data structures results from designing your program around them in the first<br />

place. Still, it is important to build your programs so that alternative implementations can be tried. This<br />

involves separating the internals of the data structure (be it a tree, a hash table, or a sorted array) from its<br />

interface (operations like search, insert, delete). Such data abstraction is an important part of producing<br />

clean, readable, and modifiable programs. We will not dwell on such software engineering issues here,<br />

but such a design is critical if you are to experiment with the impact of different implementations on<br />

performance.<br />

In this chapter we will also discuss sorting, stressing how sorting can be applied to solve other problems<br />

more than the details of specific sorting algorithms. In this sense, sorting behaves more like a data<br />

structure than a problem in its own right. Sorting is also represented by a significant entry in the problem<br />

catalog; namely Section .<br />

<strong>The</strong> key take-home lessons of this chapter are:<br />

● Building algorithms around data structures such as dictionaries and priority queues leads to both<br />

clean structure and good performance.<br />

● Picking the wrong data structure for the job can be disastrous in terms of performance. Picking the<br />

very best data structure is often not as critical, for there are typically several choices that perform<br />

similarly.<br />

● Sorting lies at the heart of many different algorithms. Sorting the data is one of the first things any<br />

algorithm designer should try in the quest for efficiency.<br />

● Sorting can be used to illustrate most algorithm design paradigms. Data structure techniques,<br />

file:///E|/BOOK/BOOK/NODE22.HTM (1 of 2) [19/1/2003 1:27:43]

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!