<p>It is possible, but it is very complicated! A simpler O(nlogn) and O(1) space solution might be better to code and in terms of cache.</p>

<p>We will solve a problem different from yours, but your problem is trivial to solve once we solve that problem.</p>

<p>Consider the array to be</p>

<pre><code>b1, a1, b2, a2, ..., bn, an
</code></pre>

<p>and you have to convert this to </p>

<pre><code>a1, a2, ..., an, b1, b2, ..., bn
</code></pre>

<p>Working with indices 1 to 2n,</p>

<p>we see that this is given by</p>

<pre><code>i -&gt; (n+1)*i (mod 2n+1).
</code></pre>

<hr>

<p><strong>An O(nlogn) time O(1) space solution</strong></p>

<p>We can use divide and conquer as follows.</p>

<p>First for some m close to n/2 convert</p>

<p><code>b1, a1, ..., bn , an</code> </p>

<p>to</p>

<pre><code>a1,a2,...am, b1,b2, ..bm, a(m+1), ..., an, b(m+1), ... , bn
</code></pre>

<p>by recursively applying to first 2m elements, and then the remaining.</p>

<p>Now all we need to do this cyclic shift the middle array by m spots (this can be done in O(n) time and O(1) space) </p>

<p>to give</p>

<pre><code>a1, a2, .., am , a(m+1), ..., an, b1, b2, ..., bm, b(m+1), ..., bn.
</code></pre>

<p>Of course, as IVlad pointed out, this needs O(logn) stack space. We can get around that by doing the following:</p>

<p>We have:</p>

<pre><code>b1 a1, b2 a2, .. bm am, b(m+1) a(m+1), ..., bn an
</code></pre>

<p>Now swap pairs in the latter part of the array to give</p>

<pre><code>b1 a1, b2 a2, .. bm am, a(m+1) b(m+1), ..., an bn
</code></pre>

<p>Now cyclic shift the elements at odd position: <code>b1, b2, .., bm, a(m+1), a(m+2) ..., a(n).</code></p>

<p>This gives something like</p>

<pre><code>a(m+1) a1, a(m+2) a2, ..., a(2m) am, a(2m+1) b(m+1),...,an b(n-m), b1 b(n-m+1),...,bm bn
</code></pre>

<p>Now again swap the latter part of the array to give</p>

<pre><code>a(m+1) a1, a(m+2) a2, ..., a(2m) am, b(m+1) a(2m+1),...,b(n-m) an,b(n-m+1) b1,..., bn bm
</code></pre>

<p>Now recursively solve the first part and second part to give</p>

<pre><code>[a1 a2 ... am][a(m+1) ... a(2m)]   [a(2m+1) ...an b1 b2 .. bm][b(m+1) ... bn]
</code></pre>

<p>This works whether 2m >= n or not.</p>

<p>So, this is O(nlogn) time and O(1) space algorithm.</p>

<hr>

<p><strong>An O(n) time O(1) space solution.</strong></p>

<p>The ideas used are similar to the ideas used in the following paper:
<a href="http://arxiv.org/abs/0805.1598" rel="nofollow noreferrer">A simple in-place algorithm for Inshuffle</a>.</p>

<p>You would need to read that paper to understand the below. I suggest you also read: <a href="https://stackoverflow.com/questions/2352542/how-to-master-in-place-array-modification-algorithms">How to master in-place array modification algorithms?</a></p>

<p>This is basically the inverse permutation of what is solved in the paper above.</p>

<p>It is enough to solve this when 2n+1 is a power of 3  = (3^m say), as we can use divide and conquer after that (like the O(nlogn) solution).</p>

<p>Now 2n+1 and n+1 are relatively prime, so working modulo 3^m, we see that n+1 <em>must</em> be some power of 2. (See that paper again to see why: basically any number modulo 3^m which is relative prime to 3^m is a power of 2, again modulo 3^m).</p>

<p>Say n+1 = 2^k (we don't know k yet and note this is modulo 3^m).</p>

<p>A way to find out k, compute powers of n+1 modulo 3^m, till it becomes 1. This gives us k (and is O(n) time at most).</p>

<p>Now we can see that the cycles of the permutation (see above paper/stackoverflow link for what that is) start at</p>

<p>2^a*3^b</p>

<p>where 0 &lt;= a &lt; k, and 0 &lt;= b &lt; m.</p>

<p>So you start with each possible pair (a,b) and follow the cycles of the permutation, and this gives an O(n) time, in-place algorithm, as you touch each element no more than a constant number of times!</p>

<p>This was a bit brief(!) and if you need more info, please let me know.</p>
in-place permutation of a array follows this rule
<p>Suppose there is an array, we want to find everything in the odd index (index starting with 0), and move it to the end.
Everything in the even index move it to the beginning.
The relative order of all odd index items and all even index items are preserved.</p>

<p>i.e. if the array is </p>

<pre><code>a1 b1 a2 b2 ...  an bn    
</code></pre>

<p>after the operation it becomes</p>

<pre><code>a1 a2 a3 ... an b1 b2 ... bn
</code></pre>

<p>Can this be done in-place and in O(n) time?</p>