Algorithms and Abstract Data Types
ADTs and Modules in Java and ANSI C
This document introduces the concepts of Modules and ADTs, and describes how to implement them
in both Java and ANSI C.
Abstract Data Type
(ADT) is a collection of mathematical
objects of some kind, together with some associated operations on those objects.
When an ADT is
used in a program, it is usually implemented in its own
A module is a self-contained
component of a program having a well defined
that details its role and relationship to the rest
of the program.
Why are ADTs necessary?
The standard data types provided by many programming languages are not
powerful enough to capture the way we think about the higher level objects in our programs.
why most languages have a type declaration mechanism the allows the user to create high level types
Often the implementation of these high level types gets spread throughout the program,
creating complexity and confusion.
Errors may occur when the legal operations on the high level types
are not well defined or are not consistently used.
The term Abstract Data Type can mean different things to different people, but for the purposes of this
course, an ADT consists of two things:
(1) A set
of “mathematical structures”, the elements of which are called
(2) An associated set of operations which can be applied to the states in
has a current state which is one of the elements of the set
fall (roughly) into two classes.
are operations which cause
an ADT instance to change it's state.
are operations which return information about
an ADT instance, without altering it's state.
In this course we will maintain a clear distinction between
the two types of operations.
We will also from time to time consider operations which don't fall into
either category, but we will not use operations which belong to both categories.
An ADT is an abstract mathematical entity which exists apart from any program or computing device.
On the other hand, ADTs are frequently implemented by a program module.
We will distinguish
between the mathematical ADT and it's implementation in a programming language.
In fact, a single
ADT could have many different implementations, all with various advantages and disadvantages.
In this case
is the set of all finite sequences of integers, and
the associated operations are: Enqueue, Dequeue, getFront, getLength, and isEmpty.
The meanings of
these operations are given below.
One possible state for this ADT is
(5, 1, -7, 2, -3, 4, 2).
recommended that the reader who is unfamiliar with elementary data structures such as queues, stacks,
and lists, review sections 10.1 and 10.2 of the text.)