3 ms·
Why bubble sort when a slight modification can create a still simple but much more respectable algorithm called "comb sort". https://www.delftstack.com/tutoria
by jqpabc123 3y ago
Why bubble sort when a slight modification can create a still simple but much more respectable algorithm called "comb sort".
https://www.delftstack.com/tutorial/algorithm/comb-sort/ https://www.delftstack.com/tutorial/algorithm/comb-sort/
- jqpabc123 3y agoComb sort tip --- instead of dividing by 1.3 use 1.333 (repeating) instead. In practical terms using integers, this makes almost no difference *except* it can be performed using faster shift and add operations: gap = ((gap << 1) + gap) >> 2; For even more speed, I'd also recommend in-lining this to eliminate the function call. Properly implemented, respectable speed can be achieved from a really trivial implementation.