ADT and Data Structure
ADT and Data Structure
operations.
but can we say about stack data structure if I mean I used stack implemented
as an array in my algorithm? And why heap isn't ADT? It can be implemented
as tree or an array.
You first might want to read What is the difference between an Array and a
Stack? chrisaycock May 15 '12 at 19:16
Simply put, an ADT (Abstract Data Type) is more of a logical description, while
a Data Structure is concrete.
A Data Structure is the the real, concrete thing. It can be implemented and
used within an algorithm.
A few examples:
ADT: List
ADT: Map
Abstract Data Type: ADT may be defined as a set of data values and
associated operations that are precisely specified independent of any
particular implementation. Thus an Abstract Data Type is an organized
collection of information and a set of operations used to manage that
information. The set of operations defines the interface of the ADT. As long as
the ADT fulfills the conditions of the interface, it doesnt really matter how the
ADT is implemented. Since, in ADT, the data values and operations are
defined with mathematical precision, rather than as an implementation in a
computer language, we may reason about effects of the operations, relations
to other abstract data types whether a program implements the data type
etc. One of the simplest abstract data type is the stack data type for which
functions might be provided to create an empty stack, to push values onto a
stack and to pop values from a stack.
The basic difference between abstract data type (ADT) and concrete data
type is that the latter allow us to look at the concrete representation, whereas
the former hide the representation from us. An ADT may be pure ADT or
Updatable ADT. A pure ADT is one where all operations are pure functions.
This means that operations have no side effects. In particular, they do not
modify or update there input arguments. They just use these arguments to
generate output, which are fresh values of ADT (or of other types). Most
concrete types are pure. For example, no operation on integers actually
modifies an integer. Instead, all the operations like + produce fresh outputs.
We know that an Abstract Data Type is a data type that satisfies the following
two conditions:
The representation of objects of the type is hidden from the program units
that use the type, so only direct operations possible on those objects are
those provided in the types definition.
A type definition that allows program units to declare variables of the type,
but hides the representation of these variables.
{int x;
float y;
};
The above structure definition does not create any variables, rather it creates
a new type. Variables of this type may be created in a similar way to
variables of a built in type.
struct abc a;
The typedef keyword allows us to create new type names for our new types.
For example:
where AB is a new type name that can now be used to create new types.
AB b;
Data Structures:
A data structure may be static or dynamic. A static data structure has a fixed
size. This meaning is different from the meaning of static modifier. Arrays are
static; once we define the number of elements it can hold, the number
doesnt change. A dynamic data structure grows and shrinks at execution
time as required by its contents. A dynamic data structure is implemented
using links.
Data structures may further be categorized into linear data structures and
non-linear data structures. In linear data structures every component has a
unique predecessor and successor, except first and last elements, whereas in
case of non-linear data structures, no such restriction is there as elements
may be arranged in any desired fashion restricted by the way we use to
represent such types.