Data Structure
Data Structure
INTRODUCTION
This course is not about any particular programming language, both the
textbook and the lectures are 99% language independent. However, the
assignments must be done in a specific programming language - Turbo C.
The assignments assume you are already familiar with:
Let me begin the course by giving definitions for the terms data type and
structured data type.
Example 2: As a second example, consider the data type fraction. How can
we specify the domain and operations that define fractions? It seems
straightforward to name the operations; fractions are numbers so all the
normal arithmetic operations apply, such as addition, multiplication,
comparison. In addition there might be some fraction-specific operations
such as normalizing a fraction by removing common terms from its
numerator and denominator - for example, if we normalized 6/9 we'd get 2/3.
But how do we specify the domain for fractions, i.e. the set of possible values
for a fraction? Structural and behavioral
The alternative approach to defining the set of values for fractions does not
impose any internal structure on them. Instead it just adds an operation that
creates fractions out of other things, such as
CREATE_FRACTION(N,D)
where N is any integer, D is any non-zero integer.
The values of type fraction are defined to be the values that are produced by
this function for any valid combination of inputs.
You are probably thinking, this is crazy, CREATE_FRACTION could be any old
random function, how do we guarantee that CREATE_FRACTION(N,D) actually
returns the fraction N/D?
And that's the reason I call this sort of definition behavioral, because the
definition is strictly in terms of a set of operations and constraints or axioms
relating the behavior of the operations to one another.
In this style of definition, the domain of a data type - the set of permissible
values - plays an almost negligible role. Any set of values will do, as long as
we have an appropriate set of operations to go along with it.