You are on page 1of 3

A data type can be considered abstract when it is defined in terms of operations on it,

and its implementation is hidden

An abstract data type is defined indirectly, only by the operations that may be performed
on it and by mathematical constraints on the effects (and possibly cost) of those
operations.[1]

For example, an abstract stack data structure could be defined by three operations: push,
that inserts some data item onto the structure, pop, that extracts an item from it (with the
constraint that each pop always returns the most recently pushed item that has not been
popped yet), and peek, that allows data on top of the structure to be examined without
removal. When analyzing the efficiency of algorithms that use stacks, one may also
specify that all operations take the same time no matter how many items have been
pushed into the stack, and that the stack uses a constant amount of storage for each
element

An abstract data type is defined as a mathematical model of the data objects that make up
a data type as well as the functions that operate on these objects

If for a particular collection of data only the


structure
of data and the functions to be performed on the data
is
defined but the implementation is not defined,then
such a
collection of data is called Abstrct data type.

Denition 2.1. An Abstract Data Type, or ADT, consists of (a) a specication of the possible
values of the data type and (b) a specication of the operations that can be performed on
those
values in terms of the operations' inputs, outputs, and eects.
We are all used to dealing with the primitive data types as abstract data types. It is quite
likely
that you don't know the details of how values of type double are represented as sequences
of bits.
The details are, in fact, rather complicated. However, you know how to work with double
values
by adding them, multiplying them, truncating them to values of type int, inputting and
outputting
them, and so on. To work with values of type double, you only need to know how to use
these operations and what they do. You don't need to know how they are implemented.
When you create your own new data types|stacks, queues, trees, and even more
complicated
structures|you are necessarily deeply involved in the data representation and in the
implemen-11
12 CHAPTER 2. ABSTRACT DATA TYPES
tation of the operations. However, when you use these data types, you don't want to have
to
worry about the implementation. You want to be able to use them the way you use the
built-in
primitive types, as abstract data types. This is in conformance with one of the central
principles of
software engineering: encapsulation, also known as information hiding, modularity, and
separation
of interface from implementation.
2.1 Stacks and Queues
Let's consider two familiar data

Abstract Data Types


An Abstract Data Type (ADT) is more a way of looking at a data structure: focusing on
what it does and ignoring how it does its job. A stack or a queue is an example of an
ADT. It is important to understand that both stacks and queues can be implemented using
an array. It is also possible to implement stacks and queues using a linked list. This
demonstrates the "abstract" nature of stacks and queues: how they can be considered
separately from their implementation.

To best describe the term Abstract Data Type, it is best to break the term down into "data
type" and then "abstract".

data type

When we consider a primitive type we are actually referring to two things: a data item
with certain characteristics and the permissible operations on that data. An int in Java,
for example, can contain any whole-number value from -2,147,483,648 to
+2,147,483,647. It can also be used with the operators +, -, *, and /. The data type's
permissible operations are an inseparable part of its identity; understanding the type
means understanding what operations can be performed on it.

In Java, any class represents a data type, in the sense that a class is made up of data
(fields) and permissible operations on that data (methods). By extension, when a data
storage structure like a stack or queue is represented by a class, it too can be referred to as
a data type. A stack is different in many ways from an int, but they are both defined as a
certain arrangement of data and a set of operations on that data.

abstract

Now lets look at the "abstract" portion of the phrase. The word abstract in our context
stands for "considered apart from the detailed specifications or implementation".

In Java, an Abstract Data Type is a class considered without regard to its implementation.
It can be thought of as a "description" of the data in the class and a list of operations that
can be carried out on that data and instructions on how to use these operations. What is
excluded though, is the details of how the methods carry out their tasks. An end user (or
class user), you should be told what methods to call, how to call them, and the results that
should be expected, but not HOW they work.

We can further extend the meaning of the ADT when applying it to data structures such as
a stack and queue. In Java, as with any class, it means the data and the operations that can
be performed on it. In this context, although, even the fundamentals of how the data is
stored should be invisible to the user. Users not only should not know how the methods
work, they should also not know what structures are being used to store the data.

Consider for example the stack class. The end user knows that push() and pop() (amoung
other similar methods) exist and how they work. The user doesn't and shouldn't have to
know how push() and pop() work, or whether data is stored in an array, a linked list, or
some other data structure like a tree.

The Interface

The ADT specification is often called an interface. It's what the user of the class actually
sees. In Java, this would often be the public methods. Consider for example, the stack
class - the public methods push() and pop() and similar methods from the interface would
be published to the end user.

You might also like