What is the complexity of this sorting algorithm?

Revision en1, by BlueDiamond, 2020-03-26 23:13:03

Hi!

I was playing around with sorting algorithms and came up with this ideea ~~~~~

vector solve(vector a) { shuffle(a.begin(), a.end(), rng); int n = (int) a.size(); bool changes = 1; while (changes) { changes = 0; for (int x = 1; x <= n; x *= 2) { for (int i = 0; i + x < n; i++) { if (a[i + x] < a[i]) { swap(a[i], a[i + x]); changes = 1; } } } } return a; }

~~~~~

Tags stayathome

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en2 English BlueDiamond 2020-03-26 23:21:47 277 Tiny change: 'n\n~~~~~\nYour code here...\n~~~~~\n\' -> 'n\n~~~~~\n`vector<int> a`\n~~~~~\n\' (published)
en1 English BlueDiamond 2020-03-26 23:13:03 527 Initial revision (saved to drafts)