Skip to main content

Define ADT with example

Short answer

An abstract data type (ADT) is a mathematical model defined by its values and allowed operations, hiding implementation. For example, a RATIONAL ADT provides makerational and add operations without revealing if it uses an array or struct.

Define ADT (abstract data type) with a suitable example.

An abstract data type (ADT) is a mathematical model of a data type that is defined by its values and the operations allowed on them, without saying how they are stored or coded. The user sees only what the type does; how it is done (array, linked list, etc.) stays hidden. In Tenenbaum's style an ADT has two parts: a value definition and an operator definition.

Example: RATIONAL numbers

/* Value definition */
abstract typedef <integer, integer> RATIONAL;
condition RATIONAL[1] != 0;      /* denominator never zero */

/* Operator definition */
abstract RATIONAL makerational(a, b)
   int a, b;
   precondition  b != 0;
   postcondition makerational[0] == a  and  makerational[1] == b;

abstract RATIONAL add(a, b)
   RATIONAL a, b;
   postcondition add[1] == a[1] * b[1]
             and add[0] == a[0] * b[1] + b[0] * a[1];

Here the user calls makerational(1, 2) and add(x, y) without knowing whether a rational is kept as an array of two integers or a struct. Another common example is the stack ADT with push, pop, empty.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Data Structure and Algorithm chapter 1 questions →