Date
2025-01-22.00:00:00
Message id
14548

Content

For N5001, section [alg.merge] p5, it says for `merge()` Complexity (emphasis mine):

For the overloads with no `ExecutionPolicy`, at most N - 1 comparisons and applications of each projection

For N5001, section [alg.merge] p11, it says from `inplace_merge()` Complexity (emphasis mine):

Complexity: Let N = last - first:

  1. (11.1) — For the overloads with no `ExecutionPolicy`, and if enough additional memory is available, exactly N - 1 comparisons.

  2. (11.2) — Otherwise, 𝒪(N log N) comparisons.

This wording should be (emphasis mine)

Complexity: Let N = last - first:

  1. (11.1) — For the overloads with no `ExecutionPolicy`, and if enough additional memory is available, at most N - 1 comparisons.

  2. (11.2) — Otherwise, 𝒪(N log N) comparisons.

Consider the 2 sequences in a `std::vector` of `int`s and assume that `inplace_merge` has enough memory:

{ 1 }, { 2, 3, 4, 5, 6, 7 )

N is `7`, 7 elements. So N - 1 is `6`

If you `inplace_merge()` the two sequences, the `1` is compared with `2` and `1` is output. But now the 1st sequence is over, so the 2nd sequence is copied. Only 1 comparison is done, not 6.