Base constructors of a ADT

Base constructors express how values of a certain ADT are constructed canonically (not as a result of other ADT operations). Base constructors are defined via their signature, which expresses how values of a certain type are constructed.

Define base constructors for the following types:

1. Binary tree with keys as integers (Tree)

2. FIFO (First-In First Out) with elements of an arbitrary type E (FIFO)

3. Map (A map is a one-to-one association of “keys” and “values”) with keys of an arbitrary type K and values of an arbitrary type V (Map)

ADT operators and their axioms

Operators are functionalities or operations available for the datatype at hand. Operators have:

  • a signature
  • a set of axioms which specify how the operator implementation should behave. There is no fixed recipe for finding proper axioms, but a good set of axioms usually:
    • specifies behaviour in terms of base constructors
    • is general enough
    • allows proving sensible properties of the ADT

2.1. Define axioms for the following operators:

  • size : Tree → Integer
  • height : Tree → Integer
  • mirror : Tree → Tree
  • flatten : Tree → List

2.2. Define operators and their proper axioms for:

  • the concatenation of two FIFOs
  • the operations top and dequeue used in a previous lecture (top produces the first-in element of the FIFO while dequeue returns a FIFO without this very element)

ADT implementation

Implement the ADT Tree and FIFO in Python, together with thier operations. Use two stacks to implement the FIFO. For the implementation, you may use classes, following the example shown in the lecture. To what extent can you use the axioms to provide correct implementations for each operation?

The ADT ''Map''

3.1. Define axioms for the following Map operations:

  • get which returns the value associated with a given key, if the key exists
  • update which modifies the value associated with a given key, if the key exists
  • is_defined which returns True if a certain key has a defined value
  • remove which deletes an entry based on it's key.

3.2. (Optional). Implement Map as a HashMap (ro: folosind tabele de dispersie).