swap n/2-1 with n/2+1 , and then n/2-3 with n/2+3 till we reach n-1 . so we need n/4 swaps .
On Sun, Sep 4, 2011 at 5:28 PM, Anup Ghatage <[email protected]> wrote: > That's interesting. > > when n = 3 > > We have been given this :F F F | E E E > > Swap the middle element and it becomes: F E F | E F E > > Which is what you want, but when n = 5 > > F F F F F | E E E E E > > And you swap the middle element it becomes: F F E F F | E E F E E > > So the same startegy doesn't apply. > > But if you do with from the center for every alternate element, it works > > for n = 3 > > F F F | E E E > F F E | F E E > E F E | E F E > > It also works for n = 5 etc. So, It is a more uniform solution if you may. > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
