Table of Contents: The Problem Introduction 0:00 - 0:33 Cases That Are Height Balanced 0:33 - 1:56 Cases That Are NOT Height Balanced 1:56 - 2:58 Approach #1: Get Heights of Subtrees At Each Node 2:58 - 3:46 Approach #2: Recurse To Base Cases 3:46 - 4:23 Walkthrough of The Recursion 4:23 - 12:39 Time Complexity 12:39 - 13:25 Space Complexity 13:25 - 13:39 Wrap Up 13:39 - 13:57 The teacher's notes contain a link to the code for the problem discussed in the video. It is fully commented for teaching purposes strictly.
@dolcyrao57634 жыл бұрын
You're really amazing, I was enjoying your teaching. Thanks a lot for this high-quality teaching for free.
@BackToBackSWE4 жыл бұрын
great to hear!!!
@anthonysummit30983 жыл бұрын
Where is the code?
@sivaprakashkkumar96913 жыл бұрын
Where is code
@debanjanasantra67243 жыл бұрын
Could not find the link to the code :(
@BismaSuleman4 жыл бұрын
Me on Tinder: Hey, what is your height? And are you balanced?
@BackToBackSWE4 жыл бұрын
ye
@ExplorerSpace3 жыл бұрын
@@BackToBackSWE i am average height
@johnpaul43013 жыл бұрын
Balanced here might mean whether your tootsiroll matches your height
Sharing this channel to all my friends who are interested to learn data structure algorithm .. Please make more videos on Data Structure and algorithms .. Believe me nobody tech like you. This channel has potential to become one of the best. The difference between you and others, is that most people just jumps directly into the solution but you tell us 'the thought process', 'how to interpret the problem' which are most important. Your think loud approach is best part. Please don't stop making such video. People like me are always with you.
@BackToBackSWE5 жыл бұрын
Haha thanks
@baraaabuasal56265 ай бұрын
yes!!
@rban1235 жыл бұрын
Better than my data structures professor, thank you
@BackToBackSWE5 жыл бұрын
thx
@josephwong28324 жыл бұрын
asking the "critical question" and then returning the answer to that question to my parent is a great way to reason about recursion in general your teaching style sir is on another level!!!
@BackToBackSWE4 жыл бұрын
thanks!
@nikhilkumarmishra12255 жыл бұрын
OMG the way you explain the idea behind why the algorithm works, it just blew me away. Thanks a lot mate!
@BackToBackSWE5 жыл бұрын
wassup
@turnuptheMIKEG4 жыл бұрын
you're a remarkable teacher. blew my PhD data structures professor out of the water, honestly. thank you for making these videos. I'm surviving interview season bc of this.
@BackToBackSWE4 жыл бұрын
lol nice, sure sure, they are a relic of the past self. I don't even remember recording some of these. Nice nice, you'll make it yo
@psthakur11994 жыл бұрын
Loved that idea of "asking a question".Thanks man!!
@BackToBackSWE4 жыл бұрын
ye
@rakhman8621 Жыл бұрын
The way you explain everything man…the number of times you revisit some moments is perfect, the speed with which you explain the material is perfect. Keep up the good work and thank you for teaching us such important topics in such a great way.
@adityajain-fn6ne4 жыл бұрын
You deserve way way more recognition and credit for the work you have done sir! better than any college professor I have had.
@BackToBackSWE4 жыл бұрын
thanks and thx
@rahoolification4 жыл бұрын
What you are doing is nothing short of humanitarian work my friend!
@BackToBackSWE4 жыл бұрын
ye
@priyogopalsingha34872 жыл бұрын
undoubtedly, the best explanation of how recursion works in trees
@adenosinetp104 жыл бұрын
why this has so less views??! No one these days teaches like this guy...not even my professor does....this video helped me creating a foundation for my data structure course
@BackToBackSWE4 жыл бұрын
ye
@PherricOxide5 жыл бұрын
Thanks for the videos! They're very well done compared to most of the others where people either start writing code immediately or jump straight to the solution without explaining how they got there.
@BackToBackSWE5 жыл бұрын
Sure, this channel still has a long way to go
@ruthylevi98042 жыл бұрын
you are so gifted at teaching, never stop!
@MuhammadIrshadAli4 жыл бұрын
Man, you should train CS professors at universities on how to teach algorithms
@BackToBackSWE4 жыл бұрын
nah
@afsinyilmaz86653 жыл бұрын
great way of explaining stuff...Keep up the good work...you folks are as valuable as nation's best teachers.
@kunpeng86464 жыл бұрын
What a smart and attractive illustration, well-done man!
@BackToBackSWE4 жыл бұрын
thanks
@Don_ron6665 жыл бұрын
Finally a clear cut video good job!
@BackToBackSWE5 жыл бұрын
thanks
@deepamkumar52114 жыл бұрын
Your explanation is the best i have ever seen and really helps to understand these difficult problems. I appreciate your selfless work and the dedication with which you teach us these topics..Got to learn a lo from you,keep uploading more videos and soon this channel would turn out to be the best resource for interview preparation.
@BackToBackSWE4 жыл бұрын
thx
@johnmcway61204 жыл бұрын
Thank you very much. I myself teach myself to code, I'm also a teacher in kindergarten. I recognize a lot of myself in you. Keep up the good work!
@BackToBackSWE4 жыл бұрын
Nice! thanks!
@hugenerretho91512 жыл бұрын
ur explanation is so concise that my golden retriever can now display his treats in tree structure
@BackToBackSWE2 жыл бұрын
Thank you, glad you liked it 😀 Do check out backtobackswe.com/platform/content and please recommend us to your family and friends 😀
@realmarciomarinho3 жыл бұрын
You said the code was below, but I cannot find it.
@wowzande5 жыл бұрын
That's gangsta as fuck we need more of this
@BackToBackSWE5 жыл бұрын
haha
@HemanthaKumarYadav4 жыл бұрын
I am so glad that I found your channel on KZbin...! Thank You very Much Sir!
@BackToBackSWE4 жыл бұрын
welcome
@ahiduzzamanahir13383 жыл бұрын
WHAT! Did you just teach me recursion? I thought it was impossible!
@kevinandres33065 жыл бұрын
EXCELLENT explanation. extremely clear
@BackToBackSWE5 жыл бұрын
thanks, I like you
@wellingtonzane42885 жыл бұрын
Really detailed and clear explanation! Thank you!!!
@BackToBackSWE5 жыл бұрын
sure
@doruwyl5 жыл бұрын
Very cool approach with the nodes which are "bellow sea level". 😊
@BackToBackSWE5 жыл бұрын
hahaha
@リンゴ酢-b8g2 жыл бұрын
A balanced binary tree, also referred to as a height-balanced binary tree, is defined as a binary tree in which the height of the left and right subtree of any node differ by no more than 1.
@maripaz56504 жыл бұрын
Best interview prep ever :)
@BackToBackSWE4 жыл бұрын
thanks
@SOURAVKUMAR-tw3ds3 жыл бұрын
awesome work bro!! helped a lot in visualization of recursion calls
@missrockinout5 жыл бұрын
you get so into explaining this, gotta love the head scratch lmao thanks for an awesome explanation :D
@BackToBackSWE5 жыл бұрын
lol wut
@quirkyquester4 жыл бұрын
Thank you man! This video really helps me to understand the process of solving the problem.
@BackToBackSWE4 жыл бұрын
sure
@nandanimadhukar4 жыл бұрын
Awesome explanation! Trees are speaking for themselves :D
@BackToBackSWE4 жыл бұрын
ye
@ggzz88453 жыл бұрын
where is the code ?
@TheAntloo4 жыл бұрын
Awesome walkthrough! Gave me a nice intuition on how I would write the code. Do you think you could make a video on how to insert a node into a BBST?
@BackToBackSWE4 жыл бұрын
Nice. and maybe.
@ramizrizwan3057 Жыл бұрын
Such a good explanation, you’re the best!
@BackToBackSWE Жыл бұрын
Happy Holidays! Really glad to help 🎉 Do you know about the BacktoBackSWE 5 Day Free Mini Course? Check it out here - backtobackswe.com/
@aatifnazar17665 жыл бұрын
The node which is marked red cross will not return 2. It breaks the call there only.
@BackToBackSWE5 жыл бұрын
ok
@TacklessNebula33 жыл бұрын
Made your 2K to 2.1K... Thanks for the brief explanation!
@max500k3 жыл бұрын
Great job! You explained this well
@saikatdutta19915 жыл бұрын
Hey bro, I want you to explain "Median in a stream of integers (running integers)" this problem. I am unable to understand why we need to use self balanced binary tree to solve this problem. Thanks. I will be helpful.. You explain better than any other.
@BackToBackSWE5 жыл бұрын
I'll be covering that in my class but not on the channel, most of my technical videos will go there now. I'm going to convert the channel into a more "I'm building things" type thing soon
@sankethb.k6425 жыл бұрын
Thank you very much sir, your channel will soon be on the top.
@BackToBackSWE5 жыл бұрын
thanks
@malaguna664 жыл бұрын
This explanation is so clear so good!
@BackToBackSWE4 жыл бұрын
glad it helped
@hinocenciopaulo9 ай бұрын
Thank you so much for this beautiful explanation 🙏
@neghatnazir16684 жыл бұрын
awesome explination , i love the way you explain things.
@BackToBackSWE4 жыл бұрын
thx
@baraaabuasal56265 ай бұрын
at 6:00 I was like, say no more => Subscribed. fkn love the way explain stuff man
@ShortGiant15 жыл бұрын
Great video, thanks. Appreciate the table of contents.
@BackToBackSWE5 жыл бұрын
May you flourish
@rhiannonsmeby95663 жыл бұрын
This video was fireeee I hate recursion but this visualization and explanation really helped
@amitmishra27364 жыл бұрын
Dude! I am not seeing the code in the down :( could you please update the Link
@BackToBackSWE4 жыл бұрын
The repository is deprecated - we only maintain backtobackswe.com now.
@intoeleven4 жыл бұрын
the time complexity is wrong, it should be O(n*log n), n is for getting height for each node and you need to check every node for balanced is log n. The worst case could be O(n^2) in this top-down solution, actually.
@BackToBackSWE4 жыл бұрын
If the tree is skewed height checking is O(n)
@intoeleven4 жыл бұрын
@@BackToBackSWE Yes, and you not only check the height, but also check the balanced, which will cost O(log n). The total time complexity should be O(n log n) leetcode.com/problems/balanced-binary-tree/solution/
@fantasy99602 жыл бұрын
wow, your teaching is amazing! thanks again!
@wappa69144 жыл бұрын
Thank you from France !
@BackToBackSWE4 жыл бұрын
sure! 🇫🇷
@MoscleBrog10 ай бұрын
people like u save students like us😃
@randalllionelkharkrang40473 жыл бұрын
if it has to fail, it will always fail at the root node right? can you provide with a counterexample to what I said?
@abbasjradi50012 жыл бұрын
Exactly, it doesnt wkrk
@yuyu-qr7ih5 жыл бұрын
very detailed explaination brada love u
@BackToBackSWE5 жыл бұрын
sure homie
@neotong98855 жыл бұрын
really nice job on explaining Balanced Binary Tree!
@BackToBackSWE5 жыл бұрын
thanks
@pushkalkatara21535 жыл бұрын
Hey, really a great explanation man! It'd be awesome if you could whiteboard the pseudocode too after the explanation.
@BackToBackSWE5 жыл бұрын
yeah good idea
@syedmdharris88143 жыл бұрын
we can simply check whether each node has left and right node? can you explain about that
@wahtthepho3 жыл бұрын
excellent explanation!! thank you!
@mohannadbayoumi96864 жыл бұрын
May I ask what the complexity of the non-efficient way you mentioned in the beginning of the video is?
@BackToBackSWE4 жыл бұрын
Quadratic O(n^2)
@超级小棕熊05 жыл бұрын
thank you much ,I totally uderstand how recursion work
@BackToBackSWE5 жыл бұрын
nice
@abhishekk.39774 жыл бұрын
Ok, I accept that I agreed to max(0,0) = 1. @ 8:40
@BackToBackSWE4 жыл бұрын
ok
@ashwanigupta46723 жыл бұрын
Finally got an awesome explanation 🏆
@Kellworkie3 ай бұрын
Amazing teaching!
@hikemalliday6007 Жыл бұрын
this dude kills it
@qingruxia63123 жыл бұрын
I love u your videos so much! Thank you so much for your time and work!
@researchandbuild17514 жыл бұрын
Could you just do a breadth search and if the count of children at a level count is odd, it is not balanced?
@BackToBackSWE4 жыл бұрын
How would this work exactly?
@researchandbuild17514 жыл бұрын
@@BackToBackSWE well it seemed like possibly a feature of an unbalanced binary tree is it would have a level with non-even count of nodes. Unless i am misunderstanding what a balanced tree should look like (which is possible). So you just make a queue and walk down the nodes, pushing children at each. If your total count of children in the queue is ever odd at each step then you know the tree is unbalanced. Not sure if that would work or not though, just pondering
@MahmoudSayed-hg8rb2 жыл бұрын
I'm kinda late idk if you'll respond to this comment first of all thanks for your efforts. second thing ... as far as I know ( and i almost know nothing yet, I'm just a beginner), something doesn't add up in the last example Dont we consider a tree a Balanced tree if the absolute difference of the heights of each side is
@khan.mansoor3 жыл бұрын
Great explanation! Do you have a link to the code for this problem that I can refer to?
@eliasmoreno46724 жыл бұрын
you explained this so well. wow. *subscribed :)
@BackToBackSWE4 жыл бұрын
thanks!
@pawanacharya9974 жыл бұрын
How can someone explain this clearly wow you really helped me.. thanks
@BackToBackSWE4 жыл бұрын
nice
@shruthiranganatha73334 жыл бұрын
Why add 1 to max(heightOfRightNode, heightOfLeftNode) ?, Wha's the logic here??
@BackToBackSWE4 жыл бұрын
Including the node that the call is working on in the height as the calls go up
@techzoo14 жыл бұрын
Your explanation is somehow kinda funny (in a good way)!
@BackToBackSWE4 жыл бұрын
yeah I was weird when the channel started. no one was watching
@stargazer87182 жыл бұрын
What's the difference between this and an AVL tree?
@ashishbisht9804 жыл бұрын
Bro you are awesome , love from India
@BackToBackSWE4 жыл бұрын
much love
@pewdiepieschair26933 жыл бұрын
thanks lad, much appreciated!
@SreyesSrinivasan3 жыл бұрын
Great explanation, thanks a lot :)
@mpalanipsbb10 ай бұрын
Best explanation!
@AllNaturale11 Жыл бұрын
very helpful. thank you!
@BackToBackSWE Жыл бұрын
Thank you! Please enjoy a special code from us - backtobackswe.com/checkout?plan=lifetime-legacy&discount_code=AllNaturale11 🎉
@RedRabbitII3 жыл бұрын
love this! thank you
@jgraiver4 жыл бұрын
have you done the code for this anywhere?! loved the video
@BackToBackSWE4 жыл бұрын
I think so here: github.com/bephrem1/backtobackswe
@shijames41295 жыл бұрын
nice video!!! thanks!!
@BackToBackSWE5 жыл бұрын
sure
@ifelsedeveloper4 жыл бұрын
hey! love your videos! one question, can't i just check the absolute height difference from each node? without asking are you balanced to each node?
@BackToBackSWE4 жыл бұрын
Yes but that will duplicate subtree measurements
@ashwinvarma93494 жыл бұрын
Dude please include in your videos bro that would be of great help!
@aatifnazar17665 жыл бұрын
A big thank you for this content
@BackToBackSWE5 жыл бұрын
thanks for being here
@sameerpatel34763 жыл бұрын
Would a tree be considered balanced tree if the root have only one node at one side ?
@cocoarecords5 жыл бұрын
My goto channel for any problem
@BackToBackSWE5 жыл бұрын
hey
@shashankshekhar3904 жыл бұрын
That helped, thanks.
@BackToBackSWE4 жыл бұрын
sure
@PankajKP5 жыл бұрын
i hav to pause the video and say GOD to you.... You are GOD!!!!! 😇😇
@BackToBackSWE5 жыл бұрын
i try, i try
@nishanth9984 жыл бұрын
where can i find the code in the website??plz tell me
@BackToBackSWE4 жыл бұрын
The repository is deprecated - we only maintain backtobackswe.com now.
@darshantsdarshan14 жыл бұрын
This guy is awesome 👏
@BackToBackSWE4 жыл бұрын
I'm ok.
@XLpacman8052 жыл бұрын
Thanks
@zackyang1234 жыл бұрын
That 8:40 zoom is gold hahahaha
@BackToBackSWE4 жыл бұрын
what did I do
@maidul135 жыл бұрын
I just don't get why its max(-1,-1)+1, is that supposed to be equivalent to taking absolute value? if so can you explain please
@BackToBackSWE5 жыл бұрын
I am just simulating the code as it would execute the base case.
@poojaguru25165 жыл бұрын
Lifesaver : ) Thank you so much!! Best explanation ever!!
@BackToBackSWE5 жыл бұрын
sure
@lucy2003-d8p Жыл бұрын
great work brother
@wentingzhang30974 жыл бұрын
I'm having trouble finding the code in the description! :(
@BackToBackSWE4 жыл бұрын
The repository is deprecated - we only maintain backtobackswe.com now.
@salwaabdullah20035 жыл бұрын
Thanks 🙏
@BackToBackSWE5 жыл бұрын
sure
@kimmyliu55092 жыл бұрын
May I ask where is the code? you mentioned it is in description but it is not...