Sie sind auf Seite 1von 13

2.

Sequence Algorithm Concepts

Section authors: David R. Musser and Brian Osman.

2.1. Sequence Algorithm


Algorithm 1.2


 
 
Input- Strategy-
Specialized 1.3 Specialized 1.4
 
 

 
 
Sequence Graph
Algorithm Algorithm 3.1
 
 

  
Comparison Based 2.2 Index Based 2.3 Predicate Based 2.4
  

A sequence algorithm is an algorithm (§1.2) that takes one or more linear


sequences as inputs.
Refinement of: Algorithm Specialized by Input (§1.3).
2.2. Comparison Based Sequence Algorithm

 
Input-
Specialized 1.3
 

 
Sequence
Algorithm 2.1
 

  
Comparison Based Index Based 2.3 Predicate Based 2.4
  

 
 
 
Sequence Sequence Heap
Sorting 2.6 Selection 2.7 Algorithm 2.10
 
 
 

A comparison based sequence algorithm is a sequence algorithm (§2.1)


whose computation depends on comparisons between pair of values in
the sequence. Such an algorithm depends upon a comparison operator,
one that is either previously defined as < or is passed to the algorithm. In
either case the comparison operator must compute a Strict Weak Ordering
(§5.1) on the value type of the sequence.

Refinement of: Sequence Algorithm (§2.1).


2.3. Index Based Sequence Algorithm

 
Input-
Specialized 1.3
 

 
Sequence
Algorithm 2.1
 

  
Comparison Based 2.2 Index Based Predicate Based 2.4
  

 
 
Sequence Sequence
Rotation 2.8 Reversal 2.9
 
 

An index based sequence algorithm is a sequence algorithm (§2.1) that


operates only on the positions within the sequence, independently of the
values stored.

Refinement of: Sequence Algorithm (§2.1).


2.4. Predicate Based Sequence Algorithm

 
Input-
Specialized 1.3
 

 
Sequence
Algorithm 2.1
 

  
Comparison Based 2.2 Index Based 2.3 Predicate Based
  

 
Partitioning
2.11
 

A predicate based sequence algorithm is a sequence algorithm (§2.1)


whose computation depends on the results of applying a given predicate
to values in the sequence.

Refinement of: Sequence Algorithm (§2.1).


2.5. Sequence Permuting Algorithm


Sequence


Algorithm 2.1

  
Comparison Index

Based 2.2

Permuting


Based 2.3

      
Sequence Heap Permutation Sequence Sequence Sequence Sequence








Merging 4.1 Algorithm 2.10Generation 11.1 Sorting 2.6 Selection 2.7 Reversal 2.9 Rotation 2.8

A sequence permuting algorithm is a sequence algorithm (§2.1) whose


output is a permutation of its input.

Refinement of: Sequence Algorithm (§2.1).


2.6. Sequence Sorting Algorithm

 
Sequence
Algorithm 2.1
 

 
Comparison Based 2.2 Permuting 2.5
 

 
Sequence
Sorting
 

   
Heapsort 2.6.1 Introsort 2.6.2 Mergesort 2.6.3 Quicksort 2.6.4
   

Refinement of: Comparison Based (§2.2), Permuting (§2.5), Sequence


Algorithm (§2.1).

Input: Iterators first and last delimiting a range of elements [first, last),
and optionally a comparison operator (§2.2) comp.

Output: A modified sequence of elements in the same range.

Effects:
• After execution, the elements in [first, last) are a permu-
tation (§2.5) of the input.
• After execution, the elements in [first, last) are in nonde-
creasing order according to the comparison operator defined
on the value type of the sequence or passed to the algorithm
as parameter comp.
2.7. Sequence Selection Algorithm

 
Sequence
Algorithm 2.1
 

   
Comparison Based 2.2 Permuting 2.5
   

 
Sequence
Selection
 

   
Linear Time
Hoare Select 2.12
  
Select 2.13


Refinement of: Comparison Based (§2.2), Permuting (§2.5), Sequence


Algorithm (§2.1).
Input: Iterators first, nth and last such that nth is in the range
[first, last), and optionally a comparison operator (§2.2) comp.

Output: A modified sequence of elements in the same range.


Effects:
• After execution, the elements in [first, last) are a permu-
tation (§2.5) of the input.
• After execution, the element pointed to by the iterator nth is
the same as the element that would be in that position if the
entire range [first, last) had been sorted, and none of the
elements in [nth, last) are less than any of the elements in
the range first, nth).
• The reordering is done according to the comparison operator
defined on the value type of the sequence or passed to the
algorithm as parameter comp.
2.8. Sequence Rotation Algorithm

 
Sequence
Algorithm 2.1
 
 
Index Based 2.3 Permuting 2.5
 
 
Sequence
Rotation
 

 
 
 
Forward Iterator Bidirectional Random Access
Rotation 2.7.1 Iterator Rotation 2.7.2 Iterator Rotation 2.7.3
 
 
 

Refinement of: Index Based (§2.3), Permuting (§2.5), Sequence Al-


gorithm (§2.1).

Input: Iterators first, middle, and last such that first and last de-
limit a range of elements [first, last) and the range [first, middle)
is a prefix of [first, last).

Output: A modified sequence of elements in the range [first, last).


Effects: After execution, the elements in [first, last) are those that
were in [middle, last) in the input, followed by those that were
in [first, middle) in the input.
2.9. Sequence Reversal Algorithm

 
Sequence
Algorithm 2.1
 

   
Index Based 2.3 Permuting 2.5
   

 
Sequence
Reversal
 

Refinement of: Index Based (§2.3), Permuting (§2.5), Sequence Al-


gorithm (§2.1).

Input: A sequence of elements in a range [first, last).

Output: A modified sequence of elements in the same range.

Effects: After execution, the elements in [first, last) are the same as
those in the input, but in the reverse order.

Das könnte Ihnen auch gefallen