The idea was not to go through a cycle every time.
For example i you start from A2 and the cycle is A2, A3, ....
When you go back to A2 do not traverse the same cycle from A3 but
proceed searching unprocessed elements.
This will work if the content of the cells is something similar to {int
number, bool bAlreadyProcessed }
It will also work if there is some function returning that
f(cellContent) = Ai. From the function you will know whether the
content of the cell was moved or not.
So in this case you have N-2 replacements + N/2 searchs for a begining
of a cycle(just the begining, don't traverse the whole cycle if it
already was).
If the content of the cell is an Random Number this algo will not work
but I think one modification will work:
First I think cycles arize when N=2^p , p - an integer.
The length of every cycle is an number L. = f(p)
if you start from cell at position x=f(p,N) , and at the next cycle
from x+1 .... x+N/p this will make the expected result.
--~--~---------~--~----~------------~-------~--~----~
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-beta.google.com/group/algogeeks
-~----------~----~----~----~------~----~------~--~---