(no title)
okaleniuk | 5 months ago
For instance, all the sorting algorithm turn to, effectively, bubble sort since without branches, you always go with the worst case - and the sorting complexity is always the O(n^2). But it's okay, since the algorithm becomes predictable. You just swap a conditional swap:
if a < b then swap(a, b)
with arithmetic swap: c = (a+b)/2
d = |a-b|/2
a = c + d
b = c - d
and that's it.
ashdnazg|5 months ago
I suspect everyone turns to Bubblesort since the inputs are small enough that it doesn't matter (evident by the fact that it should fit within microseconds).