---
title: "ADT of stack: value and operator definition"
subject: "Data Structure and Algorithm"
chapter: 1
key: "semester_4/data_structure_and_algorithm:adt-stack-value-operator"
source: https://www.bctengineer.com/q/semester_4/data_structure_and_algorithm/adt-stack-value-operator
site: BCT Engineering
---

# ADT of stack: value and operator definition

Data Structure and Algorithm · Chapter 1: Concept of data structure

- Asked in: 2073 Magh, 4 marks
- Video: [Introduction to Stacks](https://www.youtube.com/watch?v=I37kGX-nZEI) — Neso Academy
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_4/data_structure_and_algorithm/adt-stack-value-operator
- Whole chapter: https://www.bctengineer.com/md/semester_4/data_structure_and_algorithm/chapter-1

## Question

Describe value definition and operator definition of ADT and apply it to describe STACK.

## Short answer

ADT specification includes value definition (abstract typedef describing the set of values) and operator definition (header, precondition, postcondition). For STACK, the value is an ordered sequence accessible only at the top; operations push, pop, empty, and stacktop are defined with preconditions (e.g., pop on non-empty stack) and postconditions that specify the LIFO behavior without storage details.

## Answer

#### Value definition and operator definition

An ADT specification has two parts.

- **Value definition**: describes the set of values of the type. It has the keyword `abstract typedef` (the type and its structure) and an optional `condition` that restricts the values.
- **Operator definition**: gives each operation as a header (name and parameters), an optional `precondition` (what must be true before the call) and a `postcondition` (what is true after the call). Together they describe the effect without implementation.

#### Applying it to STACK

A stack is an ordered collection of elements in which insertion and deletion take place only at one end, the top (LIFO).

```text
/* Value definition */
abstract typedef <<eltype>> STACK(eltype);
   /* an ordered sequence of items of type eltype; the first item is the top */

/* Operator definition */
abstract empty(s)
   STACK(eltype) s;
   postcondition empty == (len(s) == 0);

abstract push(s, elt)
   STACK(eltype) s;  eltype elt;
   postcondition s == <elt> + s(before);          /* elt becomes the top */

abstract eltype pop(s)
   STACK(eltype) s;
   precondition  empty(s) == FALSE;               /* no pop on empty stack */
   postcondition pop == first(s(before));         /* returns old top     */
                 s == sub(s(before), 1, len(s(before)) - 1);

abstract eltype stacktop(s)
   STACK(eltype) s;
   precondition  empty(s) == FALSE;
   postcondition stacktop == first(s);            /* read top, no removal */
```
The preconditions of `pop` and `stacktop` correspond to the *stack underflow* check in any implementation.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. What does the value definition of an ADT contain?
   A. precondition and postcondition
   B. Only function headers
   C. Only C code
   D. abstract typedef and an optional condition
   Answer: D. Value definition describes the set of values; the operator definition has pre/postconditions. (Key point: Value definition)

2. A precondition in an operator definition states:
   A. What is true after the call
   B. The speed of the operation
   C. The data type of the return value
   D. What must be true before the operation is called
   Answer: D. The postcondition states what is true after. (Key point: Precondition meaning)

3. Why does pop have the precondition empty(s) == FALSE?
   A. To avoid overflow
   B. To make the stack sorted
   C. Popping an empty stack would cause underflow
   D. To return the stack length
   Answer: C. It corresponds to the stack underflow check in any implementation. (Key point: Pop precondition)

4. How does stacktop differ from pop?
   A. stacktop removes the top
   B. stacktop works on an empty stack
   C. stacktop reads the top without removing it
   D. stacktop inserts an element
   Answer: C. stacktop returns first(s) and leaves the stack unchanged. (Key point: stacktop vs pop)

## Related in Data Structure and Algorithm

- [Data type and ADT definition](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Adata-type-and-adt) — Data Structure and Algorithm, chapter 1, asked 3×
- [ADT of linked list](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Aadt-linked-list-definition) — Data Structure and Algorithm, chapter 1
- [Stack definition and basic operations](https://www.bctengineer.com/question.md?key=semester_4%2Fdata_structure_and_algorithm%3Astack-operations-algorithms) — Data Structure and Algorithm, chapter 2

## Related in other subjects

- [Operator overloading: need and definition](https://www.bctengineer.com/question.md?key=semester_3%2Fobject_oriented_programming%3Aoperator-overloading-why-define) — Object Oriented Programming, chapter 5, asked 3×
