Sorted sequence: Difference between revisions

From Algowiki
Jump to navigation Jump to search
Line 5: Line 5:
'''Representation invariant:'''
'''Representation invariant:'''
# The abstract data structure '''sorted sequence''' implements sorted sequences as defined [[Sets and sequences|here]].
# The abstract data structure '''sorted sequence''' implements sorted sequences as defined [[Sets and sequences|here]].
# This abstract data structure is [[Genericity|generic]] and parameterized by a fixed key type <math>\kappa</math> and a fixed [[Genericity|comparision]] <math>c</math> defined on <math>\kappa</math>.
# This abstract data structure is [[Genericity|generic]] and parameterized by a fixed key type <math>\kappa</math> and a fixed [[Genericity|comparison]] <math>c</math> defined on <math>\kappa</math>.


'''Constructor:''' Gets a [[Genericity|comparision]] <math>c</math> and initializes ths sequence so as to be empty.
'''Constructor:''' Gets a [[Genericity|comparison]] <math>c</math> and initializes ths sequence so as to be empty.


== Insert ==
== Insert ==

Revision as of 13:54, 9 May 2015


General Information

Representation invariant:

  1. The abstract data structure sorted sequence implements sorted sequences as defined here.
  2. This abstract data structure is generic and parameterized by a fixed key type [math]\displaystyle{ \kappa }[/math] and a fixed comparison [math]\displaystyle{ c }[/math] defined on [math]\displaystyle{ \kappa }[/math].

Constructor: Gets a comparison [math]\displaystyle{ c }[/math] and initializes ths sequence so as to be empty.

Insert

Input: A key [math]\displaystyle{ K \in \kappa }[/math].

Output:

Precondition:

Postcondition: A new element with the key [math]\displaystyle{ K }[/math] is inserted at the appropriate position in sorting order.

Traverse

Input:

Output: A Linear sequence [math]\displaystyle{ L }[/math] containing all elements of the sorted sequence in ascending order.

Precondition:

Postcondition: All keys of the sorted sequence are appended to [math]\displaystyle{ L }[/math] in ascending order.

Find

Input: A key [math]\displaystyle{ K \in \kappa }[/math].

Output: A Boolean value, which is true if, and only if, [math]\displaystyle{ K }[/math] is currently contained in the sequence.

Precondition:

Postcondition:

Remove

Input: A key [math]\displaystyle{ K \in \kappa }[/math].

Output: A Boolean value, which is true if, and only if, [math]\displaystyle{ K }[/math] is currently stored in the sequence.

Precondition:

Postcondition: If the output is true, one occurrence of [math]\displaystyle{ K }[/math] is removed.

Known Implementations

  1. B-Trees
  2. Binary Search Tree

Remark

  • The number, find, find at position, and remove methods are identical to those of Linear sequences, so they are omitted here.
  • For method traverse see also the remark on iterators for Linear sequences.