Skip to content

Commit 390d817

Browse files
committed
Sorting, Measures of disorder, and Worst-case performance
1 parent fd13fcc commit 390d817

File tree

4 files changed

+21
-4
lines changed

4 files changed

+21
-4
lines changed

docs/Measures-of-presortedness.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ In other domains, that value is called *F* (for *Footrule*). It is no more helpf
329329

330330
### *Par*
331331

332-
*Par* was described by V. Estivill-Castro and D. Wood in *A New Measure of Presortedness* as follows:
332+
*Par* is described by V. Estivill-Castro and D. Wood in *A New Measure of Presortedness* as follows:
333333

334334
> *Par(X)* = min { *p* | *X* is *p*-sorted }
335335
@@ -343,6 +343,10 @@ The following definition is also given to determine whether a sequence is *p*-so
343343
344344
In their subsequent papers, those authors consistently use *Dis* instead of *Par*, often accompanied by a link to *A New Measure of Presortedness*.
345345

346+
### *Pos*
347+
348+
*Pos* is described by V. Estivill-Castro and D. Wood in *Sorting, Measures of disorder, and Worst-case performance* as "the position number": the number of elements in a sequence that are not in their sorted position. This definition matches that of *Ham*, the Hamming distance between a sequence and its sorted permutation.
349+
346350
### *Radius*
347351

348352
T. Altman and Y. Igarashi mention the concept of *k*-sortedness and the measure *Radius*(*X*) in *Roughly Sorting: Sequential and Parallel Approach*. However *k*-sortedness is the same as *p*-sortedness, and *Radius* is just another name for *Par* (and thus for *Dis*).

include/cpp-sort/probes/ham.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2016-2022 Morwenn
2+
* Copyright (c) 2016-2025 Morwenn
33
* SPDX-License-Identifier: MIT
44
*/
55
#ifndef CPPSORT_PROBES_HAM_H_
@@ -110,7 +110,7 @@ namespace probe
110110
static constexpr auto max_for_size(Integer n)
111111
-> Integer
112112
{
113-
return n == 0 ? 0 : n;
113+
return n;
114114
}
115115
};
116116
}

tests/probes/ham.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
/*
2-
* Copyright (c) 2016-2022 Morwenn
2+
* Copyright (c) 2016-2025 Morwenn
33
* SPDX-License-Identifier: MIT
44
*/
55
#include <forward_list>
66
#include <iterator>
77
#include <vector>
88
#include <catch2/catch_test_macros.hpp>
9+
#include <rapidcheck.h>
10+
#include <rapidcheck/catch.h>
911
#include <cpp-sort/probes/ham.h>
1012
#include <cpp-sort/utility/size.h>
1113
#include <testing-tools/distributions.h>
@@ -46,4 +48,8 @@ TEST_CASE( "presortedness measure: ham", "[probe][ham]" )
4648

4749
CHECK( ham(collection) == 0 );
4850
}
51+
52+
rc::prop("Ham(X) ≠ 1", [](const std::vector<int>& sequence) {
53+
return cppsort::probe::ham(sequence) != 1;
54+
});
4955
}

tests/probes/relations.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ TEST_CASE( "relations between measures of presortedness", "[probe]" )
8383
return rem(sequence) <= 2 * exc(sequence);
8484
});
8585

86+
// Sorting, Measures of disorder, and Worst-case performance
87+
// by Vladimir Estivill-Castro and Derick Wood
88+
89+
rc::prop("Rem(X) ≤ Ham(X)", [](const std::vector<int>& sequence) {
90+
return rem(sequence) <= ham(sequence);
91+
});
92+
8693
// Encroaching lists as a measure of presortedness
8794
// by Steven S. Skiena
8895

0 commit comments

Comments
 (0)