Previous   Next

Elementary Data Structures

Organizing the data for processing is an essential step in the development of a computer program. For many apps, the choice of the proper data structure is the only major decision involved in the implementation: once the choice has been made, the necessary algorithms are simple. For the same data, some data structures require more or less space than others; for the same operations on the data, some data structures lead to more or less efficient algorithms than others. The choices of algorithm and of data structure are closely intertwined, and we continually seek ways to save time or space by making the choice properly.

A data structure is not a passive entity: We also must consider the operations to be performed on it (and the algorithms used for these operations). This concept is formalized in the notion of a data type. In this chapter, our primary interest is in concrete implementations of the fundamental approaches that we use to structure data. We consider basic methods of organization and methods for manipulating data, work through a number of specific examples that illustrate the benefits of each, and discuss related issues such as storage management. In , we discuss abstract data types, where we separate the definitions of data types from implementations.

We discuss properties of arrays, linked lists, and strings. These classical data structures have widespread applicability: with trees (see ), they form a basis for virtually all the algorithms considered in this tutorial. We consider primitive operations for manipulating these data structures in order to develop a basic set of tools that we can use to develop sophisticated algorithms for difficult problems.

The study of storing data as variable-sized objects and in linked data structures requires an understanding of how the system manages the storage that it allocates to programs for their data. We do not cover this subject exhaustively because many of the important considerations are system and machine dependent and because one of Java's prime features is to free programmers from some of the basic problems that can arise. However, we do discuss some approaches to storage management and some basic underlying mechanisms.

At the end of the chapter, we consider several examples of compound structures, such as arrays of linked lists and arrays of arrays. The notion of building abstract mechanisms of increasing complexity from lower-level ones is a recurring theme throughout this tutorial. We consider a number of examples that serve as the basis for more advanced algorithms later in the tutorial.

The data structures that we consider in this chapter are important building blocks that we can use in a natural manner in Java and many other coding languages. In , we consider another important data structure, the tree. Arrays, strings, linked lists, and trees are the basic elements underlying most of the algorithms that we consider in this tutorial. In , we discuss the use of the concrete representations developed here in building basic abstract data types that can meet the needs of a variety of apps. In the rest of the tutorial, we develop numerous variations of the basic tools discussed here, trees, and abstract data types in order to create algorithms that can solve more difficult problems and that can serve us well as the basis for higher-level abstract data types in diverse apps.

Previous   Next