Finding the Maximum Depth of a Binary Tree (Recursion)

  Рет қаралды 43,704

Stephen O'Neill

Stephen O'Neill

Күн бұрын

Пікірлер: 71
@Sunshine-mj2pf
@Sunshine-mj2pf 4 жыл бұрын
This is the first video I watched that explains the timeline of recursion, which is extremely helpful for people like me who is always confused by recursion process. Thanks a lot.
@jacob.lee380
@jacob.lee380 2 жыл бұрын
I've been watching more than 10 videos to understand how binary tree traversal and recursion work. This is the first video I truly understand both concepts! Thanks!
@wperlich
@wperlich 7 жыл бұрын
Thanks for the explanation. I am practicing for interviews and these recursive solutions have a lot more depth than what meets the eye. I think it's important to run through the tree like this to have an understanding of what is going on at least on a conceptual level. It's all too tempting to just memorize the simple code. Keep up the good work.
@abhishekchaudhary3909
@abhishekchaudhary3909 6 жыл бұрын
Cool video
@dark13angelxxx
@dark13angelxxx 4 жыл бұрын
Did you get a job?
@trinityimma
@trinityimma 5 жыл бұрын
You just cleared my confusion on how it would work recursively. Thanks for the tips.
@parthyadav3177
@parthyadav3177 4 жыл бұрын
i didnt understand could you explain pleasse
@kofi7617
@kofi7617 4 жыл бұрын
exactly what I was looking for ... thank you ONeill
@lukelyu3264
@lukelyu3264 3 жыл бұрын
The beeeeest recursion explanation ever!
@ankishbansal420
@ankishbansal420 5 жыл бұрын
I was struggling with recursion in tree and graph, your clear cut explanation made it very easy. Thanks:)
@go_cool_travels
@go_cool_travels 4 жыл бұрын
Same here bro do you overcome that now??
@Gman-kx9dr
@Gman-kx9dr 2 жыл бұрын
the cleanest explanation I can find on youtube...especially about the recursion which trips me up all the time... a bunch thanks man ...
@JamesHalpert8555
@JamesHalpert8555 4 жыл бұрын
Probably the best explanation of the recursive calls!! Thank You!!!
@pranjalpimpale8465
@pranjalpimpale8465 4 жыл бұрын
Thank you so much sir....Only video I found on youtube with explanation of recursion
@aimeewildstone4602
@aimeewildstone4602 3 жыл бұрын
Thank you so much - I finally understand how recursion works in a binary tree!
@navarroaccount2085
@navarroaccount2085 5 жыл бұрын
If the height of the root is 4, then he height of node 2 is 3, the height of node 5 is 2 and the height of node 6 is 1. It doesn't add up. The same happens with the height.
@hanxu2143
@hanxu2143 4 жыл бұрын
Thank you so much for explaining it in a visual way. I could not find a better video that explains how recursive navigation of a tree works. Keep up with the illustrations! Subscribed.
@jaepark1593
@jaepark1593 5 жыл бұрын
Awesome explanation. Most videos don't cover each step of the recursion.
@xavicfc1504
@xavicfc1504 4 жыл бұрын
Thank you for the video, it is people like you, why we can understand difficult concepts, Thank you!
@sourabh3584
@sourabh3584 4 жыл бұрын
Thankyou very much for this walkthrough I needed this
@wtfchazpwnt
@wtfchazpwnt 4 жыл бұрын
The visual explanation helped so much. Thanks!
@KeenalShah
@KeenalShah 4 жыл бұрын
Thank you!! This is exactly what I was looking for. I was getting a bit mixed up with how the recursion code was working, your explanation cleared it!
@sourabh3584
@sourabh3584 4 жыл бұрын
are u doing leetcode or gfg?
@KeenalShah
@KeenalShah 4 жыл бұрын
@@sourabh3584 yup, leetcode!
@sourabh3584
@sourabh3584 4 жыл бұрын
@@KeenalShah would you like to do it with me, I'm doing interview prep!! you can find me on linked in
@KeenalShah
@KeenalShah 4 жыл бұрын
@@sourabh3584 sure!
@abhishek.eswarappa
@abhishek.eswarappa 3 жыл бұрын
@@sourabh3584 That was smooth Lol xD
@bennet5467
@bennet5467 2 жыл бұрын
Excellent explanation. Thanks sir!
@eyalpery8470
@eyalpery8470 3 жыл бұрын
Thanks! It's really important to UNDERSTAND recursion and not try to memorize the small code snippets.
@theboy466
@theboy466 5 жыл бұрын
Thanks man. This is top level best explanation
@alexei1750
@alexei1750 5 жыл бұрын
Awesome video for computer science lovers!!
@krishnansnair4386
@krishnansnair4386 6 жыл бұрын
shouldnt the depth be 3 because there is only 3 edges from root to the deepest leaf?
@johnnyweng1164
@johnnyweng1164 6 жыл бұрын
I think so. It is easier to get the depth by just using the definition of the tree depth than by doing the code analysis. The tricky part in code is adding one to the maximum of right and left. This one does not represent the node itself, but it means the edge between the node and its upper node.
@acxd
@acxd 4 жыл бұрын
Can you please explain various tree traversal methods using recursion.
@Richard-yz2gy
@Richard-yz2gy Жыл бұрын
Hi Stephen, if "3.left" is None=0 from the right side of the tree then how can you put left= 3 in the final return statement surely it should be 0 because the last value for the varaible for "left" is 0 not 3 surely?
@AyushGupta-kp9xf
@AyushGupta-kp9xf 4 жыл бұрын
thanks a lot for this explanation it was really much needed!
@joseluislopez788
@joseluislopez788 4 жыл бұрын
Thanks a lot, your explanation was amazing.
@chandlerlxw
@chandlerlxw 4 жыл бұрын
Thank you for the detailed explanation, really helpful for me! Subscribed
@ynidhypatia
@ynidhypatia 3 жыл бұрын
Woahh, this is the only video I've seen that starts the counting with one, the others started at zero
@steven3461
@steven3461 15 күн бұрын
I thought you counted edges for depth and height, not the nodes?
@rashmi_gaur
@rashmi_gaur 4 жыл бұрын
Great explanation!!👍
@didoma73
@didoma73 4 жыл бұрын
this is excellent, thank you!
@tahakhan3963
@tahakhan3963 Жыл бұрын
thanks a lot for the explanation
@rubenlech7256
@rubenlech7256 4 жыл бұрын
Very good explanation...
@rathan235
@rathan235 Жыл бұрын
Great job
@darshmahra5048
@darshmahra5048 3 жыл бұрын
so this would be considered an inorder traversal right?
@abajoaladerecha
@abajoaladerecha 3 жыл бұрын
What if the top of the tree have more than one treeNode?
@prakharagrawal8547
@prakharagrawal8547 4 жыл бұрын
nice explanation
@kingdavey87
@kingdavey87 4 жыл бұрын
Wow dude awesome video
@dweebosupremo5904
@dweebosupremo5904 3 жыл бұрын
good explanation
@siriuz9279
@siriuz9279 Жыл бұрын
well explained
@sushantkshirsagar
@sushantkshirsagar 7 жыл бұрын
Amazing explanation. Thanks a lot
@abhinavreddy5350
@abhinavreddy5350 4 жыл бұрын
Nice explaination bro Do more videos........:)
@Santi-iz1uo
@Santi-iz1uo 4 жыл бұрын
Shouldn't the height be 3? You count the edges not the nodes no?
@yangyu2950
@yangyu2950 6 жыл бұрын
wow this is great, thanks so much. awesome explanation too!
@ashleygautama4551
@ashleygautama4551 7 жыл бұрын
Thanks for explaining this so clearly. It's nice seeing what is going on behind the scenes. I have a question though: say I only have 1 node in my tree. If I use the recursion code you provided to calculate the depth I get a depth of 1. Shouldn't that be 0 because this node has no children? Or is my concept of depth wrong? Also as a novice I would not know how to solve this problem. Will I ever learn to produce these kind of solutions on my own or am I stuck copying code :( ? This seems quite difficult to come up with yourself and at the moment i'm stuck coping code from others with regard to binary trees.....
@ONeillCode
@ONeillCode 7 жыл бұрын
Hey Ashley, great question! This will come down to the way you perceive solving the max depth and if you are asked to solve this problem you should as the following: Do you want me to calculate using the number of nodes from the root or number of edges from the root? Searching the internet you will see if shown both ways. In my example we calculated using nodes. When using the number of nodes we return 0 when we find a null root ( if(root == null) return 0; ). If you were to calculate using the number of edges (Max Height / Max Depth would be 3 instead of 4) you would return -1 when you find a null root ( if(root==null) return -1; ). This will return 0 just as you asked above. It comes down to how you perceive finding the max. And as for if you will ever learn, of course you will! After getting more experience programming, you will pick up on data structures and algorithms useful for solving certain types of problems. It just takes practice. Don't worry!
@ashleygautama4551
@ashleygautama4551 7 жыл бұрын
Thank you again for clearing that up, too and also for your encouraging words. I know how recursion works, but as seen in your video it sometimes is difficult to keep track at what it is it's doing and how you can solve certain problems with it. Keep up the good work!
@callmewave_
@callmewave_ 6 жыл бұрын
The depth would be 1 because there is a level. You're thinking index. Look at the solution - if your depth with a single node would be zero, then the solution provided above should be 3.
@jasmine9538
@jasmine9538 3 жыл бұрын
Bravo!
@rasikadandawate4721
@rasikadandawate4721 4 жыл бұрын
Thanks a lot!!
@lappham6915
@lappham6915 2 жыл бұрын
Clear!!
@maabul01
@maabul01 4 жыл бұрын
Thanks a lot : )
@farrukhatabekov595
@farrukhatabekov595 5 жыл бұрын
Thanks a lot man
@ejsafara456
@ejsafara456 Жыл бұрын
god bless ya!
@BT-de4wl
@BT-de4wl 4 жыл бұрын
god bless you!
@rishabhchauhan6016
@rishabhchauhan6016 2 жыл бұрын
helped a fuck out of me !!
@matthewlev1342
@matthewlev1342 6 жыл бұрын
Thanks!
@gustavonavarro4205
@gustavonavarro4205 6 жыл бұрын
Suscribed!
@harelperry7051
@harelperry7051 6 жыл бұрын
Who think of that???!! (Thank you by the way..)
@lettttt5557
@lettttt5557 4 жыл бұрын
😭thanks
Кто круче, как думаешь?
00:44
МЯТНАЯ ФАНТА
Рет қаралды 5 МЛН
風船をキャッチしろ!🎈 Balloon catch Challenges
00:57
はじめしゃちょー(hajime)
Рет қаралды 92 МЛН
Long Nails 💅🏻 #shorts
00:50
Mr DegrEE
Рет қаралды 13 МЛН
Lowest Common Ancestor of a binary tree | Leetcode #236
17:29
Height of a Binary Tree / Maximum depth of a binary tree Algorithm [REVISITED]
16:50
Vivekanand Khyade - Algorithm Every Day
Рет қаралды 119 М.
Merge Sort step by step walkthrough (Recursion)
7:29
Stephen O'Neill
Рет қаралды 98 М.
Dynamic Programming isn't too hard. You just don't know what it is.
22:31
DecodingIntuition
Рет қаралды 197 М.
104. Maximum Depth of Binary Tree Java Solution
6:37
Code with Carter
Рет қаралды 912
New divisibility rule! (30,000 of them)
26:51
Stand-up Maths
Рет қаралды 274 М.
Depth First Search vs Breadth First Search (Graph)
5:54
Stephen O'Neill
Рет қаралды 29 М.
Кто круче, как думаешь?
00:44
МЯТНАЯ ФАНТА
Рет қаралды 5 МЛН