Tower of Hanoi | Recursion

  Рет қаралды 165,495

Aditya Verma

Aditya Verma

4 жыл бұрын

The tower of Hanoi is a famous puzzle where we have three rods and N disks. The objective of the puzzle is to move the entire stack to another rod. You are given the number of discs N. Initially, these discs are in the rod 1. You need to print all the steps of discs movement so that all the discs reach the 3rd rod. Also, you need to find the total moves.
Problem Description: practice.geeksforgeeks.org/pr...
The Notes that I taught in the video and the Working Code (if any) will be available on my Patreon page under the "Notes, Code And Support" tier.
Link: / adityaverma
Video Pdf Notes: / 38704739 .
------------------------------------------------------------------------------------------
Here are some of the gears that I use almost everyday:
🖊️ : My Pen (Used in videos too): amzn.to/38fKSM1
👨🏻‍💻 : My Apple Macbook pro: amzn.to/3w8iZh6
💻 : My gaming laptop: amzn.to/3yjcn23
📱 : My Ipad: amzn.to/39yEMGS
✏️ : My Apple Pencil: amzn.to/3kMnKYf
🎧 : My Headphones: amzn.to/3kMOzM7
💺 : My Chair: amzn.to/385weqR
🛋 : My Table: amzn.to/3kMohtd
⏰ : My Clock: amzn.to/3slFUV3
🙋🏻‍♀️ : My girlfriend: amzn.to/3M6zLDK ¯\_(ツ)_/¯
PS: While having good gears help you perform efficiently, don’t get under the impression that they will make you successful without any hard work.

Пікірлер: 353
@atulpant6369
@atulpant6369 4 жыл бұрын
Priest logo n bolo thoda zyada hora h but its ok 😆😆😆 Great content as usual 👍
@TheAdityaVerma
@TheAdityaVerma 4 жыл бұрын
😅😅 Thanks !!
@ps7072
@ps7072 4 жыл бұрын
😂😂
@ru2979
@ru2979 2 жыл бұрын
😂🤣🤣🤣
@pprathameshmore
@pprathameshmore 2 жыл бұрын
Yeah sahi tha!
@anonmityslayer
@anonmityslayer 7 ай бұрын
How casually bhaiya said this 😅😅😅
@sambhute1991
@sambhute1991 3 жыл бұрын
Every time I do a recursion problem: My Time Complexity: " Thoda jyada ho rha hai par thik hai"
@tarunstv796
@tarunstv796 2 жыл бұрын
kzbin.info/www/bejne/jHSXh2ltppeee80
@CodingEnv
@CodingEnv 2 жыл бұрын
Brahmaji bole "coding kar lo , placement aa raha hai". You are the best teacher. The way you explain the complex concepts in simple manner, it is really amazing. Thanks a lot.
@sumitkeshav4718
@sumitkeshav4718 4 жыл бұрын
Bhai u will revolutionize the teaching standards on youtube!!!. Well for me, i think you have already done it. Hats off bro.
@ronitkumar19
@ronitkumar19 Жыл бұрын
Mark the words ...one of the best playlist available for recursion!!!! :)
@AnkushKumar-mk8ns
@AnkushKumar-mk8ns 4 жыл бұрын
Others: Tower of hanoi. Aditya verma: Tower of brahma.😂 Thank you sir for making this playlist. I hope, further we will get more content. 🙏
@basketballlove1540
@basketballlove1540 3 жыл бұрын
Your teaching style is just amazing. Please keep uploading this type of amazing content.
@Amitkumar-fo1lv
@Amitkumar-fo1lv 3 жыл бұрын
6:40 bahut pitogee... 😂😂 bhramaji rocked..!
@TheAdityaVerma
@TheAdityaVerma 3 жыл бұрын
😅 Bhramaji's Thug Life
@ManuSingh-lt8wr
@ManuSingh-lt8wr 3 жыл бұрын
😂🤣
@anniebhalla1237
@anniebhalla1237 3 жыл бұрын
Recursion is seriously magic!! And the way you explain it is so amazing !
@googlepay4295
@googlepay4295 2 жыл бұрын
but im getting demotivated .. not able to solve any questions from past 25 days
@nopecharon
@nopecharon 2 жыл бұрын
@@googlepay4295 Don't play PUBG
@googlepay4295
@googlepay4295 2 жыл бұрын
@@nopecharon seriously bro ....its jus name 🤣🤣🤣
@googlepay4295
@googlepay4295 2 жыл бұрын
My younger did this
@ajitdhayal1612
@ajitdhayal1612 4 жыл бұрын
Brahmaji bhi coding kerte the😂😂
@TheAdityaVerma
@TheAdityaVerma 4 жыл бұрын
😅😅
@TheAdityaVerma
@TheAdityaVerma 4 жыл бұрын
Brahmaji ki Jay 🙏🙏❤️
@shivamshaw5867
@shivamshaw5867 4 жыл бұрын
Aur hum bhi karenge☺️☺️☺️
@akashpurbia4390
@akashpurbia4390 4 жыл бұрын
he created universe(brahmaand) so yes.
@sankalparora9261
@sankalparora9261 3 жыл бұрын
yeah, that was good.
@mayankguptacse5904
@mayankguptacse5904 4 жыл бұрын
Never came across such a unique way of teaching things. Thanks for such a great content . Brahmaji ki Jay :)
@aniketmore7409
@aniketmore7409 2 жыл бұрын
great job bro!!! you've very unique and great way of teaching things!! you made such complex things so easy !! I appreciate it bro !!
@ShabnamKhan-cj4zc
@ShabnamKhan-cj4zc 3 жыл бұрын
Thank you very much for this video as you are the only one who explained why disk needs to move from source to helper first instead of making statement that it has to be moved. Thanks again for focussing on explaining the logic instead of memorize something.
@entc_khushalnikam8124
@entc_khushalnikam8124 2 жыл бұрын
Was stuck at this problem from so long . Great explanation . Thank you for these ❤️
@shaikirfanameer359
@shaikirfanameer359 4 жыл бұрын
bhai how u r teaching in unique manner i think u were blessed with it
@TheAdityaVerma
@TheAdityaVerma 4 жыл бұрын
Thanks brother, just developed my own way of learning things !! 😅
@shaikirfanameer359
@shaikirfanameer359 4 жыл бұрын
I watched ur every video but today i felt like if i comment today u'll reply me Finally it Happened 😍
@TheAdityaVerma
@TheAdityaVerma 4 жыл бұрын
Haha, even if I am unable to reply to every comment on the channel. I make sure to read each and everyone of them !! So don't worry brother, your blessings and comments are reaching out to me. ❤️
@divyanshuyadav5524
@divyanshuyadav5524 3 жыл бұрын
@@TheAdityaVerma sahi h ❤️
@visheshagrawal8676
@visheshagrawal8676 Жыл бұрын
From a long time I couldn't able to understand this problem but I got confidence to solve problems similar like this... really improved my way of thinking of recursion
@jatinoza3099
@jatinoza3099 2 жыл бұрын
Wow, TBH now i am getting a great confidence in this recursion... really great playlist
@kamalkumar7133
@kamalkumar7133 3 жыл бұрын
sir u r great. GFG waalo ne dimag ka dahi kar diya thaa aapne achcha sikhaya.🤩🤩
@reckonmazumdar3063
@reckonmazumdar3063 3 жыл бұрын
This is some next level way of teaching !!!
@AmarMishra
@AmarMishra 2 жыл бұрын
Great visualization in explaining this. Visualization will help retain the problem. Thanks.
@babitas5381
@babitas5381 2 жыл бұрын
you've made life easier for me this is pure gold content, thanks a lot bhaiya 😊
@ananysharma9290
@ananysharma9290 4 жыл бұрын
Sir Again You explained it in a Really Great manner , love your Channel , Please please Upload Graphs Too
@tomriddle2427
@tomriddle2427 2 жыл бұрын
Aditya... Man you have a great knack of storytelling and that's the reason why you teach so very well. Loved the story... Never have heard it before and the way you narrated it seriously I laughed for like whole of that story time 😂. Thanks a lot.
@priyaanshhuu
@priyaanshhuu 9 ай бұрын
this was never so easy to understand aditya bhaiya, you really meant it when you said you would convert us into jedis of recursion, thankyou for doing what you're doing!! :D
@shailypatel585
@shailypatel585 2 жыл бұрын
Grate i don't have word to thank you Bro!! mene bhot sare videos dekhe par kisise bhi smj nai aaya even gate ki preparation m bhi sir ne pdaya lekin smj nai aaya but because of you I understood it very clearly !! thank you so much
@sahilanand30
@sahilanand30 2 жыл бұрын
What a explanation 🔥 Hats off ♥
@Ashish123
@Ashish123 3 жыл бұрын
thanks a lot mere bhai for the explanation of the code because i was confused how its code work but now you have cleared all my doubts :-)
@kaanchacheena8087
@kaanchacheena8087 2 жыл бұрын
Great way of teaching, keep going brother !!!
@ntesla5
@ntesla5 4 жыл бұрын
wonderful explaination as usual
@aryapandey4576
@aryapandey4576 2 жыл бұрын
And then he said "to priest logo ne bola, "yaar ye thoda zyada ho rha hai par chalo okay"" Couldn't help laughing xDD Your content is so easy to understand :")
@aashishsah2110
@aashishsah2110 2 жыл бұрын
Just Checked out your channel!! Hope you become a better coder and KZbinr than aditya!✌️
@aryapandey4576
@aryapandey4576 2 жыл бұрын
Haha, maybe in another world, thanks for checking out! Means a lot :)
@vrajupadhyay4755
@vrajupadhyay4755 2 жыл бұрын
amazing teaching way of yours thank you.
@vibhutiagrawal5105
@vibhutiagrawal5105 2 жыл бұрын
The most hilarious line for me was, brahma ji ne bola, 'choti plate ke upar badi plate mat rakh dena bohot pitoge' XD. You make this too fun bhai
@human75788
@human75788 2 жыл бұрын
Outstanding Teaching!
@shubhankarmane3172
@shubhankarmane3172 3 жыл бұрын
This is the best video on Towers of Hanoi.
@ritikgalgate7783
@ritikgalgate7783 3 жыл бұрын
Sir mene bhot sare videos dekhe tower of hanoi k lekin mujhe samajh nhi aa rha tha . apka video dekh k mujhe ache se samajh aa gaya .thank you sir
@AbhishekGupta-cr1mf
@AbhishekGupta-cr1mf 3 жыл бұрын
Bahut Behtarinnnn.... tarike se samjh Aa gya , Aaditya BHai 👍👍😎😎 ->> KOi gold medal do Inko 😆
@nishanb9721
@nishanb9721 3 жыл бұрын
Great content 🔥
@kumarirashmi6828
@kumarirashmi6828 4 жыл бұрын
Thank u bhaiya for such a wonderful explanation
@armaankashyap366
@armaankashyap366 2 жыл бұрын
Nyccc bro mene abhi bahut jagah se samjha iska code but meko yaha se clear ho gaya thanku bhaai 🤗
@harshvardhandixit5046
@harshvardhandixit5046 2 жыл бұрын
Thanks a lot I'll never have to memorize the TOH code ever again!
@ChandanKumar-wf5sx
@ChandanKumar-wf5sx 3 жыл бұрын
Pahali baar kisi ne TOH itne unique aur easy way me samjhaya.. Thanks Aditya bhaiya.. (Aap hamare liye Bramhaji ke Priest ho)
@RicheshGuptaRichu
@RicheshGuptaRichu 3 жыл бұрын
video bnana khtm kr doge to universe waps restart ho jaegi
@arbaajkhan4591
@arbaajkhan4591 4 жыл бұрын
Bhai level h seriously , amazing 💯💯
@utkarshgautam1940
@utkarshgautam1940 2 жыл бұрын
code padhne m aur samjane m fark hota hai ,this is is teching how to write code,@Aditya bhiya love u
@sachetansabhahit6235
@sachetansabhahit6235 3 жыл бұрын
TOB was never this easy bro. Hats off
@aadil4236
@aadil4236 Жыл бұрын
The best part about the video was the Bhrama story. I loved it. What an amazing story. I heard a story about where a Peasent goes to a King for some rice. So the King asks how much rice does he needs. The Peasent says he needs a single grain of rice for each square in a chess board. The only condition is that you have to double the rice of grain each time you go to a new square. The King was a fool so he agreed to the deal. 2^64 grain of rice is quite much. How much? Well as a proud/weird nerd I went to the internet to find the answer. As it turns out 2^64 grain of rice is roughly equivalent to a millennium(1000 years) of our entire plantes rice production. Yikes!!
@Bharat_Rider
@Bharat_Rider 10 ай бұрын
Great video 👍👍
@kush3764
@kush3764 Жыл бұрын
Thank you bhai especially for the Amazing story...
@NiteshKumar-dn4em
@NiteshKumar-dn4em Жыл бұрын
Bhaiya aap same Love Babbar ki tarah samjhate ho....dono hi ek dam OP ho...concept crystal clear ho jate h🙌
@rashikakurhade3499
@rashikakurhade3499 2 жыл бұрын
Well I must say anyway good teacher is a great story teller. Look at you!!
@babbarutkarsh7770
@babbarutkarsh7770 4 жыл бұрын
Bhai feel aa gyi aaj.🔥
@kailashchandra2666
@kailashchandra2666 Жыл бұрын
one of the best technique......Best mentor🤩🤩🤩🤩🤩🤩
@manavkampani594
@manavkampani594 2 жыл бұрын
This is the funniest video of the series till yet.
@degavathanandnayak9692
@degavathanandnayak9692 3 жыл бұрын
Great explanantion!
@harshalgarg1149
@harshalgarg1149 3 жыл бұрын
So helpful. 😍
@kishanmishra9802
@kishanmishra9802 3 жыл бұрын
Great teacher
@666_kanishkanarayan3
@666_kanishkanarayan3 3 жыл бұрын
18:29 previously when you pass the first argument as n, then how are you receiving with int s which has been given for starting point and n is for no. of plates.
@RohitSharma-hd4me
@RohitSharma-hd4me 3 жыл бұрын
me - which compiler do you use ?? brahma ji - priest
@hope-jh7bv
@hope-jh7bv 3 жыл бұрын
Thank you so much sir.
@ExplooreWithManoj
@ExplooreWithManoj 3 жыл бұрын
Nice explanation...
@vishalgupta9620
@vishalgupta9620 2 жыл бұрын
I have a question , this was a little complex solution that had too many variables to track for dry running this code on paper but that didn't matter because of recursion and we solved it easily if we come across a rec code of similar type and had understand it without compiling it can we do it like we solved it (from n to n-1 i mean ) will that be ok
@sumitsaini589
@sumitsaini589 3 жыл бұрын
Hahaha Nice concept man xD Love your videos ;)
@kairatopa9564
@kairatopa9564 4 жыл бұрын
Great bro
@shubhampokhriyal8491
@shubhampokhriyal8491 4 жыл бұрын
Awesome bhaiya
@usmanaliansari5223
@usmanaliansari5223 Жыл бұрын
for count we can directly print that using maths i.e. n disks can be solved in minimum 2^n−1 steps.
@roushanraj8530
@roushanraj8530 3 жыл бұрын
#storytelling awesome bhaiya 😍😍 Brahmaji apne aditya bhai ko ye task dete, ek program me khel khtm, 😅😅
@hrithikdhanraj2919
@hrithikdhanraj2919 2 жыл бұрын
.Achcha hai nhi diya wrna sab chutkiyo me finish
@nopecharon
@nopecharon 2 жыл бұрын
You are the best teacher
@deepthiacharya9991
@deepthiacharya9991 Жыл бұрын
Thank you sooo much sir🥺❤
@charanreddy5227
@charanreddy5227 Жыл бұрын
is this algorithm applicable for 4 discs? For the four discs problem we will use source aswell for the transferring the discs.
@sumitapathak2900
@sumitapathak2900 3 ай бұрын
"zyada ho rha hai par kar lenge" was 😅😂 Amazing lecture
@PythonGuruji
@PythonGuruji 3 жыл бұрын
bro mouse se itni jldi likh lete ho ya fr touch pad laptop ka??
@rishikeshkumarsingh3283
@rishikeshkumarsingh3283 4 жыл бұрын
maza aa gya story sun ke..
@amartyadas5-yriddmechanica597
@amartyadas5-yriddmechanica597 2 жыл бұрын
Today I understood the term "Recursion works like magic"
@jayantkumar4-yearb.tech.ci302
@jayantkumar4-yearb.tech.ci302 2 жыл бұрын
Brahma ji v coding karte the , toh chalo hamlog v karte h. hamlog toh Aditya bhai aapkji wajah se kar paa rhe h Thanks bro..
@worldcitizen7890
@worldcitizen7890 3 жыл бұрын
bohot zabardast video hai bhai...bas agli bar thoda short rakhna best of luck
@msk9414
@msk9414 2 жыл бұрын
The order of plates to be moved is FIFO i.e 2nd, 3rd, 4th plate from bottom. The poles are not representing stack.
@mrdevtelugu
@mrdevtelugu Жыл бұрын
Wah I loved the introduction
@sarthaktomar4686
@sarthaktomar4686 6 ай бұрын
Real power of recursion!!!!!!!!!💪💪💪💪
@sanjayjoshi8807
@sanjayjoshi8807 3 жыл бұрын
where did you learn this from because never seen such an explanation like this bro plz tell this bro !! you are amazing liked and subscribed and make a video on books and online material for the best understanding of ds and algo as you used !!!!!!
@TheAdityaVerma
@TheAdityaVerma 3 жыл бұрын
haha I didnt learn this from anywhere, as the time passed I started to make my own methods and started to see patterns that were never mentioned anywhere before. You will too, just keep practising.
@sanjayjoshi8807
@sanjayjoshi8807 3 жыл бұрын
@@TheAdityaVerma okay bhaiya thankyou ! keep growig
@immagod5285
@immagod5285 Жыл бұрын
Bro this is just💙❤️
@aasthagoyal5059
@aasthagoyal5059 3 жыл бұрын
Bhaiya sbse phle jo sbse niche disk hai vo move kregi ya jo sbse upr hai... Jo diagram apne btaya usme last disk move kregi?
@piyushmishra4988
@piyushmishra4988 4 жыл бұрын
bro, which tools you use for video recording and writing?
@yatinarora1252
@yatinarora1252 3 жыл бұрын
he is using some sort of ipad for writing and for recording it must be kine master
@alringeorgesabu4391
@alringeorgesabu4391 3 жыл бұрын
Nice bro
@pranayreddyannam188
@pranayreddyannam188 2 жыл бұрын
Very Nice
@bennet615
@bennet615 2 жыл бұрын
sir suppose 3 plates li hai to jab aap 1st plate ko vaps from destination to source bhejoge vo kahan par ho raha hai , vo mujhe smamjh nahi aa raha , could you please explain that
@ShubhamKumar-lb9lf
@ShubhamKumar-lb9lf 4 жыл бұрын
Ismai bhi recursively bottom mai insert ni kr sakte hai kya? Jaise ki stack mai kiya tha
@caspers8933
@caspers8933 Жыл бұрын
Can anyone suggest me a good course for DSA like this one for other topics
@hrishikeshmishra-tl7le
@hrishikeshmishra-tl7le Жыл бұрын
How he is transfering all the plates (n-1) from source to helper without following the two conditions and vice versa ?
@atulwadhwa192
@atulwadhwa192 2 жыл бұрын
At 10:19 For smaller input why can't we pop the top of the stack and then remaining n-1 ele par solve func lagaye and the hypothesis can be moving all n-1 from source to destination and then in the induction step we push the poped element at pole 3. Can someone clear what's wrong with this approach?
@ArvindYadav-gy7fj
@ArvindYadav-gy7fj 2 жыл бұрын
it cannot be done bcoz when u pop it means u are storing it in any of the one pillar(either helper and destination) and then it cannot be solved for remaining disc by only using one pillar bcoz in the pillar storing the top disc u can't put any other disc as it it is of the least size.
@sudhanshuraj8632
@sudhanshuraj8632 Жыл бұрын
might be this story is correct but I am known to the fact that there is only one temple for brahma dev in entire world, and these has many reasons that are there in hindu mythlogy, one is he was cursed to have just one temple, and that is in pushkar, but the explanation was fabulous sir, no one can make it much easier
@anirudhatole2557
@anirudhatole2557 3 жыл бұрын
you gained a sub my friend.
@himanshumalik6913
@himanshumalik6913 2 жыл бұрын
Exact same code in Java: import java.util.*; class Main { public static void main(String[] args) { Scanner scn = new Scanner(System.in); int n = scn.nextInt(); int s = 1, d = 2, h = 3; solve(n , s, d, h); } public static void solve(int n, int s, int d, int h){ if(n == 1){ System.out.println("Moving plate " + n + " from " + s + " to " + d); return; } solve(n - 1, s, h, d); System.out.println("Moving plate " + n + " from " + s + " to " + d); solve(n - 1, h, d, s); } }
@offensive-brat
@offensive-brat Жыл бұрын
man of culture
@rakhsanthrakhy1587
@rakhsanthrakhy1587 3 жыл бұрын
Looks like at the end of this problem Bhrammaji ka recursive stack memory complete hogi and new system(universe) banayega :) :)
@sajidmanzoor1184
@sajidmanzoor1184 4 жыл бұрын
Solve the following puzzle for Tower of Hanoi · If puzzle can be accomplished in 3 moves with two discs. Use this to work out how many moves would be needed with three discs? · If puzzle can be completed in 15 moves with four discs. Use this to work out how many moves would be needed with five discs? · In general, describe a way of working out how many moves are needed when one extra disc is added? ye kese hoga
@mohan_792
@mohan_792 Жыл бұрын
2^n - 1; where n == number of discs
@bismeetsingh352
@bismeetsingh352 3 жыл бұрын
This one felt likee magic.
@sudhanvah3222
@sudhanvah3222 2 жыл бұрын
Aditya really apricate the good work, could you please improve the audio qualities of the videos.
@h6_wingers
@h6_wingers Жыл бұрын
Thank u sir
@arpanbanejee5143
@arpanbanejee5143 3 жыл бұрын
sir, induction step main ap cout kar rahe hian moving plate n from A to C. jabki humein pata hain ki ek hi plate bacha hua hain. yeh n plate ka funda samajh nhi aya, pata hain n likh rahe hain tab hi 1, 2, 3 karke print hoga, but apke tarika se wo kaise malum kare ki n likhna hain waha. Baki sab cystral clear hain bas ek yehi hain
@subratasatapathy3822
@subratasatapathy3822 2 жыл бұрын
Can't we pop the source stack and push to helper stack(it will be reversed).Then pop the helper stack and push to destination(reversed->reversed: original)?
@mohan_792
@mohan_792 Жыл бұрын
We can't keep larger discs on smaller discs... If we reverse them, this rule will be violated. So, ....
@paritoshdadhich2954
@paritoshdadhich2954 3 жыл бұрын
bhramaji bole placement aa raha hai coding karo... bhramaji jaisa bole vaisa hai karne ka :) great content... ab kabhi nahi bhuluga iska solution hahahah
Print Subsets | Print PowerSets | Print all Subsequences
15:48
Aditya Verma
Рет қаралды 186 М.
Towers of Hanoi: A Complete Recursive Visualization
21:13
Reducible
Рет қаралды 453 М.
Я обещал подарить ему самокат!
01:00
Vlad Samokatchik
Рет қаралды 9 МЛН
Can A Seed Grow In Your Nose? 🤔
00:33
Zack D. Films
Рет қаралды 30 МЛН
Kth Symbol in Grammar
23:32
Aditya Verma
Рет қаралды 119 М.
Fun Python Project. Recursion and the Towers of Hanoi
22:29
Python Programmer
Рет қаралды 31 М.
Solving Tower Of Hanoi Problem With Recursion
10:25
Coding Ninjas
Рет қаралды 68 М.
7 Time Complexity of a Recursive Tree
25:43
Aditya Verma
Рет қаралды 10 М.
BREAKING Chess Drama As Niemann Rips Into Magnus Carlsen
8:25
Epic Chess
Рет қаралды 53 М.
Towers of hanoi problem
29:27
Sudhakar Atchala
Рет қаралды 20 М.
Tracing of Recursive Calls in Tower of Hanoi
14:12
CodingByMahajans
Рет қаралды 27 М.