Sorted sequence: Difference between revisions

From Algowiki
Jump to navigation Jump to search
Line 40: Line 40:
'''Input:''' A key <math>K \in \mathcal{K}</math>.
'''Input:''' A key <math>K \in \mathcal{K}</math>.


'''Output:''' A Boolean value, which is '''''true''''' if, and only if, <math>K</math> is currently stored in the sequence.
'''Output:''' A Boolean value, which is '''true''' if, and only if, <math>K</math> is currently stored in the sequence.


'''Precondition:'''
'''Precondition:'''


'''Postcondition:''' If the output is '''''true''''', one occurrence of <math>K</math> is removed.
'''Postcondition:''' If the output is '''true''', one occurrence of <math>K</math> is removed.


== Known Implementations ==
== Known Implementations ==
# [[B-Trees]]
# [[B-Trees]]
# [[Binary Search Tree]]
# [[Binary Search Tree]]

Revision as of 07:08, 18 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{ \mathcal{K} }[/math] and a fixed comparison [math]\displaystyle{ c }[/math] defined on [math]\displaystyle{ \mathcal{K} }[/math].

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

Insert

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

Output:

Precondition:

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

Traverse

Input:

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

Precondition:

Postcondition:

Find

Input: A key [math]\displaystyle{ K \in \mathcal{K} }[/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 \mathcal{K} }[/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