Skip to content

Appendix A

This page provides a listing of mathematically expressed, model-based, semi-formal ADT specifications by “family” as well as links to representation implementations (where they exist) in the companion library.

For all ADT specifications, the following abstract types can be defined as:

  • Option(T) = {Some(t) | t ∈ T} ⊎ {None} where the first set represents all possible Some-wrapped values and {None} represents a singleton set containing the None alternative. The None alternative is a distinct value of the Option(T) type, not a null reference or null value. This provides a safe abstraction for making an otherwise partial operation total by extending its codomain and defining None for inputs where the operation would otherwise be undefined.
  • Result(T, Err) = T ⊎ Err where T represents the success alternative and Err represents the error alternative. The disjoint union preserves the distinction between these alternatives, even when T and E overlap.

These semantic definitions follow Rust’s Option<T> and Result<T, E> conventions and assume the implementing language provides a mechanism for representing and distinguishing alternative outcomes safely, such as through similar sum types (tagged/disjoint unions) or an analogous exception-handling mechanism.

Sequential ADTs

Sequential ADTs exhibit linear ordering of elements.

The basic List ADT provides sequential access to its elements without specifying named access to individual positions. Its operations generally concern either operations at the front or back of the list, but also include iteration, access-by-value operations, and concatenation. This provides sufficient functionality to support Stack, Queue, Circular Queue, and Deque ADTs.

The Positional List ADT provides access to elements through position handles, allowing direct access to positions and efficient local operations without requiring a value-based search. These handles remain stable across structural mutations that do not remove their associated elements; removing an element invalidates its corresponding position handle.

The Indexed List ADT provides direct access to elements through numerical indices, allowing convenient access by ordinal position within the list. Its indices are not stable across structural mutations, meaning that operations such as insertions and removals may change the indices of subsequent elements, but not their values.


List


Abstract Values

A finite sequence of elements from a domain E:
[e_0, e_1, … e_n-1], e_i ∈ E

Behavioral Semantics

  • The sequence preserves structural ordering of its elements.
  • Duplicate elements are permitted.
  • The sequence may be empty.
  • Provides access-by-value operations, with “find” operations necessarily requiring O(n) traversal.

Interface

Constructors
  • new: -> List(E)
Producers
  • concat: List(E) × List(E) -> List(E)
Observers
  • size: List(E) -> ℕ
    Returns the number of elements in the list as n ∈ ℕ
  • is_empty: List(E) -> bool
    Returns true if the list contains 0 elements, e.g. size(List(E)) = 0
  • contains: List(E) × E -> bool
    Returns true if the list contains query element e ∈ E
Generic List Mutators
  • add: List(E) × E -> void \
  • add_at: List(E) × E × P -> void \
  • set: List(E) × E × P -> void \
  • get: List(E) × E × P -> void \
  • clear: List(E) × E -> void \
  • remove: List(E) × E -> void \
Mutators
  • insert_head: List(E) × E -> void
    Prepends the list with an element e ∈ E such that List(E)_post = [e] ++ List(E) and size(List(E))_post = size(List(E)) + 1
  • insert_tail: List(E) × E -> void
    Apends the list with an element e ∈ E such that List(E)_post = List(E) ++ [e] and size(List(E))_post = size(List(E)) + 1
  • remove_head: List(E) -> Option(E)
    For non-empty lists, removes and returns the element e ∈ E from the head of the list leaving the remainder of the list in its original ordering such that size(List(E))_post = size(List(E)) - 1
  • remove_tail: List(E) -> Option(E) For non-empty lists, removes and returns the element e ∈ E from the tail of the list leaving the remainder of the list in its original ordering such that size(List(E))_post = size(List(E)) - 1
  • insert_before: List(E) × E × E -> void
    Inserts e ∈ E directly before the first occurrence of query element q ∈ E such that, given the original list List(E) = A + [q] + B, the resulting list is List(E)_post = A + [e, q] + B; prepends e to the list if q is not found
  • insert_after: List(E) × E × E -> void
    Inserts e ∈ E directly after the first occurrence of query element q ∈ E such that, given the original list List(E) = A + [q] + B, the resulting list is List(E)_post = A + [q, e] + B; ; appends e to the list if q is not found
  • remove_before: List(E) × E -> Option(E)
    Removes and returns the element e ∈ E directly before the first occurrence of query element q ∈ E such that, given the original list List(E) = A + [e, q] + B, the resulting list is List(E)_post = A + [q] + B; returns {None} if q is not found
  • remove_after: List(E) × E -> Option(E)
    Removes and returns the element e ∈ E directly after the first occurrence of query element q ∈ E such that, given the original list List(E) = A + [e, q] + B, the resulting list is List(E)_post = A + [q] + B; returns {None} if q is not found
  • split_before: List(E) × E -> List(E)
    Mutates l ∈ List(E) and splits it at the first occurrence of query element q ∈ E, returning a new list containing all elements from q onward, including q; The original list retains all elements preceding q such that, given the original list _List(E)pre = A + [q] + B, the resulting two lists are List(E)_post = A and List(E)_new = [q] + B; returns {None} if q is not found
  • split_after: List(E) × E -> List(E)
    Mutates l ∈ List(E) and splits it at the first occurrence of query element q ∈ E, returning a new list containing all elements after q, not including q; The original list retains all elements preceding q such that, given the original list List(E)_pre = A + [q] + B, the resulting two lists are List(E)_post = A + [q] and List(E)_new = B; returns {None} if q is not found
  • clear: List(E) -> void
    Frees all elements from the list

Representations


Indexed List


Abstract Values

A finite sequence over an element domain E of length n >= 0:
[e_0, e_1, …, e_{n - 1}] where e_k ∈ E for 0 <= k < n

Behavioral Semantics

  • The sequence may be empty.

  • Duplicate elements are permitted.

  • Each element has a unique numerical position k where {k ∈ ℕ | 0 <= k < n}.

  • Elements are ordered according to their numerical positions.

  • Positions are contiguous, zero-based numerical indices.

  • For all lists of length n, the valid index range is 0 <= i < n.

  • Positions identify elements independently of their values such that structural mutations involving individual elements may change the positions of subsequent elements.

  • Elements can be observed and mutated via position.

  • The abstract value does not prescribe a particular memory layout or representation.

  • Emptiness & multiplicity: The sequence may be empty (n = 0), and duplicate elements are permitted.

  • Index domain: Each element is associated with a unique, contiguous, zero-based index k ∈ {i ∈ N \mid 0 \le i < n}$.

  • Ordering: Elements are ordered strictly by their indices $0, 1, \dots, n-1$.

  • Index-element binding: Indices identify positions in the sequence independently of element values. Inserting or removing an element may shift the indices of subsequent elements.

  • Access & mutation: Elements are observed and mutated by index within $0 \le i < n$.

  • Quasi-representational scope: Defines coordinate-based access without prescribing contiguous arrays, gap buffers, or tree-indexed sequences.

Interface

Creators
  • new: -> IndexedList(E) Creates a new list with dynamic capacity
  • new_with_capacity: ℕ -> IndexedList(E) Creates a new list with bounded capacity which may be extendable for dynamically sized implementations
Producers
  • concat: IndexedList(E) × IndexedList(E) -> IndexedList(E)
    Joins two lists; splice is the mutator variant
Observers
  • size: IndexedList(E) -> ℕ
  • is_empty: IndexedList(E) -> bool
  • get: IndexedList(E) × ℕ -> Result(E, Err)
    Returns the element at valid index i, otherwise returns Error; May be relegated to language-level notation as list[i]
  • contains: IndexedList(E) × E -> bool
  • index_of: IndexedList(E) × E -> Option(ℕ)
    Returns the first position of an element e, if it exists in the list.
Mutators
  • insert: IndexedList(E) × E × ℕ -> Result(void, Err)
    Inserts the element e into the list for valid indexes {i ∈ k | 0 <= k <= size - 1}.
  • push: IndexedList(E) × E -> void
    Appends element e onto the list
  • set: IndexedList(E) × E × ℕ -> Result(E, Err)
    Replaces the element at index i × ℕ and returns the previously stored element if the index is valid; otherwise returns an error.
  • remove: IndexedList(E) × ℕ -> Result(E, Err)
    Returns the removed element e if the index i is valid, otherwise returns error.
  • pop: IndexedList(E) -> Option(E)
    Removes the tail, if the list is not empty
  • splice: IndexedList(E) × IndexedList(E) -> IndexedList(E)
    Mutates a list by joining another list at its tail; concat is the producer variant
  • split_at: IndexedList(E) × ℕ -> IndexedList(E)
    Mutates a list by splitting it into two lists at index i × ℕ
  • clear: IndexedList(E) -> void Empties the list
Common Convenience Algorithms
  • filter: IndexedList(E) × P -> Option([E]) Returns an iterator over all elements that satisfy predicate p ∈ P as a non-mutaing version of retain_all
  • retain_all: IndexedList(E) × P -> void
    Retains all elements that satisfy predicate p ∈ P; Mutating version of filter
  • dedup: IndexedList(E) -> void
    Removes all duplicate elements from the list
  • sort: IndexedList(E) -> void
    Mutates the list to create a sorted structure
  • swap_remove: IndexedList(E) × E × ℕ -> void
    Removes the element e at index n ∈ ℕ and swaps in the last element in the list such that no elements actually move.
  • reverse: IndexedList(E) -> void
  • bm_select: IndexedList(E) × Pre -> Option([E])
    Boyer-Moore sub-string search
  • kmp_select: IndexedList(E) × Pre -> Option([E])
    Knuth-Morris-Pratt sub-string search
  • get_kth: IndexedList(E) × ℕ -> Option(E)
    Get the k-th ranked element in the list where k ∈ ℕ (O(n) with Quickselect)
  • ceiling: IndexedList(E) × E -> Option(E)
    Returns the smallest element e in the list such that e >= q, where q ∈ E, returns None if the query element does not exist; requires that elements are comparable
  • floor: IndexedList(E) × E -> Option(E)
    Returns the largest element e in the list such that e <= q, where q ∈ E, returns None if the query element does not exist; requires that elements are comparable
  • sliding_sum: IndexedList(E) × ℕ -> Option([ℕ])
    Return the sum of ordered elements within the window-number of contiguous elements; Only applies where E ∈ ℕ
  • lcs: IndexedList(E) -> Option([E])
    Returns the longest common sub-sequence from self, requires that elements are comparable
  • partition: IndexedList(E) × F -> ℕ where predicate f(F): -> bool
    Returns the number n ∈ ℕ if the list was able to partition at the given predicate

Representations

  • Contiguous static or dynamic array
  • Gap buffer
  • Piece table

Cursor List


Abstract Values

A finite sequence over a domain E, where each element is associated with a unique position P:
[(p_0, e_0), (p_1, e_1), …, (p_{n - 1}, e_{n - 1})]

where:

  • e_k ∈ E
  • p_k ∈ p, where P is the abstract position domain
  • Each p_k identifies exactly one element in the sequence
  • The positions are distinct and arranged in the sequence’s linear order

Behavioral Semantics

  • Duplicate elements are permitted.
  • The sequence may be empty.
  • Each element has a unique position.
  • Positions are not public or de-referencable, but instead accessible by a cursor that can only operate on the previous node, the current node, and the next node in the list.
  • Elements are ordered according to their positions, accessible sequentially; random access is not permitted.
  • Provides access-by-value operations, with “find” operations necessarily requiring O(n) traversal.

Interface

Creators
  • new: -> PositionalList
Producers
  • concat: CursorList(E) × CursorList(E) -> CursorList(E)
Observers
  • size / len: CursorList(E) -> ℕ
  • is_empty: CursorList(E) -> bool
  • peek_first / peek_head: CursorList(E) -> Option(E)
  • peek_last / peek_tail: CursorList(E) -> Option(E)
  • peek_prev: CursorList(E) × Cursor -> Option(E)
  • peek_next: CursorList(E) × Cursor -> Option(E)
  • get / current: PositionalList × Cursor -> E
  • contains: PositionalList × E -> bool
  • position_of / index_of: List × E -> Option(Position)
  • iterate: List(E) -> Iterator(E)
Mutators
  • is_some: CursorList(E) × Cursor -> bool
  • is_none: CursorList(E) × Cursor -> bool
  • next: CursorList(E) × Cursor -> void
  • prev: CursorList(E) × Cursor -> void
  • insert_first / push_head: CursorList(E) × E -> void
  • insert_last / push_tail: CursorList(E) × E -> void
  • insert_before: CursorList(E) × E -> void
  • insert_after: CursorList(E) × E -> void
  • remove_current: CursorList(E) -> Option(E)
  • remove_first / pop_head: CursorList(E) -> Option(E)
  • remove_last / pop_tail: CursorList(E) -> Option(E)
  • insert_before: CursorList(E) × Cursor × E -> void
  • insert_after: CursorList(E) × Cursor × E -> void
  • set: CursorList(E) × Cursor × E -> E
  • split_before: CursorList(E) × Cursor -> CursorList(E)
    Mutates a list by splitting it before index i × ℕ
  • split_after: CursorList(E) × Cursor -> CursorList(E)
    Mutates a list by splitting it before index i × ℕ
  • splice_before: CursorList(E) × CursorList(E) × Cursor -> CursorList(E)
    Mutates a list by splitting it before index i × ℕ
  • splice_after: CursorList(E) × CursorList(E) × Cursor -> CursorList(E)
    Mutates a list by splicing it before index i × ℕ
  • remove: PositionalList × Cursor -> E
  • clear: PositionalList -> void

Representations

  • Doubly linked list with either public position handles or a cursor implementation
  • Array-based sequence with position handles

Positional List


Abstract Values

A finite sequence over a domain E, where each element is associated with a unique position P:
[(p_0, e_0), (p_1, e_1), …, (p_{n - 1}, e_{n - 1})]

where:

  • e_k ∈ E
  • p_k ∈ p, where P is the abstract position domain
  • Each p_k identifies exactly one element in the sequence
  • The positions are distinct and arranged in the sequence’s linear order

Behavioral Semantics

  • Duplicate elements are permitted.
  • The sequence may be empty.
  • Each element has a unique position.
  • Elements are ordered according to their positions.
  • Positions identify elements independently of their values.
  • A position remains associated with its element until that element is removed from the list.
  • Insertion and removal may change the numerical ranks of other elements without changing their positions.
  • The abstract value does not specify how positions are represented or maintained, though these are commonly represented as stable/safe pointer handles.

Interface

Creators
  • new / empty: -> PositionalList
Producers
  • concat: PositionalList × PositionalList -> PositionalList
Observers
  • size: PositionalList -> ℕ
  • is_empty: PositionalList -> bool
  • first: PositionalList -> Option(Position)
  • last: PositionalList -> Option(Position)
  • before: PositionalList × Position -> Option(Position)
  • after: PositionalList × Position -> Option(Position)
  • get: PositionalList × Position -> E
  • contains: PositionalList × E -> bool
  • position_of / index_of: List × E -> Option(Position)
Mutators
  • insert_first: PositionalList × E -> Position
  • insert_last: PositionalList × E -> Position
  • insert_before: PositionalList × Position × E -> Position
  • insert_after: PositionalList × Position × E -> Position
  • set: PositionalList × Position × E -> E
  • remove: PositionalList × Position -> E
  • clear: PositionalList -> void

Representations

  • Doubly linked list with either public position handles or a cursor implementation
  • Array-based sequence with position handles

Stack


Abstract Values

A finite sequence over a domain E.

Behavioral Semantics

  • Elements are ordered by their insertion history.
  • The most recently inserted element is the first element removed.
  • Insertion and removal occur only at the top.
  • Duplicates are permitted.
  • The abstract value does not specify a particular representation.

Interface

Creators
  • new: -> Stack
    Creates a new, empty stack
Observers
  • size: Stack -> ℕ
  • is_empty: Stack -> bool
  • top / peek / poll: Stack -> Option(E)
    Observes the most recently inserted element without modifying the stack, if an element exists
Mutators
  • push: Stack × E -> void
  • pop: Stack -> Option(E)
  • clear: Stack -> void

*NOTE: top and pop are partial on an empty stack. top pop removes and returns that element.

Representations

  • Dynamic array
  • Linked list
  • Static array, if a capacity bound is part of the representation

Queue


Abstract Values

A finite sequence over a domain E.

Behavioral Semantics

  • Elements are ordered by their insertion history.
  • The earliest inserted element is the first element removed.
  • Insertion occurs at the rear; removal occurs at the front.
  • Duplicates are permitted.
  • The abstract value does not specify a particular representation.

Interface

Creators
  • new: -> Queue
    Creates a new, empty queue
Observers
  • size: Queue -> ℕ
  • is_empty: Queue -> bool
  • front: Queue -> Option(E)
  • back: Queue -> Option(E)
Mutators
  • enqueue: Queue × E -> void
    Inserts an element e onto the back of the queue
  • dequeue: Queue -> Option(E)
    Removes and returns the front of the queue
  • clear: Queue -> void
    Removes all elements from the queue

Representations

  • Static or dynamic array
  • Linked list

Deque (Double-Ended Queue)


Abstract Values

A finite sequence over a domain E.

Behavioral Semantics

  • Elements are ordered by their insertion history.
  • Insertion and removal are permitted at both ends.
  • Duplicates are permitted.
  • The abstract value does not specify a particular representation.

Interface

Creators
  • new / empty: -> Deque
Observers
  • size: Deque -> ℕ
  • is_empty: Deque -> bool
  • front: Deque -> Option(E)
  • back: Deque -> Option(E)
Mutators
  • insert_front: Deque × E -> void
  • insert_back: Deque × E -> void
    Inserts an element n ∈ E onto the back of the queue, similar to the enqueue operation on the basic queue
  • remove_front: Deque -> Option(E)
    Removes and returns element n ∈ E from the front of the queue, if it exists; similar to the dequeue operation on the basic queue
  • remove_back: Deque -> Option(E)
  • clear: Deque -> void

*NOTE: Removal operations return the element removed from the corresponding end.

Representations

  • Circular array
  • Doubly linked list
  • Dynamic array with front and rear indices

Circular Queue


Abstract Values

A finite sequence over a domain E.

Behavioral Semantics

  • Elements are ordered by their insertion history.
  • The earliest inserted element is the first element removed.
  • Insertion occurs at the rear; removal occurs at the front.
  • Duplicates are permitted.
  • The abstract value does not require circular storage or wraparound indices; circularity is a representation-level property.
  • If the queue is bounded, its capacity is part of the specification.

Interface

Creators
  • new / empty: -> CircularQueue
Observers
  • size: CircularQueue -> ℕ
  • is_empty: CircularQueue -> bool
  • is_full: CircularQueue -> bool
    For a bounded circular queue of capacity C, is_full is true when size = c.
  • front: CircularQueue -> Option(E)
  • back: CircularQueue -> Option(E)
Mutators
  • enqueue: CircularQueue × E -> void
    Inserts an element n ∈ E onto the back of the queue; Capacity constraints and wraparound behaviors are specified in t he representation for bounded queues, otherwise grows dynamically sized queues
  • dequeue: CircularQueue -> Option(E)
  • clear: CircularQueue -> void

Representations

  • Fixed-capacity circular array
  • Dynamically resizing circular array
  • Circular linked list

Sorted List


Abstract Values

A finite sequence over an ordered domain E.

Behavioral Semantics

  • Elements are ordered according to a total order (<=).
  • The sequence is nondecreasing: [e_i <= e_{i + 1}]
  • Duplicates are permitted.
  • Insertion preserves the ordering property.

Interface

Creators
  • new / empty: -> SortedList(E)
Producers
  • merge: SortedList(E) × SortedList(E) -> SortedList(E)
Observers
  • size: SortedList(E) -> ℕ
  • is_empty: SortedList(E) -> bool
  • min: SortedList(E) -> Option(E)
  • max: SortedList(E) -> Option(E)
  • get_kth: SortedList(E) × ℕ -> Option(E)
    Returns the kth ranked element where query k ∈ ℕ
  • contains: SortedList(E) × E -> bool
  • successor: SortedList(E) x E -> Option(E)
    Returns the smallest element larger than the provided value of type E, if it exists, otherwise returns None
  • predecessor: SortedList(E) x E -> Option(E)
    Returns the largest element smaller than the provided value of type E, if it exists, otherwise returns None
  • floor: SortedList(E) × E -> Option(E) Returns the greatest element less than or equal to the query value, or None if no such element exists
  • ceiling: SortedList(E) × E -> Option(E) Returns the smallest element greater than or equal to the query value, or None if no such element exists
  • iter: SortedList(E) -> ListIter(E)
    Returns an iterator that yields the list’s elements in comparative (sorted) order
  • range_iter: SortedList(E) × R × R -> ListIter(E)
    Returns an iterator that yields the list’s elements in comparative (sorted) order between lower range bounds r ∈ R and upper range bounds r ∈ R
Mutators
  • insert: SortedList(E) × E -> void
  • remove: SortedList(E) × E -> Option(E)
  • remove_min: SortedList(E) -> Option(E)
  • remove_max: SortedList(E) -> Option(E)
  • clear: SortedList(E) -> void
  • iter_mut: SortedList(E) -> ListIter(E)

Representations

  • Sorted dynamic array
  • Sorted linked list
  • Skip list
  • Search tree, if the representation’s iteration semantics expose the sorted sequence

Associative ADTs

Associative ADTs organize elements around keys and support key-based lookup, membership, or retrieval.


Set


Abstract Values

Finite subsets of a domain E, such that: S ⊆ E, |S| < ∞

Behavioral Semantics

  • Elements are unique under the domain’s equivalence relation.
  • Element order is not part of the abstract value.
  • Membership is determined by equivalence.
  • A set may be empty.

Interface

Creators
  • new: -> Set(E)
Producers
  • retain_all: Set(E) x P -> Set(E)
    Non-mutating producer that returns a newly allocated set containing all elements e ∈ E from the input set for which predicate p(e) = true
Observers
  • size: Set(E) -> ℕ
  • is_empty: Set(E) -> bool
  • contains: Set(E) × E -> bool
  • subset: Set(E) × Set(E) -> bool
    Returns true if every element of the first set is also present in the second set (including when both sets are equal)
  • disjoint: Set(E) × Set(E) -> bool
    Returns true if the input sets have no elements in common, such that:
    a ∩ b = ∅
  • equals: Set(E) × Set(E) -> bool
    Returns true if and only if sets a, b ∈ Set(E) contain the same abstract elements regardless of their underlying representation, such that:
    a = b <=> ∀x ∈ E, (x ∈ a <=> x ∈ b)
  • union: Set(E) × Set(E) -> Union(E)
    Returns an iterator i ∈ Union(E) that yields all unique elements from input sets a, b ∈ Set(E), such that:
    a ∪ b = {x | x ∈ a ∨ x ∈ b}
  • intersection: Set(E) × Set(E) -> Intersection(E)
    Returns an iterator i ∈ Intersection(E) that yields every element common to both input sets a, b ∈ Set(E), such that:
    a ∩ b = {x | x ∈ a ∧ x ∈ b}
  • difference / asym_diff: Set(E) × Set(E) -> Difference(E)
    Returns an iterator i ∈ Difference(E) that yields all elements present in the first input set a ∈ Set(E), but not in the second input set b ∈ Set(E), as a set-theoretic asymmetric difference (relative complement), such that:
    a \ b = {x | x ∈ a ∧ x ∉ b}
  • unique / symm_diff: Set(E) × Set(E) -> Unique(E)
    Returns an iterator i ∈ Unique(E) that yields all elements present in exactly one of the input sets a, b ∈ Set(E), as a set-theoretic symmetric difference, such that:
    a △ b = {x | (x ∈ a) ⊕ (x ∈ b)}
Mutators
  • insert: Set × E -> bool
    The Boolean return indicates whether the argument e ∈ E was inserted
  • remove: Set × E -> bool
    The Boolean return indicates whether the query argument q ∈ E was removed
  • take: Set × E -> Option(E)
    Removes and returns the element equivalent to the specified query argument q ∈ E, returns None if the q was not found
  • extend: Set(E) x Set(E) -> Set(E)
    Mutates a base set with all of the elements of a 2nd set; a mutating version of union
  • clear: Set -> void
    Removes all elements from the set

Representations

  • Hash Table
  • Unordered Dynamic Array
  • Unordered Linked List
  • Bit set, for a suitably bounded or enumerable domain

Sorted Set


Abstract Values

Finite subsets of an ordered domain E.

Behavioral Semantics

  • Elements are unique under the set’s equivalence relation.
  • The domain has a total order compatible with that equivalence relation.
  • Iteration is in ascending order.
  • Set equality and membership do not depend on traversal order.

Interface

The ordinary Set interface applies, with these additional operations.

Observers
  • min: SortedSet -> E
  • max: SortedSet -> E
  • lower_bound: SortedSet × E -> Option(E)
  • upper_bound: SortedSet × E -> Option(E)
  • predecessor: SortedSet × E -> Option(E)
  • successor: SortedSet × E -> Option(E)
Mutators
  • remove_min: SortedSet -> E
  • remove_max: SortedSet -> E

Representations

  • Search tree
  • Skip list
  • Sorted dynamic array
  • Sorted linked list

Map


Abstract Values

A finite mapping from a key domain K to a value domain V:
[M: K -> V] as { Entry<k₁, v₁>, Entry<k₂, v₂>, … }

Equivalently, a finite set of key-value pairs in which each key occurs at most once. The pair notation is an abstract mathematical description; an implementation need not contain a concrete Entry<K, V> type.

Behavioral Semantics

  • Each key is associated with at most one value.
  • The key domain has an equivalence relation.
  • Lookup and removal are key-driven.
  • Inserting a binding for an existing key replaces its value.
  • Key-value pairs have no abstract ordering.

Interface

Creators
  • new: -> Map
Observers
  • size: Map -> ℕ
  • is_empty: Map -> bool
  • contains_key: Map × K -> bool
  • get: Map × K -> V
    Returns the value associated with the key, and is partial when the key is absent.
  • domain: Map -> Set(K)
  • equal: Map × Map -> bool
  • iterate: Map -> Iter(Entry)
  • iter_keys: Map -> Iter(K)
  • iter_vals: Map -> Iter(V)
Mutators
  • insert: Map × K × V -> Option(V) Binds k to v, replacing any prior value. Returns the previous value, if one existed.
  • try_insert: Map × K × V -> Option(V) Binds k to v only if k is absent. If k already exists, leaves the map unchanged and returns its associated value.
  • remove: Map × K -> Option(V) Removes the key’s binding and returns its value, if it exists.
  • clear: Map -> void

Representations

  • Hash table
  • Unordered array of key-value pairs
  • Unordered linked list of key-value pairs

Sorted Map


Abstract Values

Finite mappings (M: K -> V), where the key domain K is totally ordered.

Behavioral Semantics

  • All Map semantics apply.
  • The key order is part of the abstract behavior.
  • Traversal of bindings is in ascending key order.
  • Values themselves need not be ordered.

Interface

The Map interface applies, with the following additions:

Observers
  • min_key: SortedMap -> K
  • max_key: SortedMap -> K
  • predecessor_key: SortedMap × K -> Option(K)
  • successor_key: SortedMap × K -> Option(K)
  • range: SortedMap × K × K -> Iter(K × V) Returns bindings whose keys lie within the specified bounds; whether the bounds are inclusive or exclusive is part of its contract.
Mutators
  • remove_min: SortedMap -> K × V
  • remove_max: SortedMap -> K × V

Representations

  • Search tree
  • Skip list
  • Sorted array of key-value pairs
  • Sorted linked list

Hierarchical ADTs

Hierarchical ADTs exhibit hierarchical, parent-child structural organization.


Simple Priority Queue


Abstract Values

A finite multiset of elements of domain E associated with priorities of ordered domain P:
[{(p_1, e_1), (p_2, e_2), …, (p_n, e_n)}]

Behavioral Semantics

  • Each entry has a priority.
  • Entries may have equal priorities.
  • The queue exposes the entry with minimum priority (for a min-priority queue).
  • The abstract value does not prescribe a heap-shaped tree.

Interface

Creators
  • new: -> PriorityQueue
Observers
  • size: PriorityQueue -> ℕ
  • is_empty: PriorityQueue -> bool
  • min: PriorityQueue -> P × E
Mutators
  • insert: PriorityQueue × P × E -> void
  • extract_min: PriorityQueue -> P × E
  • clear: PriorityQueue -> void

Representations

  • Binary heap
  • d-ary heap
  • Binomial heap
  • Fibonacci heap
  • Unsorted array or linked list
  • Sorted array or linked list

Array-based representations may offer different operation costs; the ADT does not require heap structure.


Adaptable Priority Queue


Abstract Values

A finite collection of priority-element entries, where each entry is associated with a distinct abstract locator L.

Behavioral Semantics

  • Each active entry has a priority and element.
  • A locator identifies one active entry.
  • Updating or removing an entry by locator affects that entry.
  • Locators cease to be valid after their entry is removed.
  • Equal priorities are permitted.

Interface

Creators
  • empty: -> AdaptablePriorityQueue
Observers
  • size: AdaptablePriorityQueue -> ℕ
  • is_empty: AdaptablePriorityQueue -> bool
  • min: AdaptablePriorityQueue -> P × E
Mutators
  • insert: AdaptablePriorityQueue × P × E -> L
  • update_priority: AdaptablePriorityQueue × L × P -> void
  • update_element: AdaptablePriorityQueue × L × E -> void
  • remove: AdaptablePriorityQueue × L -> P × E
  • extract_min: AdaptablePriorityQueue -> P × E
  • clear: AdaptablePriorityQueue -> void

Representations

  • Locator-aware binary heap
  • Indexed heap
  • Heap combined with a locator-to-position map
  • Balanced search tree keyed by priority with locator support A heap combined with a map is a common representation strategy, but not a requirement of the ADT.

Search Tree


Abstract Values

Finite sets of values from a totally ordered domain T: [S ⊆ T, |S| < ∞]

A finite, strictly increasing sequence (no duplicates) of unique elements from a totally ordered domain T:
[[e_1, e_2, …, e_n] where e_i ∈ T, e_i < e_{i + 1}, 1 <= i < n, 0 <= n < ∞ ]

Behavioral Semantics

  • Each value is unique under the domain’s equivalence relation.
  • The domain T has a total order compatible with that equivalence relation.
  • Membership, insertion, and removal are based on value comparisons.
  • In-order traversal yields values in ascending order.
  • The abstract value does not specify a particular tree structure or balancing condition.

Interface

Creators
  • empty: -> SearchTree
Producers
  • union: SearchTree × SearchTree -> SearchTree
  • intersection: SearchTree × SearchTree -> SearchTree
  • difference: SearchTree × SearchTree -> SearchTree
Observers
  • size: SearchTree -> ℕ
  • is_empty: SearchTree -> bool
  • contains: SearchTree × T -> bool
  • *min: SearchTree -> T
  • *max: SearchTree -> T
  • predecessor: SearchTree × T -> Option(T) Returns the largest value smaller than query value t, if one exists in the tree.
  • successor: SearchTree × T -> Option(T) Returns the smallest value larger than query value t, if one exists in the tree.
  • iterate: SearchTree -> Iter
Mutators
  • insert: SearchTree × T -> bool Returns true if the tree was changed.
  • remove: SearchTree × T -> Option(T) Removes and returns the query value, if one exists in the tree.
  • *remove_min: SearchTree -> T
  • *remove_max: SearchTree -> T
  • clear: SearchTree -> void

*NOTE: min, max, remove_min, and remove_max are partial on an empty tree.

Representations

  • Unbalanced binary search tree
  • AVL tree
  • Red-black tree
  • B-tree
  • B+ tree
  • Treap

Relational ADTs

Relational ADTs represent relationships between elements through connections that are not restricted to linear or hierarchical organization.