-
hey! I have learned a lot from your code. About the Bitonic sort algorithm, I don'k know how to understand about :
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
where This is basically log(total elements size) if you think about it. If total elements is 8, it gives you 4, 2, 1 where you sort the pairs that are 4 apart, then 2 apart, then 1 apart. THIS you do over and over in a loop until entire elements are sorted.
|
Beta Was this translation helpful? Give feedback.
ij = i ^ j
,where
ij
is basicallyj
bits away fromi
in binary terms. This is to ensure proper pairing for sorting as this avoids duplicate pairs and such.Each element gets exactly one partner at the correct distance
No duplicates
No self-pairing
This is basically log(total elements size) if you think about it. If total elements is 8, it gives you 4, 2, 1 where you sort the pairs that are 4 apart, then 2 apart, then 1 apart. THIS you do over and over in a loop until entire elements are sorted.
i & k
determines whether the current element is in a bitonic sequence that should be sorted ascending or descending. Ifi & k == 0
, sort ascending. Ifi & k != 0
, sort descending.