Array Rotation | Reversal Algorithm

Pubblicato il: 06 giugno 2021
sul canale di: DS Algo
2,238
34

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  


In questa pagina del sito puoi guardare il video online Array Rotation | Reversal Algorithm della durata di ore minuti seconda in buona qualità , che l'utente ha caricato DS Algo 06 giugno 2021, condividi il link con amici e conoscenti, su youtube questo video è già stato visto 2,238 volte e gli è piaciuto 34 spettatori. Buona visione!