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

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

18.04.2013 Views

Data Structures and Sorting Next: Fundamental Data Types Up: Techniques Previous: Implementation Challenges Data Structures and Sorting When things go right, changing a data structure in a slow program works the same way an organ transplant does in a sick patient. For several classes of abstract data types, such as containers, dictionaries, and priority queues, there exist many different but functionally equivalent data structures that implement the given data type. Changing the data structure does not change the correctness of the program, since we presumably replace a correct implementation with a different correct implementation. However, because the new implementation of the data type realizes different tradeoffs in the time to execute various operations, the total performance of an application can improve dramatically. Like a patient in need of a transplant, only one part might need to be replaced in order to fix the problem. It is obviously better to be born with a good heart than have to wait for a replacement. Similarly, the maximum benefit from good data structures results from designing your program around them in the first place. Still, it is important to build your programs so that alternative implementations can be tried. This involves separating the internals of the data structure (be it a tree, a hash table, or a sorted array) from its interface (operations like search, insert, delete). Such data abstraction is an important part of producing clean, readable, and modifiable programs. We will not dwell on such software engineering issues here, but such a design is critical if you are to experiment with the impact of different implementations on performance. In this chapter we will also discuss sorting, stressing how sorting can be applied to solve other problems more than the details of specific sorting algorithms. In this sense, sorting behaves more like a data structure than a problem in its own right. Sorting is also represented by a significant entry in the problem catalog; namely Section . The key take-home lessons of this chapter are: ● Building algorithms around data structures such as dictionaries and priority queues leads to both clean structure and good performance. ● Picking the wrong data structure for the job can be disastrous in terms of performance. Picking the very best data structure is often not as critical, for there are typically several choices that perform similarly. ● Sorting lies at the heart of many different algorithms. Sorting the data is one of the first things any algorithm designer should try in the quest for efficiency. ● Sorting can be used to illustrate most algorithm design paradigms. Data structure techniques, file:///E|/BOOK/BOOK/NODE22.HTM (1 of 2) [19/1/2003 1:27:43]

Data Structures and Sorting divide-and-conquer, randomization, and incremental construction all lead to popular sorting algorithms. ● Fundamental Data Types ❍ Containers ❍ Dictionaries ❍ Binary Search Trees ❍ Priority Queues ● Specialized Data Structures ● Sorting ● Applications of Sorting ● Approaches to Sorting ❍ Data Structures ❍ Incremental Insertion ❍ Divide and Conquer ❍ Randomization ❍ Bucketing Techniques ● War Story: Stripping Triangulations ● War Story: Mystery of the Pyramids ● War Story: String 'em Up ● Exercises Next: Fundamental Data Types Up: Techniques Previous: Implementation Challenges Algorithms Mon Jun 2 23:33:50 EDT 1997 file:///E|/BOOK/BOOK/NODE22.HTM (2 of 2) [19/1/2003 1:27:43]

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!