3 ms·
Yes. Ignorant question: if you use bubble sort but go through the array in alternating senses, could it not improve locality and speed? Array v with N elements
by padf 3y ago
Yes. Ignorant question: if you use bubble sort but go through the array in alternating senses, could it not improve locality and speed?
Array v with N elements:
First pass: go from v[0] to v[N-1] comparing v[i] with v[i+i]
Second pass: go from v[N-1] to v[0] comparing v[i] with v[i+i]
This is so obvious that it should have a name...
- padf 3y agoAnswering myself. Yes, it was an ignorant question as the name is Cocktail Shaker sort: https://en.wikipedia.org/wiki/Cocktail_shaker_sort https://en.wikipedia.org/wiki/Cocktail_shaker_sort