Skip to content

Commit 8726f93

Browse files
committed
New issue from Jiang An: "Worst time complexity of non-parallel versions of nth_element is underspecified"
1 parent 49da918 commit 8726f93

File tree

1 file changed

+67
-0
lines changed

1 file changed

+67
-0
lines changed

xml/issue4162.xml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?xml version='1.0' encoding='utf-8' standalone='no'?>
2+
<!DOCTYPE issue SYSTEM "lwg-issue.dtd">
3+
4+
<issue num="4162" status="New">
5+
<title>Worst time complexity of non-parallel versions of <tt>nth_element</tt> is underspecified</title>
6+
<section><sref ref="[alg.nth.element]"/></section>
7+
<submitter>Jiang An</submitter>
8+
<date>29 Sep 2024</date>
9+
<priority>99</priority>
10+
11+
<discussion>
12+
<p>
13+
Currently, <sref ref="[alg.nth.element]"/> doesn't specify the worst time complexity for <tt>nth_element</tt>
14+
without <tt>ExecutionPolicy</tt> parameter, which seemingly allows a complexity that is
15+
<tt>&#x1d4aa;(<i>N</i><sup>2</sup>)</tt> or even worse. Presumably we should make the worst time complexity
16+
consistent between parallel and non-parallel versions. For <tt>sort</tt>, LWG <iref ref="713"/> already
17+
strengthened complexity requirements.
18+
</p>
19+
</discussion>
20+
21+
<resolution>
22+
<p>
23+
This wording is relative to <paper num="N4988"/>.
24+
</p>
25+
26+
<ol>
27+
<li><p>Modify <sref ref="[alg.nth.element]"/> as indicated:</p>
28+
29+
<blockquote>
30+
<pre>
31+
template&lt;class RandomAccessIterator&gt;
32+
constexpr void nth_element(RandomAccessIterator first, RandomAccessIterator nth,
33+
RandomAccessIterator last);
34+
template&lt;class ExecutionPolicy, class RandomAccessIterator&gt;
35+
void nth_element(ExecutionPolicy&amp;&amp; exec,
36+
RandomAccessIterator first, RandomAccessIterator nth,
37+
RandomAccessIterator last);
38+
template&lt;class RandomAccessIterator, class Compare&gt;
39+
constexpr void nth_element(RandomAccessIterator first, RandomAccessIterator nth,
40+
RandomAccessIterator last, Compare comp);
41+
template&lt;class ExecutionPolicy, class RandomAccessIterator, class Compare&gt;
42+
void nth_element(ExecutionPolicy&amp;&amp; exec,
43+
RandomAccessIterator first, RandomAccessIterator nth,
44+
RandomAccessIterator last, Compare comp);
45+
template&lt;random_access_iterator I, sentinel_for&lt;I&gt; S, class Comp = ranges::less,
46+
class Proj = identity&gt;
47+
requires sortable&lt;I, Comp, Proj&gt;
48+
constexpr I
49+
ranges::nth_element(I first, I nth, S last, Comp comp = {}, Proj proj = {});
50+
</pre>
51+
<blockquote>
52+
<p>
53+
[&hellip;]
54+
<p/>
55+
-5- <i>Complexity</i>: <del>For the overloads with no <tt>ExecutionPolicy</tt>, linear on average.
56+
For the overloads with an <tt>ExecutionPolicy</tt>,</del> <tt>&#x1d4aa;(<i>N</i>)</tt> applications
57+
of the predicate<del>,</del> and <tt>&#x1d4aa;(<i>N</i> log <i>N</i>)</tt> swaps, where <tt><i>N</i> =
58+
last - first</tt>. <ins>For the overloads with no <tt>ExecutionPolicy</tt>, <tt>&#x1d4aa;(<i>N</i>)</tt>
59+
on average.</ins>
60+
</p>
61+
</blockquote>
62+
</blockquote>
63+
</li>
64+
</ol>
65+
</resolution>
66+
67+
</issue>

0 commit comments

Comments
 (0)