Skip to content

question about bitonic sort algorithms #1

Answered by rbga
luohj29 asked this question in Q&A
Discussion options

You must be logged in to vote

ij = i ^ j,

where ij is basically j bits away from i 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. If i & k == 0, sort ascending. If i & k != 0, sort descending.

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@luohj29
Comment options

Answer selected by rbga
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants