Different Approaches to Perform an Array Rotation
Approach 5 - Reversal algorithm for rotate the array to the left or right by 'r' steps, where 'r' is non-negative.
Problem:
We have an array consisting of Integers ∈ Z of size (n) and a positive integer of rotation count (r) ∈ Z+.
We are allowed to shift each of the array's elements by one position.
We have to perform left or right rotations in an array.
Algorithm Concept:
Left Rotation
Reverse the last ‘r’ elements of the given array and then reverse the remaining ‘n-r’ elements followed by reversing the complete array elements.
Right Rotation
Reverse the last all elements of the given array and then reverse the remaining first 'r' elements followed by reversing the complete remaining ‘n-r’ elements.
Outline (check the comment section for a clickable version):
00:00 : Introduction
00:12 : Left Rotation | Algorithm Steps
01:05 : Time and Auxiliary Space Complexity Analysis
02:16 : Right Rotation | Algorithm Steps
02:46 : Animation Example
03:58 : Code Implementation of Algorithm
Code Available At:
https://sites.google.com/view/arrayro...
Other Approaches:
Approach 1 - Using Brute Force - • Array Rotation
Approach 2 - Using Temporary Variable - • Array Rotation | Temporary Variable
Approach 3 - Using Auxiliary Array - • Array Rotation | Auxiliary Array
Approach 4 - Using Juggling Algorithm - • Array Rotation | Juggling Algorithm
Approach 6 - Using Block Swap Algorithm - • Array Rotation | Block Swap Algorithm
Auf dieser Seite können Sie das Online-Video Array Rotation | Reversal Algorithm mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer DS Algo 06 June 2021 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 2,238 Mal angesehen und es wurde von 34 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!