This preview shows pages 1–3. Sign up to view the full content.
1
CMPS 101
Algorithms and Abstract Data Types
ADTs and Modules in Java and ANSI C
Introduction
This document introduces the concepts of Modules and ADTs, and describes how to implement them
in both Java and ANSI C.
Informally, an
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
module
.
A module is a selfcontained
component of a program having a well defined
interface
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.
This is
why most languages have a type declaration mechanism the allows the user to create high level types
as desired.
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
S
of “mathematical structures”, the elements of which are called
states
.
(2) An associated set of operations which can be applied to the states in
S
.
Each ADT
instance
or
object
has a current state which is one of the elements of the set
S
.
The
operations on
S
fall (roughly) into two classes.
Manipulation procedures
are operations which cause
an ADT instance to change it's state.
Access functions
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.
Example
Consider an
integer queue
.
In this case
S
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).
(It is
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.)
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document2
Manipulation procedures
Enqueue
Insert a new integer at the back of the queue
Dequeue
Remove an integer from the front of the queue
This is the end of the preview. Sign up
to
access the rest of the document.
 Spring '09
 AgoreBack
 Algorithms

Click to edit the document details