-5
1
Write a sorting algorithm for a list of integers that has an average performance of O(n^2).
This is code-golf, so the shortest code in bytes wins.
RULES:
The characters wasted for the declaration of the list are not counted
(e.g.
var c = new List<int>() { 4, 2, 1, 3 };
is not counted)Builtins to sort a list are not allowed.
The best I did in C# is 82 ('c' is the list to be sorted):
var n=c.ToList();for(int i=0;i<n.Count;i++){int x=c.Min();c.Remove(x);n[i]=x;}c=n;
@AdmBorkBork notable difference is disallowing bogosort and not counting the list declaration, whatever that means. – Giuseppe – 2019-06-24T18:15:11.580
3
Welcome to Code Golf Stack Exchange! Since you're new, we do typically recommend using The Sandbox to get feedback on a challenge to make sure it's up to our usual standards or isn't a duplicate of an existing challenge; I think I'd agree with @AdmBorkBork that this really doesn't add much to the existing challenge and should be closed as a duplicate.
– Giuseppe – 2019-06-24T18:18:11.440Also, for the sake of being self-contained it should probably supply a definition of sorting. – Unrelated String – 2019-06-24T18:19:09.613
4This might be better received if you ask us to golf a specific sorting algorithm. Asking a question of the form "Do this thing but not this way" is generally ill-received (In this case restricting the use of a specific algorithm). Additionally there are other challenges that already ask for a golfed sorting such as the one AdmBorkBork linked. Because of that, this will likely get closed as a duplicate since, as Giuseppe mentioned, this challenge isn't really adding anything interesting over those challenges. – Poke – 2019-06-24T18:19:15.437
1And if bogosort and variants thereof are to be excluded then a rigorous definition of bogosort variant is probably warranted. I feel like
p≤₁
in Brachylog is probably not in the spirit of that rule, but it complies with the letter. – Unrelated String – 2019-06-24T18:21:42.123@AdmBorkBork I edited the question to clarify it. – Bip – 2019-06-24T18:50:34.947
1
Generally on CGCC the code is a full program or function, and input and output are accepted with the default I/O rules.
– lirtosiast – 2019-06-25T01:31:39.8002This challenge was reopened after Bip edited it the first time. Can the folks who closed it again please at least comment to add more context about why it was put on hold again? – Poke – 2019-06-25T14:08:17.770
1"an average performance of O(n^2)" isn't exactly clear, since big-O refers to worst-case time complexity, not average case. Also, perhaps the question should clarify input methods, because the example one uses variable assignment, which we don't generally allow. – mbomb007 – 2019-06-25T19:17:03.707