All Topics  
Abstract data type

 

   Email Print
   Bookmark   Link






 

Abstract data type



 
 
In computing
Computing

Computing is usually defined as the activity of using and developing computer technology, computer hardware and computer software. It is the computer-specific part of information technology....
, an abstract data type (ADT) is a specification of a set of data and the set of operations that can be performed on the data. Such a data type
Data type

A data type in programming languages is an attribute of a data which tells the computer something about the kind of data it is. This involves setting constraints on the datum, such as what values it can take and what operations may be performed upon it....
 is abstract in the sense that it is independent of various concrete implementation
Implementation

Implementation is the realization of an application, or execution of a plan, idea, model, design, specification, Standardization, algorithm, or policy....
s. The definition can be mathematical, or it can be programmed
Computer programming

Computer programming is the process of writing, testing, debugging/troubleshooting, and maintaining the source code of computer programs. This source code is written in a programming language....
 as an interface
Interface (computer science)

Interface generally refers to an Abstraction_%28computer_science%29 that an entity provides of itself to the outside. This separates the methods of external communication from internal operation, and allows it to be internally modified without affecting the way outside entities interact with it, as well as provide Polymorphism in object-orien...
. A first class ADT supports the creation of multiple instances of the ADT, and the interface normally provides a constructor, which returns an abstract handle
Handle (computing)

A handle is a particular kind of smart pointer. Handles are used when an application references blocks of memory or objects managed by another system, such as a database or an operating system....
 to new data, and several operations, which are function
Subroutine

In computer science, a subroutine or subprogram is a portion of computer code within a larger computer program, which performs a specific task and is relatively independent of the remaining code....
s accepting the abstract handle as an argument.

The main contribution of the abstract data type theory (and its evolution, the design by contract
Design by contract

Design by Contract or Programming by Contract is an approach to designing computer software. It prescribes that software designers should define Formal methods, precise and verifiable interface specifications for Component-based software engineering#Software component based upon the theory of abstract data types and the conceptual metaph...
) is that it (1) formalizes a definition of type (which was only intuitively hinted on procedural programming
Procedural programming

Procedural programming can sometimes be used as a synonym for imperative programming , but can also refer to a programming paradigm based upon the concept of the procedure call....
) (2) on the basis of the information hiding
Information hiding

Information hiding in computer science is the principle of hiding of design decisions in a computer program that are most likely to change, thus protecting other parts of the program from change if the design decision is changed....
 principle and (3) in a way that such formalization can be explicitly represented in programming language
Programming language

A programming language is a machine-readable artificial language designed to express computations that can be performed by a machine, particularly a computer....
 notations and semantics.






Discussion
Ask a question about 'Abstract data type'
Start a new discussion about 'Abstract data type'
Answer questions from other users
Full Discussion Forum



Encyclopedia


In computing
Computing

Computing is usually defined as the activity of using and developing computer technology, computer hardware and computer software. It is the computer-specific part of information technology....
, an abstract data type (ADT) is a specification of a set of data and the set of operations that can be performed on the data. Such a data type
Data type

A data type in programming languages is an attribute of a data which tells the computer something about the kind of data it is. This involves setting constraints on the datum, such as what values it can take and what operations may be performed upon it....
 is abstract in the sense that it is independent of various concrete implementation
Implementation

Implementation is the realization of an application, or execution of a plan, idea, model, design, specification, Standardization, algorithm, or policy....
s. The definition can be mathematical, or it can be programmed
Computer programming

Computer programming is the process of writing, testing, debugging/troubleshooting, and maintaining the source code of computer programs. This source code is written in a programming language....
 as an interface
Interface (computer science)

Interface generally refers to an Abstraction_%28computer_science%29 that an entity provides of itself to the outside. This separates the methods of external communication from internal operation, and allows it to be internally modified without affecting the way outside entities interact with it, as well as provide Polymorphism in object-orien...
. A first class ADT supports the creation of multiple instances of the ADT, and the interface normally provides a constructor, which returns an abstract handle
Handle (computing)

A handle is a particular kind of smart pointer. Handles are used when an application references blocks of memory or objects managed by another system, such as a database or an operating system....
 to new data, and several operations, which are function
Subroutine

In computer science, a subroutine or subprogram is a portion of computer code within a larger computer program, which performs a specific task and is relatively independent of the remaining code....
s accepting the abstract handle as an argument.

The main contribution of the abstract data type theory (and its evolution, the design by contract
Design by contract

Design by Contract or Programming by Contract is an approach to designing computer software. It prescribes that software designers should define Formal methods, precise and verifiable interface specifications for Component-based software engineering#Software component based upon the theory of abstract data types and the conceptual metaph...
) is that it (1) formalizes a definition of type (which was only intuitively hinted on procedural programming
Procedural programming

Procedural programming can sometimes be used as a synonym for imperative programming , but can also refer to a programming paradigm based upon the concept of the procedure call....
) (2) on the basis of the information hiding
Information hiding

Information hiding in computer science is the principle of hiding of design decisions in a computer program that are most likely to change, thus protecting other parts of the program from change if the design decision is changed....
 principle and (3) in a way that such formalization can be explicitly represented in programming language
Programming language

A programming language is a machine-readable artificial language designed to express computations that can be performed by a machine, particularly a computer....
 notations and semantics. This important advance in computer science theory (motivated by software engineering challenges in procedural programming
Procedural programming

Procedural programming can sometimes be used as a synonym for imperative programming , but can also refer to a programming paradigm based upon the concept of the procedure call....
) led to the emergence of language
Object-oriented programming language

An object-oriented programming language is one that allows or encourages, to some degree, object-oriented programming techniques such as Information hiding, Inheritance , module , and Polymorphism ....
s and methodological
Software development process

A software development process is a structure imposed on the development of a software product. Synonyms include Software_Lifecycle_Processes and software process....
 principles of object-oriented programming
Object-oriented programming

Object-oriented programming is a programming paradigm that uses "Object_" and their interactions to design applications and computer programs....
.

Examples

Abstract data types (ADT) typically seen in textbooks and implemented in programming languages (or their libraries) include:

Separation of interface and implementation

When realized in a computer program, the ADT is represented by an interface, which shields a corresponding implementation. Users of an ADT are concerned with the interface, but not the implementation, as the implementation can change in the future. (This supports the principle of information hiding
Information hiding

Information hiding in computer science is the principle of hiding of design decisions in a computer program that are most likely to change, thus protecting other parts of the program from change if the design decision is changed....
, or protecting the program from design decisions that are subject to change.)

The strength of an ADT is that the implementation is hidden from the user. Only the interface is published. This means that the ADT can be implemented in various ways, but as long as it adheres to the interface, user programs are unaffected.

There is a distinction, although sometimes subtle, between the abstract data type and the data structure used in its implementation. For example, a List ADT can be represented using an array-based implementation or a linked-list implementation. A List is an abstract data type with well-defined operations (add element, remove element, etc.) while a linked-list is a pointer-based data structure that can be used to create a representation of a List. The linked-list implementation is so commonly used to represent a List ADT that the terms are interchanged in common use.

Similarly, a Binary Search Tree ADT can be represented in several ways: binary tree, AVL tree
AVL tree

In computer science, an AVL tree is a self-balancing binary search tree, and it is the first such data structure to be invented. In an AVL tree, the tree height of the two child node subtrees of any node differ by at most one; therefore, it is also said to be height-balanced tree....
, red-black tree
Red-black tree

A red-black tree is a type of self-balancing binary search tree, a data structure used in computer science, typically used to implement associative arrays....
, array, etc. Regardless of the implementation, the Binary Search Tree always has the same operations (insert, remove, find, etc.)

Separating the interface from the implementation doesn't always mean the user is unaware of the implementation method, but rather that they can't depend on any of the implementation details. For example, an ADT can be created using a scripting language or one that can be decompiled (like C
C (programming language)

C is a general-purpose computer programming language originally developed in 1972 by Dennis Ritchie at the Bell Telephone Laboratories to implement the Unix operating system....
). Even though the user can discover the implementation method, the construct can still be called an ADT as long as any client program that conforms to the interface is unaffected if the implementation changes.

In object-oriented parlance, an ADT is a class
Class (computer science)

In object-oriented programming, a class is a programming language construct that is used as a blueprint to create Object s. This blueprint includes Attribute s and Method s that the created objects all share....
; an instance of an ADT or class is an object
Object (computer science)

In its simplest embodiment, an object is an allocated region of storage. Since programming languages use variable#Computer_programmings to access objects, the terms object and variable are often used interchangeably....
. Some languages include a constructor for declaring ADTs or classes. For example, C++ and Java provide a class constructor for this purpose.

Abstract data structure


An abstract data structure is an abstract storage for data defined in terms of the set of operations to be performed on data and computational complexity
Computational Complexity

Computational Complexity may refer to:*Computational complexity theory*Computational Complexity ...
 for performing these operations, regardless of the implementation in a concrete data structure
Data structure

A data structure in computer science is a way of storing data in a computer so that it can be used efficiently. It is an organization of mathematical and logical concepts of data....
.

Selection of an abstract data structure is crucial in the design of efficient algorithm
Algorithm

In mathematics, computing, linguistics and related subjects, an algorithm is a sequence of finite instructions, often used for calculation and data processing....
s and in estimating their computational complexity, while selection of concrete data structures is important for efficient implementation
Implementation

Implementation is the realization of an application, or execution of a plan, idea, model, design, specification, Standardization, algorithm, or policy....
 of algorithms.

This notion is very close to that of an abstract data type, used in the theory of programming language
Programming language

A programming language is a machine-readable artificial language designed to express computations that can be performed by a machine, particularly a computer....
s. The names of many abstract data structures (and abstract data types) match the names of concrete data structures.

Built-in abstract data types

Because some ADTs are so common and useful in computer programs, some programming languages build implementations of ADTs into the language as native types or add them into their standard libraries. For instance, Perl arrays can be thought of as an implementation of the List or Deque ADTs and Perl hashes can be thought of in terms of Map or Table ADTs. The C++ Standard Library and Java libraries provide classes that implement the List, Stack, Queue, Map, Priority Queue, and String ADTs.

Concrete examples


Rational numbers as an abstract data type

Since most computers only have built-in circuitry for whole-number and floating-point operations, general rational number
Rational number

In mathematics, a rational number is a number which can be expressed as a quotient of two integers. Non-integer rational numbers are usually written as the vulgar fraction , where b is not 0 ....
s cannot be represented natively. A set of computer instruction codes would be needed to specify operations on rational numbers in terms of the native integer operations. An ADT "Rational" would typically specify the following aspects, among others, of the data type. (Rational numbers are integers and fractions like a/b where a and b are integers.)

Construction: Create an instance using two integers, a and b, where a represents the numerator and b represents the denominator.

Operations: addition, subtraction, multiplication, division, exponentiation, comparison, simplification, conversion to real (floating point
Floating point

In computing, floating point describes a system for numerical representation in which a String of digits represents a rational number.The term floating point refers to the fact that the radix point can "float": that is, it can be placed anywhere relative to the Significant figures of the number....
) numbers.

To be a complete specification, any operation should be defined in terms of the data. For example, when multiplying two rational numbers a/b and c/d, the result is defined as (ac)/(bd). Typically, inputs, outputs, preconditions, postconditions, and assumptions for the ADT are specified as well.

The mathematical concept of rational numbers includes numbers with arbitrarily large numerator and denominator. Computer implementations are generally limited in various ways, and there are often tradeoffs between large capacities and high efficiency. An ADT will normally specify some minimum capacities and minimum efficiencies (maximum complexities
Computational complexity theory

Computational complexity theory, as a branch of the theory of computation in computer science, investigates the problems related to the Computational resource required for the execution of algorithms , and the inherent difficulty in providing efficient algorithms for specific computational problems....
).

With such an ADT, some programmers could create computer programs that use rational numbers, assuming that an implementation will be available, while other programmers could make available such an implementation. In this way, the ADT serves as a contract between programmers, specifying what each can expect from the others. An implementation would include the computer codes to actually perform the computations, and would, for instance have to include code for detecting when the products in ac/bd became too large for the chosen method of representing the parts.

To continue with the example, extracting the numerator and denominator could be, or not be, defined operations in such an ADT. If defined, it is conceivable that an implementation, after an instance has been created with the numbers 4 and 12, produces the numbers 1 and 3 respectively as the numerator and denominator. If the particular numbers returned by the implementation are to be predictable in specific ways, the ADT must say so. Things that are not specified in the ADT are left to the discretion of the implementor, and this may allow the implementor to find more efficient methods. The user of the implementation, on the other hand, must write his codes so that his program works correctly independently of such decisions by the implementor. The users code should be provably correct based on those properties of the implementation that are specified in the ADT. If later it is found that a particular implementation is incorrect, or works too slowly, another implementation of the same ADT could be subsituted without having to do a deep analysis of the user code.

Stack


Formal specification

Types:
E is the element type and T is the Stack
Stack

Stack may refer to:...
 type.

Functions:
  • T new (void)
  • T push (E,T)
  • E top(T)
  • T pop(T)
  • Boolean empty (T)

Axioms:
  • empty(new)
  • top(push(e,t)) = e
  • pop(push(e,t)) = t
  • not empty(push(e,t))

Preconditions:
  • .. top (T) requires not empty (T)
  • .. pop (T) requires not empty (T)


C-style interface and usage
The interface for a Stack
Stack (data structure)

In computer science, a stack is an abstract data type and data structure based on the principle of LIFO . Stacks are used extensively at every level of a modern computer system....
 ADT, written in C-style notation, might be:

long stack_create; /* create new instance of a stack */ void stack_push(long stack, void *item); /* push an item on the stack */ void *stack_pop(long stack); /* get item from top of stack */ void stack_delete(long stack); /* delete the stack */

This ADT could be used in the following manner:

long stack; struct foo *f;

stack = stack_create; /* create a stack */

stack_push(stack, f); /* add foo structure to stack */

f = stack_pop(stack); /* get top structure from stack */

Implementation variants
The above stack ADT could be initially implemented using an array, and then later changed to a linked list, without affecting any user code. The number of ways a given ADT can be implemented depends on the programming language. For example, the above example could be written in C using a struct and an accompanying set of data structures using arrays or linked lists to store the entries; however, since the constructor function returns an abstract handle, the actual implementation is hidden from the user.

See also

  • Concept (generic programming)
    Concept (generic programming)

    In generic programming, a concept is a description of supported operations on a type, including syntax and semantics. In this way, concepts are related to abstract base classes but concepts do not require a subtype relationship....
  • Design by contract
    Design by contract

    Design by Contract or Programming by Contract is an approach to designing computer software. It prescribes that software designers should define Formal methods, precise and verifiable interface specifications for Component-based software engineering#Software component based upon the theory of abstract data types and the conceptual metaph...
  • Formal methods
    Formal methods

    In computer science and software engineering, formal methods are particular kind of mathematically-based techniques for the formal specification, development and formal verification of software and hardware systems....
  • Functional specification
    Functional specification

    A functional specification in systems engineering and software development, is the set of documentation that describes the requested behavior of an engineering system....
  • Liskov substitution principle
    Liskov substitution principle

    In object-oriented programming, the Liskov substitution principle is a particular definition of subtype that was introduced by Barbara Liskov in a 1987 conference keynote address entitled Data abstraction and hierarchy...
  • Object-oriented programming
    Object-oriented programming

    Object-oriented programming is a programming paradigm that uses "Object_" and their interactions to design applications and computer programs....
  • Type system
    Type system

    In computer science, a type system may be defined as "a tractable syntactic method for proving the absence of certain program behaviors by classifying phrases according to the kinds of values they compute."....
  • Type theory
    Type theory

    In mathematics, logic and computer science, type theory is any of several formal systems that can serve as alternatives to naive set theory, or the study of such formalisms in general....
  • Algebraic data type
    Algebraic data type

    In computer programming, an algebraic data type is a datatype each of whose value s is data from other datatypes wrapped in one of the constructors of the datatype....
  • Generalized Algebraic Data Type
    Generalized Algebraic Data Type

    Generalized Algebraic Data Types are generalizations of the algebraic data types of Haskell and ML programming language, applying to parametric types....


External links

  • in NIST Dictionary of Algorithms and Data Structures