Tower of Hanoi solved using Recursion | Recursion Euler Tree in JAVA
HTML-код
- Опубликовано: 19 окт 2024
- Please consume this content on nados.pepcoding.com for a richer experience. It is necessary to solve the questions while watching videos, nados.pepcoding.com enables that.
NADOS also enables doubt support, career opportunities and contests besides free of charge content for learning. In this video, we discuss the solution of the popular puzzle - Tower of Hanoi using recursion. With this code, we explain the Euler tree formed for the recursive logic and also the memory for this code. In this problem,
1. There are 3 towers. Tower 1 has n disks, where n is a positive number. Tower 2 and 3 are empty.
2. The disks are increasingly placed in terms of size such that the smallest disk is on top and largest disk is at bottom.
3. You are required to
3.1. Print the instructions to move the disks.
3.2. from tower 1 to tower 2 using tower 3
3.3. following the rules
3.3.1 move 1 disk at a time.
3.3.2 never place a smaller disk under a larger disk.
3.3.3 you can only move a disk at the top.
To understand this puzzle, click here: • Tower of Hanoi - Quest...
To attempt and submit this question, click here: www.pepcoding....
For a better experience and more exercises, VISIT: www.pepcoding....
#recursion #algorithms #towerofhanoi
#pepcoding #programming #freeonlinecourses
Have a look at our result: www.pepcoding....
Follow us on our FB page: / pepcoding
Follow us on Instagram: / pepcoding
Follow us on LinkedIn: / pepcoding-education
This man has himself struggled enough with ds algo
That's why he knows all the thoughts every struggler goes through
Hatts off guru 👍
❤ such a jem, wish to hug you
at least someone who interested in clearing the concept rather than just coding
"Believe in your faith to meet your expectation" - Story of Recursion ;)
Nope- believe in sir's faith to meet your expectations.
@@yajurvedgupta9195 i meant in a general way boy
Sir You are really awesome...Literally the effort you are making to teach everyone is too Good...baar baar diagram bnakr samjhana..Jaise hi lgta hai ki is point me thoda doubt ho gya aage hi aap diagram bnake samjha dete ho..really very nice..God bless you..Aise hi help krte rhe life bn jaaye logo ki..Thank You soooooo much once again Sir!!
Thanks man. I request you to write us a LinkedIn or a fb post. Baaki bacho ka bhi bhla hoga
jitni tarif karo sir ki utni kam hai
god gifted ho sir aap with this teaching skills
Now I believe in faith, sir. Thank you
You're welcome
@@Pepcoding I just have one question, if you have time then please try to answer it :
What logic/condition of our function is making it sure that no matter what, a bigger disk will never be placed on on smaller one ?
I know the function is totally right and I even dry run it, so the working is also clear to me. But even after knowing that I can comprehend who exactly is it in the code that takes care of not putting bigger disk on the smaller one. IF ANYBODY KNOWS THIS, PLZ ANSWER IT.
@@AryanSharma-dh4fb We are only moving (n-1) which is always less than n...I guess this is the part that takes care of the rule that you are talking of.
In our faith, we obeyed all the 3 rules ... and while using our faith, we obeyed all the 3 rules ...
@@AryanSharma-dh4fbour faith
pure youtube mai kisi ne itni acchi tarah ni samjaya hoga jitna aapne samjaya sir❤❤❤❤❤
itni videos me mujhe 1 doubt bhi nhi aya...........itna crystal clear mujhe ajtak smjh nhi aya...
🙌
One of the best explanation for Tower of Hanoi Problem. My concepts of recursion really got improved from your videos.
I am glad you liked it. I also hope that you are watching till end and trying to understand the what, how and especially why of the problem.
If you like my efforts, I request a review
g.page/Pepcoding/review?rc
I just have one question, if you have time then please try to answer it :
What logic/condition of our function is making it sure that no matter what, a bigger disk will never be placed on on smaller one ?
I know the function is totally right and I even dry run it, so the working is also clear to me. But even after knowing that I can comprehend who exactly is it in the code that takes care of not putting bigger disk on the smaller one. IF ANYBODY KNOWS THIS, PLZ ANSWER IT.
@@AryanSharma-dh4fb same help me too
Tower of hanoi k saath aisa chamatkar maine pahle kabhi nai dekha.... simplest and best explanation I have ever seen.
bhai sahab yeah vo teacher hai jiske liya dil sa awaj nikelti hai hi ki video like kiya bina nahi jaana . what a mind blowing teacher yaar
it took me full day to understand tower of hanoi question , but this man explain it so nicely and gradually that is just amazing just amazing
Literally mere pass words nhi hai itna clear explanation RUclips par kya kahi par bhi nhi milega so much love sir ❤❤❤❤
After sifting through countless RUclips videos on recursion and investing hours of my time, I finally stumbled upon this gem. Even though I had a grasp of the basics - like printing numbers from 1 to n or n to 1, calculating sums, factorials, fibonacci, etc. - using recursion, I still chose to start from scratch with this playlist. I managed to tackle the zigzag pattern on my own from the previous video, which in turn prepared me to grasp the Tower of Hanoi problem in this video, a concept that had previously seemed quite alien to me.
But after watching this particular lecture, I'm certain that this logic and approach to problem solving will stick with me forever. Thank you very much sir, for your invaluable guidance.
Best teacher ever , an ultimate legend , Hats off to Sumeet Sir !
dil khush hogya bhai dekh kar, baki ke channel ne kisi ne itne depth m nahi btaya tha, ab apki videos hi follow krne wala hun ds ke liye
Great teacher, amazing explanation. Everyone needs an excellent teachers like you sir !
Sir you are true gem itna padha tower of hanoi even code rat liya tha pr aapki video se conceptually samaj AAya sirf ek video dekhne aaya tha aab Puri playlist khatam krke jaaenge thank you very much sir
Thankyou beta!
I am glad you liked it. I hope that you are watching till the end and trying to understand what, how, and especially why of the problem.
If you like our efforts, will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )
watched till 8:16 , and solved the question.
I knew recursion already, but sir you cleared the concept like no one else.🙏🙌
thank you so much sir.
literally i did a course in an local institution in delhi and they taught the same way he is teaching , even better. I gave around 13k there and he is teaching free of cost. Thank You Sir for sharing knowledge and putting this much efforts.
The way you discuss the problems with the required thought process is really great! Learning a lot from you...Thanks a ton!
humare expectation hai ki hume recursion sikhna hai
hume faith hai ki humne recursion sikh liya
expectation and faith me link - after watching pepcoding videos
thank you sirr!!! literally over the whole youtube, ONLY YOU made me understand it so deeply. I'll never forget it in my lifetime.
Sir I can't really thank you enough for making dsa easy for me. Your explanation made this so easy.
Thankyou beta!
If you like our efforts, we request a review-g.page/Pepcoding/review?rc
sir sach me maja aa gya esa vidio pure youtube me nhi milega , ek dum basics se samjhaya he sir apne . sach me ajj mera pura concept clear ho gya
Sir you are a blessing for people like me who are from a non CS background with no formal education but looking to break into the industry. Thank you for such a wonderful explanation. Pata hi nai chala kaise time paar ho gya puri video dekhte hue. Thanks a lot !!
Watching your video is more of fun , The way you clear the concept, the way you teach. No one in the entire planet can do this. Respect 🙏🙏. Thank you very much
wow, this cheers me up. I am glad we at pepcoding could be of help to you. Keep learning. Also, recommend us to your juniors and peers, they may also benefit.
Your teachings are love..I cannot explain how much I adore you for taking the teachings in Java.Your the only teacher doing that and very soon its going to increase your followers.
Thanks a million
My crush proposed me after I explained this infront of the class. He blocked me when I chose honesty and referred him to pepcoding 😝
sir you are next level... sumeet sir ki bolne ki style se hi lagta hai ki he is so enthusiastic and sincere about making the students understand everything.
Thank you for appreciating.
The love and respect which I get from you people keep me highly motivated and the same I am able to forward It to you people through my videos.
So, keep motivating, keep learning and keep loving Pepcoding😊
I was so frustrated not getting the right explanation anywhere for this problem and many too but now i will say now i got the one on the internet feeling blessed 😅
I don't know if it is a magic or what but this man exactly knows where we as students watching this will be struggling and he already has created the way to resolve it. God bless you for the work you have been doing and bless us to have a teacher like you ! 😃
sumeet sir a legend, people create so much confusion in this question and sumeet sir clear this with no time
We students of this generation needs like you and its very rare in World
Thank you sir !! This problem has been my nightmare for years, I never even tried solving it and now you made it so easy to understand.
You're welcome!
Sir Sir Sir.....u are just great...
thankyou so much...
never thought that someone can make recursion that understandable....
Happy to help and If you like our efforts, please upvote the comments written by the students about Pepcoding here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )
This man has himself struggled enough with ds algo
That's why he knows all the thoughts every struggler goes through
wow, this cheers me up. I am glad we at pepcoding could be of help to you. Keep learning. Also, recommend us to your juniors and peers, they may also benefit. If you like our efforts, we request a review
g.page/Pepcoding/review?rc
You can subscribe to our channel here
ruclips.net/user/Pepcodingabout?view_as=subscriber
Now I am loving recursion, seems complex but is amazingly simple
I am glad you liked it. I also hope that you are watching till end and trying to understand the what, how and especially why of the problem.
If you like my efforts, I request a review
g.page/Pepcoding/review?rc
@@Pepcoding reviewed already :) Thank you for the free and organised content !
first mein thoda confusing laga then jo samajh mein aya last mein bhai waaahhh👏👏👏👏👏
I understood recursion and that the steps of expectation, faith and expectation + faith are important to solve. We keep faith and it actually works. I think there is some magic in this. Such an interesting concept, recursion. Thank you Sumeet sir, I like the way you teach. Also, I really like the fact that he addresses his students as "bachcho", even though most of his students/viewers are 17+ in age. 😅
Sir please don't quit teaching at any cost its humble request to you 🙏
Thank you so much bhai 😊
Sir isliye nhi kyuki bada bhai pada rha ho esi feel aati hai 😅
Lots of love 🥰
It's the best recursion playlist on youtube...!! Thanks!
Thank you so much sir. Yours DSA teaching technique is jst amazing.
You deserve to have millions of views and subscribers sir. Next level explanation.
DSA ka asli maza Aaj AA Gaya .... Sumeet sir is truly G.O.A.T ❤️🔥
Best explaination of Tower of Hanoi , Thank you so much sir
HUGE RESPECT🙏🙏🙏
The Combo pack of patience and knowledge 😎😎
#unbeatable
have faith on faith 😎
when every1 is busy in c++.
youre helping icse students brushing concepts using java.
LOGIC GURU hain aap
Keep learning, Keep growing and keep loving Pepcoding!😊
Sir you are GOD .!! i was so frustrated regarding this recursion thing . Now after watching your playlist everything's clear. Thank you so much sir
Now I believe in faith, sir. Thank you
Sala Pura Dimag hil jata he , Sumeet Sir ke padhane se , MAJA aa gyaa Guruji , Bahut hi Aasani se koi bhi problem solve krwate ho 😍😀😍
wow, this cheers me up. I am glad we at pepcoding could be of help to you. Keep learning. Also, recommend us to your juniors and peers, they may also benefit.
I watched others videos on recursion all are confusing and u how simply explain all the deep things thanks sir #GodOfRecursion
Never knew until now that tower of hanoi is this much easy. Thank you sir, you are amazing.
Happy to help!
Keep learning.
And for better experience and well organised content visit nados.pepcoding.com
@@Pepcoding awesome sir🔥
😭😭😭 kitna ache se smjhate ho sir thank you so much from bottom of my heart ❤❤
Pleasure is all mine, For better experience and well organised content sign up to nados.pepcoding.com
Just believe on Sumeet sir and all your concepts will get crystal clear😇
Sir bhot ache se samjh aya. Ese samajh aane lage to motivation aajata hai ki haan hum bhi kr skte hain💪
Glad to know that you liked the content and thank you for appreciating.
The love and respect which I get from you people keep me highly motivated and the same I am able to forward It to you people through my videos.
So, keep motivating, keep learning and keep loving Pepcoding😊
Recursion works like magic. Sumit Sir Rocks.
Thank you
Thank you very much sir . You teaches very well. This was the first question because of which I thought recursion is very very difficult sometimes and I can never be able to do this question. But after this video recursion has become cake walk for me. You explained it in very detail. Everyone explain this question very fast , and don't go in to deep.
You are amazing teacher . Thank you sir. Hats off to you sir 👍 .
Jeetu Bhaiya of coding, feel karwa dete ho sir aap ,,tysm
I am falling short on words ... just can't thank you enough sir !!
very nice explanation...been watching many videos but yours finally helped me thank you
Coudn't resist myself from adding a comment, you are doing an absolutely amazing job. 🙂
Hope you like the video.
For better experience and well organised content sign up on nados.io
Don't forget to follow us on Instagram instagram.com/pepcoding/
Jindgi Mai pehli baar tower of Hanoi samnj Aya h
Thankyou beta!
I am glad you liked it. I hope that you are watching till the end and trying to understand what, how, and especially why of the problem.
If you like our efforts, will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )
Best session on TOH I found today ! Thankyou :)
I have always heard that recursion works like magic.. But this is the first time I felt it too.. 😁
today i really understand recursion and started believe on faith
You are awesome sir, I am addicted to ur videos. Now problems really make sense. Thankyou!
Glad to hear that
aap saaaaaandaar ho sir , ye question maine kaha kaha nahi padha par kahi samaj me nahi aaya but here in just couple of minutes...
best video i have ever seen on recursion.Thanks a lot sir
Glad to know that you liked the content and thank you for appreciating.
The love and respect which I get from you people keep me highly motivated and the same I am able to forward It to you people through my videos.
So, keep motivating, keep learning and keep loving Pepcoding😊
You are such a wonderful teacher sir jaldi videos bnao bhout time hogya
Beta, Rajneesh bhaiya ko delegate kia hai, vo daal rh h ab video. Main dev ka course bnake dalunga
Sir before watching this video I never understood toh problem. But you made it so much easy!! Thanks a lot.
I am glad you found it helpful. I request you to drop us a review
g.page/Pepcoding/review?rc
thank u so much sir .DS pdna ab maza toh ab aaya hai
The Myth, The Man, The Legend Sumeet Sir.
8th Wonder of World ---> RECURSION
You are a blessing sir... may you reach heights of success.
Pleasure!! share among your peers
I just have one question, if you have time then please try to answer it :
What logic/condition of our function is making it sure that no matter what, a bigger disk will never be placed on on smaller one ?
I know the function is totally right and I even dry run it, so the working is also clear to me. But even after knowing that I can comprehend who exactly is it in the code that takes care of not putting bigger disk on the smaller one. IF ANYBODY KNOWS THIS, PLZ ANSWER IT.
sir aaap great ho sirr . pepcoding best hai.
You are a Messiah sir. I am very grateful to you. Thankyou !!! Loved the explanation.
If you like my efforts, I request a review
g.page/Pepcoding/review?rc
@@Pepcoding Sir I already did it. Any other site to review on? I will do that too :)
😭😭 it's too good I thought I am never gone understand it 👌👌👌❤️
Thank you sir i don't know Java still i am learning recursion and translating those code in to CPP thank you thank you thank you😃😃😃😃😃😃😃😃😃😃
someone give sir oscar for his dedication
Really means lot. For better experience and precisely arranged content visit on nados.io
litrally i have never seen this type of explanation on any platform
Glad to know that you liked the content and thank you for appreciating.
The love and respect which I get from you people keep me highly motivated and the same I am able to forward It to you people through my videos.
So, keep motivating, keep learning and keep loving Pepcoding😊
I think the language used in the question is a bit miss leading , as you have mentioned in the question " from A to B using C" . but you have directly print disc 3 to B . without using helper . The helper waali cheez is useful only when you have 2 or more disc .
what a explanation outstanding sir💞💞💞
This is the most beautiful problem I ever seen
best explanation of tower of hanoi in internet.
Thankyou beta!
I am glad you liked it. I hope that you are watching till the end and trying to understand what, how, and especially why of the problem.
If you like our efforts, will you like to write a few words about us here (www.quora.com/What-are-the-good-websites-to-learn-data-structures-and-algorithms )
Such a beautiful and precise explanation. Thank you very much sir. Loving your videos. Just a small request sir, please sir try to upload more videos daily.
Hanji beta. I am trying my best. Roj 10 to atleast bnana chahta hun.
He is the guy who swear I'll teach you coding... kis gola s aaya h guru..
Awesome, I am speechless sir, Believe in faith and then done.
Keep it up
If you like our efforts, we request a review
g.page/Pepcoding/review?rc
You can subscribe to our channel here
ruclips.net/user/Pepcodingabout?view_as=subscriber
For clearing your doubts, you can join our community on telegram
t.me/pepcoding
you're the best teacher on youtube... :)
Wow, thanks!
Everyone should feel bad for this guy ! He is working so hard and providing excellent content but only 5k views
If you like our efforts, we request a review
g.page/Pepcoding/review?rc
You can subscribe to our channel here
ruclips.net/user/Pepcodingabout?view_as=subscriber
For clearing your doubts, you can join our community on telegram
t.me/pepcoding
Disco........
sir your videos are actually helping thank you
Sir ap bohot acha sikhate ha Thanks sir.
Amazingly done... I am not gonna forget euler now
Haha..Thankyou beta!
I am glad you liked it. I hope that you are watching till the end and trying to understand what, how, and especially why of the problem.
Keep learning and keep loving Pepcoding😊
@@Pepcoding sir.. I am developing softwares for 10 years now for various software giants. I just love your videos, keep up the great job
But how do we get the intuition that these function will follow the rule that are stated in first place?
i don't get the tower concept, see you putting 1,2 in other tower to place third at bottom postion so,why you dont put 1,2,3 directly to another tower like you are putting 1 and 2 directly over the 3. i think if you put single value at a time ,by my understanding from 3,2,1. 1 goes first and then over it 2 goes like 1,2 not 2,1. i am too much confused plz help.ii
Sir this question troubled me alot but thanks to you as now I can do this question even while sleeping
Always welcome
This is some next level stuff. Glad to have found it
Watched on 15 October, 2021 - thanks for the video.
Hello Sir, Video is superb... I just have one doubt, could you please make a video on how we can use this code to -->> Move disks from Source -A to Destination C using B? I have tried multiple times but couldn't make it. Please make a video on this also.
I just have one question, if you have time then please try to answer it :
What logic/condition of our function is making it sure that no matter what, a bigger disk will never be placed on on smaller one ?
I know the function is totally right and I even dry run it, so the working is also clear to me. But even after knowing that I can comprehend who exactly is it in the code that takes care of not putting bigger disk on the smaller one. IF ANYBODY KNOWS THIS, PLZ ANSWER IT.
that we overselves just move the top disk (smallest) to destination and rest using faith (which follows all rules including this one)
@@Pepcoding thank you sir very much for clearing my doubt.
Hi Sir great explanation by you very simple and clear .
Sir i have 3 years of experience and looking forward for product based companies can you please guide me on which areas of DS and Algo should i focus more or how much i study to clear interview of poduct based companies like microsoft , amazon etc.
one doubt sir.... At in( system.out.println) line how the disc at A move to disc B just by only printing ???
i love the recurion three which you made........mtlb itna kon ghus ghus kr btata hai yr.......
Thanks:) For more content like this with a better user experience please visit nados.pepcoding.com