Stacks

What Is an Abstract Data Type (ADT) in Data Structures?

What an abstract data type (ADT) is, how it differs from a data structure, and how a stack works as an ADT with push, pop, and peek operations.

On this page
  1. The idea behind an abstract data type
  2. The stack as an abstract data type
  3. ADT versus data structure
  4. Is a stack an ADT or a data structure?
  5. Other common abstract data types
  6. Why the separation helps
  7. Summary

An abstract data type, or ADT, is a description of a kind of data and the operations you can perform on it, without saying how those operations are built. The description says what the data type does. It does not say how the work is carried out.

The idea behind an abstract data type

An ADT is usually defined by three things:

  • the kind of values it holds,
  • the operations available on those values, and
  • the rules for how those operations behave.

The definition is a specification. Anyone who reads it knows what to expect from the type, whether they are writing the code or using it. For a more concrete example, see what is ADT with an example.

The stack as an abstract data type

A stack is a common example. Its specification says that it holds items and offers these operations:

  • push adds an item to the top,
  • pop removes the top item and returns it,
  • peek returns the top item without removing it, and
  • isEmpty reports whether the stack has no items.

The behavior rule is last in, first out. The most recently pushed item is the first one popped. A pop on an empty stack is an error. Nothing in that specification says whether the items live in an array or in linked nodes.

ADT versus data structure

The two terms are often used loosely, but they refer to different things:

  • An ADT is the specification: the values, the operations, and their behavior.
  • A data structure is a concrete implementation: the actual layout in memory, such as an array or a linked list.

So a stack is an ADT, and an array-based stack is one data structure that implements it. A linked-list stack is another implementation of the same ADT. Both follow the same rules for push and pop. For a fuller comparison, see adt vs data structure.

Is a stack an ADT or a data structure?

It depends on what you are discussing. When you talk about the operations and the rules they follow, a stack is an ADT. When you talk about a specific way of storing the items, such as an array with a top index, you are describing a data structure.

Many course materials use the two words for the same idea in casual conversation, so the context usually makes the meaning clear.

Other common abstract data types

Several other ADTs appear often in introductory courses:

  • List: an ordered collection, with items accessed and changed by position.
  • Queue: first in, first out, with enqueue and dequeue operations.
  • Set: a collection of distinct items, with a membership test.
  • Map: key-value pairs, with lookup by key.
  • Priority queue: removes the item with the highest priority.

Each of these can be built in more than one way. A list might use an array or a linked list. A map is often built as a hash table or a balanced search tree. The ADT stays the same across these choices.

Arrays are the storage used in many examples here, and a common question is whether they count as data structures in their own right. For that, see is an array a data structure.

Why the separation helps

Thinking in terms of ADTs has practical benefits:

  • You can reason about how a program behaves before writing the code.
  • You can replace one implementation with another without changing code that calls the operations.
  • You can compare implementations on cost and limits. For example, a fixed-size array stack can overflow, while a linked-list stack has no fixed size limit.

Some authors argue about how strictly the two ideas should be kept apart, so it is reasonable to treat the terms as a practical guide rather than a rigid rule.

Summary

  • An ADT defines values, operations, and behavior without saying how they are implemented.
  • A data structure is a concrete implementation of an ADT.
  • A stack is an ADT with push, pop, peek, and isEmpty, and it can be built on an array or a linked list.
  • Other common ADTs include lists, queues, sets, maps, and priority queues.

The complete guide to stacks

Stack Operations in Data Structures
Read the guide

Keep exploring

Guides from other topics

All topics →

Big O for Data Structures

A practical guide to Big O for data structures: how arrays, lists, hash tables, trees and heaps compare on search, insert and delete costs, with examples.

Big O Notation 5 min read