Q. Design Odd-Even Transposition Algorithm?
Algorithm: Odd-Even Transposition
for I=1 to N
{
If (I%2 != 0) //i.e. Odd phase
{
For j=1, 3, 5, 7,..................2*n/2-1
{
Apply compare-exchange (Pj, Pj+1) //Operation is performed in parallel
}
}
else // Even phase
{
For j=2, 4, 6, 8..................2*(n-1)/2-1
{
Apply compare-exchange (Pj, Pj+1) //Operation is performed in parallel
}
}
I++
}