ARRAY ROTATION

ARRAY ROTATION

This is a beginner level lab that deals with various approaches to solve questions related to array rotations.

 

WHAT WILL YOU LEARN:

  • Left rotation of arrays
  • Right rotation of arrays
  • Various approaches to rotate arrays along with their time complexities

 

PRE-REQUISITES:

Basic knowledge of arrays and C++.

 

Lets get started

 

RIGHT ROTATION

In right rotation, each element of the array will be shifted to its right by one position and the last element of the array will be kept at the first index. This process is continued a specified number of times, till the required output is obtained.

Lets take the same example array: 1,2,3,4,5 and right rotate it 3 times.

The array will look as follows after

  • the first rotation

                                      5 1 2 3 4

  • the second rotation

                                      4 5 1 2 3 

  • the third rotation

                                      3 4 5 1 2

 

So the output should be 3 4 5 1 2.

Discussion

19