Array Rotation In Place using C++ (Juggling Algorithm)

preview_player
Показать описание
To Rotate an array by k positions to the left in-place i.e O(1) space complexity by Juggling Algorithm and creating a program/code using C++ to implement the logic of rotating the array by k positions using juggling algorithm.

0:00 What is Array Rotation?
1:08 Array Rotation In-Place Algorithm Explained
4:36 How to find the number of sets?
5:11 Juggling Algorithm using GCD
13:18 C++ Code for Array Rotation In Place

-------------------------------Source Code -------------------------------

-------------------------------Support Us -------------------------------

-------------------------------Like on Facebook -------------------------------

-------------------------------Follow on twitter --------------------------------

#arrayrotation #jugglingalgorithm #codewhoop
Рекомендации по теме
Комментарии
Автор

This is the best explanation of array rotation using Juggling Algorithm out there. It is better than the video by GeeksForGeeks. Thank you.

indianstate
Автор

Best explanation of juggling algorithm I've ever seen.

rajatgupta
Автор

What I think the idea/ need of using GCD in this algorithm is that it helps combining 2 cases into single case.
Think of this algo without GCD, then we have 2 scenarios, 1- When both n and k are multiples of each other, in this case we know that we will form n/k number of cycles/set and then move elements in those cycle iteratively (using j+d % n and when d == i then we will increment our outer loop) in this way we will go for each cycle.
2- When n and k are not multiples also think in a way that you want k(th) element on first position and likewise the succeeding elements so we will use the same approach (d+j % n till d == 0) in this case we will encounter d == 0 only one time and hence we know that will be the end of algorithms because before d will end up being 0 it will cover all the possible values.

So now if we see that these 2 conditions 1- when outer loop runs n/k times and 2- when outer loop will run only 1 time. this can be achieved or calculated using gcd(n, k).
So either increase your lines of code making 2 handling 2 different scenarios then you will be clear or if you understand this then apply GCD and make your code short.

harshitgarg
Автор

Best explanation of juggling algorithm I've ever seen. And by the way it is way better than the video by GeeksForGeeks. Thank you.

hemendiranbaskaran
Автор

bro, I just subscribed watching only this video of yours!
Hats off to your explanations!
don't stop making videos!

sarvottampriyadarshee
Автор

Best Explanation of this Problem I found on the Internet.Thanks.

kamleshbhalui
Автор

Till now i did not come across such a simple
Good job
Good animation
I watched 3 different tutorials but here I understood.
Thanks....

krishnaverma
Автор

Only video! which explains juggling algo very well.👍

ravindraverma
Автор

Seriously this is the best video I have seen till now, the way you have explained it was awesome. Thanks a lot for writing the blog as well.
This is a pure gem teaching style 💯

m.vineeth
Автор

better than any arrays rotation videos available so far i understood it so damn well thnx :)

neerajoberai
Автор

Nice work there, but modulo is effectively implemented by division, so with modern branch prediction and condition k<n it would probably be more efficient to do: d=j+k; if(d>=n) d-=n;
But juggling algorithm probably behaves bad on caches anyway as addresses spread over the whole array range; at least for large k this could be a problem.

QuantenMagier
Автор

Thanks dude, and explanation is so good🔥

adarshvaranasi
Автор

Thanks for the explanation with the help of a beautiful insight.❤

AkashVerma-ly
Автор

The best explanation for juggling algo !!!!

gamingwithhemend
Автор

Your explanation is precise, quick and straight to the point.

saikiransripada
Автор

Best explanation of juggling algorithm.. Thank you.. ♥️♥️♥️

IsteyakMahmud
Автор

Wow...so much clear cut explanation...thanks

RitikSharma-pcyj
Автор

Thanks for the concise explanation! Cheers!

rachitshukla
Автор

What's the intuition behind the gcd part?

dhairyapasrija
Автор

OMG sir you hit that topics so clearly, big thanks for you, help me a lot

vincent
welcome to shbcf.ru