Data Types
Algorithms + Data Structures = Programs
Data types and data
structure are central to computer science and to programming.
- An influential book from he early days by Niklaus Wirth was aptly named
Algorithms + Data Structures = Programs
Data structures form a hierarchy
- Data structures form a hierarchy within a program. The atomic data types,
such as int, char, double occupy the lowest level of the hierarchy.
- To represent more complex information, you combine these atomic types to
form larger structures.
- These structures can then be assembled into even larger
ones in an open-ended process.
- You build each new level in the hierarchy by using one of the three primitives
for type construction: arrays, structs and pointers.
- Given an existing type, you can define an array of that type, include
it as a field of a record, or declare a pointer to it.
- These three facilities
constitute the mortar of the data hierarchy and allow you to build arbitrarily
complex structures.
As you learn more about programming, you'll discover that particular data
structures can be extremely useful and are worth studying in their own right.
Example: strings
A good example is the string.
A string in C is represented internally as an array of characters, which is
in turn represented as a pointer to the first address in the array.
But a string also has an abstract behavior that transcends its representation.
So regardless of its implementation, a string is a group of characters
that are thought of as a single object.
The operations on strings include :
- finding its length
- concatenation
- copying one string into another
- comparing two strings for equality or for alphabetic ordering
- etc.
We say that a string is an abstract
data type.