All about flooble | fun stuff | Get a free chatterbox | Free JavaScript | Avatars    


Click to listen to the single ▶

Support album on Kickstarter
perplexus dot info

Home > Algorithms
Rotating an array (Posted on 2004-04-19) Difficulty: 2 of 5
I have an array such as A-B-C-D-E-F-G-H-I-J-K I want to rotate it N places to the right; for example, if N=3, the array should end I-J-K-A-B-C-D-E-F-G-H

Assume that the only available operation is a FLIP method that can invert any portion of the array. For example, applied to the original array FLIP(3,6) would produce A-B-F-E-D-C-G-H-I-J-K.

See The Solution Submitted by e.g.    
Rating: 4.0000 (13 votes)

Comments: ( Back to comment list | You must be logged in to post comments.)
Some Thoughts re: A possible way | Comment 16 of 26 |
(In reply to A possible way by Old Original Oskar!)

The sequence FLIP(L-1,L), FLIP(L-2,L-1), FLIP(L-3,L-2), ... FLIP(1,2) is equivalent to simply FLIP(1,L-1) followed by FLIP(1,L), so by doing N times those two sentences you get the desired result faster.

(Of course, this isn't as good as the three-FLIP algorithm...)
  Posted by Federico Kereki on 2004-04-20 08:03:01

Please log in:
Login:
Password:
Remember me:
Sign up! | Forgot password


Search:
Search body:
Forums (0)
Newest Problems
Random Problem
FAQ | About This Site
Site Statistics
New Comments (4)
Unsolved Problems
Top Rated Problems
This month's top
Most Commented On

Chatterbox:
Copyright © 2002 - 2014 by Animus Pactum Consulting. All rights reserved. Privacy Information