How to solve (almost) any binary tree coding problem

  Рет қаралды 187,636

Inside code

Inside code

Күн бұрын

Пікірлер: 196
@edy231094
@edy231094 4 жыл бұрын
This is the most undervalued tree algorithm video. Info here is gold. Thanks man!
@insidecode
@insidecode 4 жыл бұрын
Thanks a lot for your comment
@tahaather7429
@tahaather7429 10 ай бұрын
Dude what an explanation. Thank you so much, using recursion to solve binary tree problems has been a really huge problem till now
@kwamenani7775
@kwamenani7775 3 жыл бұрын
I love people who make things this simple, just subscribed to your channel.
@insidecode
@insidecode 3 жыл бұрын
Thanks a lot!
@cakec9
@cakec9 3 жыл бұрын
Wow. Brilliant nugget!! Literally opened my eyes to the problems I am solving!!
@twi4458
@twi4458 2 жыл бұрын
same😍😍
@mahimapatel8706
@mahimapatel8706 3 ай бұрын
recursion is really messing with my mind
@Singh54321
@Singh54321 19 күн бұрын
true af
@iez
@iez 3 жыл бұрын
This is actually an amazing piece of intuition
@gurudevsanthosh8483
@gurudevsanthosh8483 Жыл бұрын
For height of tree it must return -1 if root is null.(2.42)
@siddharthvikram3054
@siddharthvikram3054 Жыл бұрын
that depends if u are taking the height of a leaf node to be 1 or 0, it depends upon the book u are using
@indraneel6601
@indraneel6601 3 жыл бұрын
Give this guy a whole lot of subscribers!!!!!! I feel confident to solve tree problems.You Rock man Please Create a video how to solve graph problems.
@insidecode
@insidecode 3 жыл бұрын
Thanks!!
@marcin-guitar
@marcin-guitar 2 жыл бұрын
Well, this is true for a certain kind of trees, where each node counts as equivalent. The same algorithm doesn't necessarily apply to segment trees, binary search trees, KD-trees etc. where an element's position in the tree is more important than its sole presence in the tree.
@insidecode
@insidecode 2 жыл бұрын
Yes it doesn't apply for all types of trees sure
@coolkid9206
@coolkid9206 2 жыл бұрын
@@insidecode do u have a similar video coming for binary search trees
@karthigeyanramesh4477
@karthigeyanramesh4477 Жыл бұрын
I just wanna say, that thinking of recursion in a way where we fragment the root node made sooooo much sense. My exam is next week, thanks!
@TourismFunFriends
@TourismFunFriends Жыл бұрын
Thank u so so soo much man Non linear data structures were really tough for me From school to college It was tough for me to understand But now when i am preparing for a job I saw your video And u saved my life Thank u so much
@KGTube
@KGTube 4 жыл бұрын
Very easy described man! Give this man a medal!
@insidecode
@insidecode 4 жыл бұрын
Thankss ❤️
@levidworkin851
@levidworkin851 7 ай бұрын
Hey Inside Code I loved the video! I just wanted to correct the treeHeight algorithm. It needs to return -1 if the root is None because currently with the returning of 0, the leaf nodes get a height of 1 instead of a height of 0 which will cause the resulting tree height to be 1 greater than it should be.
@flaykaz
@flaykaz 11 ай бұрын
u r genius...the most simple ways i see to learn this bianry tree...tysm blud
@RR-wx8gp
@RR-wx8gp 7 ай бұрын
Honestly.... This video is just the best!!!
@mdzikrullah9575
@mdzikrullah9575 3 жыл бұрын
This was the coolest explanation of complex problem ever..Thank you
@insidecode
@insidecode 3 жыл бұрын
You're welcome!
@DaggerMan11
@DaggerMan11 3 жыл бұрын
exactly. Once you realize these complex problems all have some pretty easy-to-remember patterns that make them easier to solve, it's just a matter of knowing which pattern to apply.
@hydromarlon4168
@hydromarlon4168 3 жыл бұрын
Bruh. This finally makes sense.
@shivansh2581
@shivansh2581 2 жыл бұрын
LEGIT MAGICK!!!!! i just solved a question using this logic. SO LUCID. SO CLEAR. TO THE POINT
@longchikanouo4905
@longchikanouo4905 2 жыл бұрын
Finally, this is what I have been looking for; algorithms with proper visualizations. I had to buy all your 5 courses on udemy
@insidecode
@insidecode 2 жыл бұрын
Thanks a lot for your comment!
@ifeanyi3713
@ifeanyi3713 2 жыл бұрын
hello, is his dynamic programming course in python?
@insidecode
@insidecode 2 жыл бұрын
Hello, yes it is
@ifeanyi3713
@ifeanyi3713 2 жыл бұрын
@@insidecode thanks for the reply, I will purchase it. are all your other courses on Udemy in python as well ?
@insidecode
@insidecode 2 жыл бұрын
@@ifeanyi3713 You're welcome! Yes
@igbalajobizhikrullah465
@igbalajobizhikrullah465 2 жыл бұрын
You just earned a new subscriber.... Spent hours searching for a simple explanation on Trees, found it in your channel.
@insidecode
@insidecode 2 жыл бұрын
@weixiangwong2227
@weixiangwong2227 Жыл бұрын
thank you for this video. i'm really bad at binary trees but this way of thinking about it really helps
@auntyBill
@auntyBill 6 ай бұрын
Amazing way of presenting… it’s awesome
@twi4458
@twi4458 2 жыл бұрын
Thanks we got a whole diffrent persepective of solving problem. Could you make this kinda videos for other DS also, pls
@insidecode
@insidecode 2 жыл бұрын
You're welcome! I'll see
@vijayola7597
@vijayola7597 3 жыл бұрын
amazing video !! please make more videos in binary trees and graphs
@insidecode
@insidecode 3 жыл бұрын
Okay!
@aspiretechie1191
@aspiretechie1191 27 күн бұрын
Recursion is the base algo you need to master before learning trees, If you are good at recursion then trees is nothing.
@germanrud4541
@germanrud4541 29 күн бұрын
what is the complexity of this kind of algorithms?
@danielapineyro1998
@danielapineyro1998 3 жыл бұрын
MAN YOU MADE ME UNDERSTAND RECURSION, finally! Thank you so much!
@insidecode
@insidecode 3 жыл бұрын
You're welcome! Check the 3 hours recursion course I published recently here
@danielapineyro1998
@danielapineyro1998 3 жыл бұрын
@@insidecode I’ll check it out. Thank you!
@insidecode
@insidecode 3 жыл бұрын
@@danielapineyro1998 I don't have a video on that but I can explain it to you here, did you see in this video the function where we calculate the sum? We calculate the sum from the left, the sum from the right, and we add to them the parent's value. For your problem, you take the same function, but you just add two things, a global boolean variable output that starts at true, and a condition before returning the sum in the recursive function, that condition is: if root.data != left+right: output = False
@insidecode
@insidecode 3 жыл бұрын
@@danielapineyro1998 What we're doing here is that we're traversing the tree, but at each node, after calculating the sum of both subtrees, we're comparing with the parent's value, and we're setting the final output to false if they're different, we used a global variable to be able to access it from any call
@insidecode
@insidecode 3 жыл бұрын
@@danielapineyro1998 The code would be something like this: output = True def tree_sum(root): global output if root is None: return 0 else: left = tree_sum(root.left) right = tree_sum(root.right) if root.data != left+right: output = False return root.data + left + right def all_equal(root): global output tree_sum(output) return output
@mayankkhanna9644
@mayankkhanna9644 2 жыл бұрын
Can we solve every binary tree problem using either BFS or DFS?
@kacap-p6t
@kacap-p6t 2 ай бұрын
To the point and well explained!
@decayingskulls7088
@decayingskulls7088 3 жыл бұрын
bro just opened my mind
@JohnDoe-yb9rg
@JohnDoe-yb9rg 2 жыл бұрын
Will this formula work for Visible Tree Node problem? If yes, how? Thank you!
@Satyamkumar19113
@Satyamkumar19113 6 ай бұрын
Just the best idea to approach binary 🌲 questions
@ragapriyakarthikeyan3139
@ragapriyakarthikeyan3139 7 ай бұрын
This is exactly what I was looking for💥
@mdzikrullah9575
@mdzikrullah9575 3 жыл бұрын
Kindly make a similiar video on Graphs. It will be soo helpfull. Thanks
@suri4Musiq
@suri4Musiq 4 ай бұрын
Isn't this just post-order DFS?
@madhavkwatra5888
@madhavkwatra5888 5 ай бұрын
Superb explanation , Thanks.
@dhairya18
@dhairya18 4 жыл бұрын
Very sell described. Good work. Keep it up👍
@insidecode
@insidecode 4 жыл бұрын
Thanks!
@rclarke88
@rclarke88 3 жыл бұрын
The sum of elements at 1:21 is not 120.
@rclarke88
@rclarke88 3 жыл бұрын
@@insidecode That was a bit nit-picky of me to point that out. The video was still very good and I look forward to watching more from you.
@insidecode
@insidecode 2 жыл бұрын
Hello, after watching it again, it's actually 120, because we're returning sum of left subtree + sum of right subtree + root's value, and 52 + 53 + 5 gives 120 not 115, you forgot to also add the root's value which is 5
@vyankateshkulkarni4374
@vyankateshkulkarni4374 2 жыл бұрын
great explanation sir, thank you so much
@premraja55
@premraja55 3 жыл бұрын
Wow, thats such a good approach! Thanks
@insidecode
@insidecode 3 жыл бұрын
You're welcome!
@pyrostation678
@pyrostation678 2 жыл бұрын
Thanks man, this is awesome!!
@TomGoo
@TomGoo 8 ай бұрын
wow this actually helped me so much thx
@coolkid9206
@coolkid9206 2 жыл бұрын
This actually works holy shit this is insane
@curesnow6493
@curesnow6493 2 жыл бұрын
Thank you so much for this video!
@insidecode
@insidecode 2 жыл бұрын
Glad it was helpful!
@shechan456
@shechan456 3 жыл бұрын
Thanku sor finally i understood Tree data after 2 months ,thanks a lot Your content is freat
@insidecode
@insidecode 3 жыл бұрын
You're welcome!
@Radi0he4d1
@Radi0he4d1 3 жыл бұрын
This nails it
@paulamorillasalonso3076
@paulamorillasalonso3076 2 жыл бұрын
Great video! I'm definetly subscribing😄
@insidecode
@insidecode 2 жыл бұрын
Thanks for subbing!
@josiahdavid7735
@josiahdavid7735 2 жыл бұрын
This man is literally the best!!!
@insidecode
@insidecode 2 жыл бұрын
Thanks a lot!
@jacobmoore8734
@jacobmoore8734 2 жыл бұрын
Omg it's literally always the same thing, how have I never noticed this before?
@harinijeyaraman8789
@harinijeyaraman8789 4 жыл бұрын
Super helpful ! Great content
@insidecode
@insidecode 4 жыл бұрын
Thanks
@chandandigumarthy9652
@chandandigumarthy9652 2 жыл бұрын
Amazing man! very helpful
@insidecode
@insidecode 3 жыл бұрын
Fix: At 2:38, the base case should return -1 not 0
@Raven-zk2xq
@Raven-zk2xq 3 жыл бұрын
Maybe I misunderstand why, but I think of it like this. If the input is simple None to begin with, is the height 0 or is it 1? From my understanding it would be 0, similar to how an len(arr) where arr is an empty array would also return 0.
@insidecode
@insidecode 3 жыл бұрын
@@Raven-zk2xq Yes but height 0 is the height of a tree with one node only (the root), so when a tree has no nodes at all, its height is -1
@fifibishi7786
@fifibishi7786 3 жыл бұрын
wow very well explained, thank you sooo much!
@insidecode
@insidecode 3 жыл бұрын
you're welcome!
@procode6881
@procode6881 3 жыл бұрын
Wonderful explaination
@filmbotreviews
@filmbotreviews 2 жыл бұрын
High quality video! Thanks
@insidecode
@insidecode 2 жыл бұрын
You're welcome
@prasanthbupd
@prasanthbupd 3 ай бұрын
the best video I have ever seen in my life definitely a like. and a subscribe
@eshank2508
@eshank2508 3 жыл бұрын
Hi..i have to appear a HireVue interview soon for Deloitte. Will this coursepack be useful to me?
@insidecode
@insidecode 3 жыл бұрын
It contains a lot of popular problems on different patterns and data structures, so it will be useful for you for sure
@hangoutwithabhi
@hangoutwithabhi 3 жыл бұрын
This is super cool. Thanks 👍🏻
@insidecode
@insidecode 3 жыл бұрын
You're welcome
@iangoodman7273
@iangoodman7273 3 жыл бұрын
isn't the tree that appears at 30 seconds not a valid bst?
@insidecode
@insidecode 3 жыл бұрын
It's not supposed to be a BST
@playingwithmhdsulu786
@playingwithmhdsulu786 5 ай бұрын
Help full video thank you❤
@KeshavKumar-qz7ow
@KeshavKumar-qz7ow 3 жыл бұрын
1:20 the sum will be 110 instead of 120
@insidecode
@insidecode 3 жыл бұрын
You took time to calculate :0 But thanks for telling me!
@isaacfs8995
@isaacfs8995 3 жыл бұрын
SUPER HELPFUL!
@tanujm87
@tanujm87 3 жыл бұрын
Super helpful bro. Thanks a lot ❣️
@insidecode
@insidecode 3 жыл бұрын
You're welcome!
@astronautonmars
@astronautonmars 2 жыл бұрын
Wow! Super helpful!
@paladin5d781
@paladin5d781 Жыл бұрын
simple beneficial and inspiring
@rajathrao3209
@rajathrao3209 2 жыл бұрын
Damn never knew tree's can be broken down like this
@sergeynazarov2473
@sergeynazarov2473 8 ай бұрын
With all respect to the author, this is trivial problems, I thought you clarify at least one of non-trivial: controlling levels of tree, controlling branches of tree, controlling nodes of tree or controlling symmethric of tree.
@PepeTostado
@PepeTostado 2 жыл бұрын
How do you learn this for sure?
@insidecode
@insidecode 2 жыл бұрын
Learn what?
@shashicsnitjsr
@shashicsnitjsr 3 жыл бұрын
How do you create the animation? Are you using any software for tha?
@insidecode
@insidecode 3 жыл бұрын
With PowerPoint
@shashicsnitjsr
@shashicsnitjsr 3 жыл бұрын
@@insidecodeOhhk. Thanks a lot.
@insidecode
@insidecode 3 жыл бұрын
@@shashicsnitjsr You're welcome!
@ojas2121
@ojas2121 3 жыл бұрын
best video. perfectly explained.
@insidecode
@insidecode 3 жыл бұрын
Thanks!
@manikantpandey4753
@manikantpandey4753 3 жыл бұрын
Can we have pdf of these codes?
@insidecode
@insidecode 3 жыл бұрын
I didn't make a PDF of them sorry
@AviPars
@AviPars 2 жыл бұрын
Thanks, share code too!!
@StrangeDooropen
@StrangeDooropen 10 ай бұрын
OMG thank u so much !
@BryceChudomelka
@BryceChudomelka 2 жыл бұрын
This is amazing
@amanr007
@amanr007 3 жыл бұрын
Wow 😎 🥺 thanks brother no more grinding
@rishav2520
@rishav2520 3 жыл бұрын
It's really Awesome 🤩
@droid806
@droid806 3 жыл бұрын
Your code in 1:31 doesn’t seem to work
@insidecode
@insidecode 3 жыл бұрын
What error you got? Maybe you didn't create Tree class or something
@yoman9446
@yoman9446 3 жыл бұрын
But what about trees that are not binary?
@insidecode
@insidecode 3 жыл бұрын
Also works with k-ary trees, instead of calling the function on tree.left and tree.right, you call the function on each children by using a for loop then you join the results (Example: sum of nodes of a k-ary tree: ... sum_children = 0 for children in tree.children: sum_children += tree_sum(children) return tree.val + sum_children
@yoman9446
@yoman9446 3 жыл бұрын
@@insidecode Thanks!
@insidecode
@insidecode 3 жыл бұрын
@@yoman9446 You're welcome!
@Jigar_S_Rajput
@Jigar_S_Rajput Жыл бұрын
Watch it in 0.75x
@MrRyanroberson1
@MrRyanroberson1 3 жыл бұрын
that bri-eff though XD (brief is said as breef, not bri-eff)
@insidecode
@insidecode 3 жыл бұрын
oh thanks for info!
@markfung1
@markfung1 2 жыл бұрын
OMg this is amazing lol thank you so much
@insidecode
@insidecode 2 жыл бұрын
You're welcome!
@chetanshrivastava3762
@chetanshrivastava3762 3 жыл бұрын
Very Nice.God bless you..
@MrLump
@MrLump 3 ай бұрын
4:20 nice
@myrelaxpoint
@myrelaxpoint 3 жыл бұрын
A BIG Thank you 🌹
@insidecode
@insidecode 3 жыл бұрын
You're welcome!
@adithiyagurupatham3255
@adithiyagurupatham3255 3 жыл бұрын
You've earned a new subscriber 🔥
@insidecode
@insidecode 3 жыл бұрын
Thankss!
@lukehatcher98
@lukehatcher98 3 жыл бұрын
Great video
@nischayagrawalVlogs
@nischayagrawalVlogs Жыл бұрын
Please dont try to eat mic when ur speaking. Its not a proper etiquette. Btw very nice explanation.
@insidecode
@insidecode Жыл бұрын
Thanks! This is quite an old video, can you check latest ones and tell me if sound quality improved?
@nischayagrawalVlogs
@nischayagrawalVlogs Жыл бұрын
@@insidecode Woah its really good. Just curious what mic do you use now?
@insidecode
@insidecode Жыл бұрын
The same mic (M-Audio Uber mic), just improved audio post processing
@sniff4643
@sniff4643 3 жыл бұрын
can I donate to you on patreon? I rly liked this video.
@fahmidurarnob2470
@fahmidurarnob2470 3 жыл бұрын
Thanks a lot🖤
@insidecode
@insidecode 3 жыл бұрын
You're welcome!
@hildamartin8022
@hildamartin8022 2 жыл бұрын
thank you!
@insidecode
@insidecode 2 жыл бұрын
You're welcome!
@kirillzlobin7135
@kirillzlobin7135 Жыл бұрын
Great channel
@minusCEE
@minusCEE 2 жыл бұрын
Underated video
@germanrud4541
@germanrud4541 29 күн бұрын
awesome, thxxxxx
@lorenzo.fiorini
@lorenzo.fiorini 3 жыл бұрын
Easy and straight forward
@subee128
@subee128 6 ай бұрын
Thanks
@titonicoladrugman
@titonicoladrugman 2 жыл бұрын
Why you are so smart?
@insidecode
@insidecode 2 жыл бұрын
haha 😂
@harsh9558
@harsh9558 3 жыл бұрын
Thx a lot!!!!!
@insidecode
@insidecode 3 жыл бұрын
You're welcome!
@oladipotimothy6007
@oladipotimothy6007 3 жыл бұрын
Recursive thinking
@alexirabor
@alexirabor 2 жыл бұрын
Thank you
@insidecode
@insidecode 2 жыл бұрын
Welcome!
@mahmudulahsan
@mahmudulahsan 2 жыл бұрын
Great!
Mastering Dynamic Programming - How to solve any interview problem (Part 1)
19:41
How to solve binary tree path-related problems - Inside code
5:32
Муж внезапно вернулся домой @Oscar_elteacher
00:43
История одного вокалиста
Рет қаралды 6 МЛН
If people acted like cats 🙀😹 LeoNata family #shorts
00:22
LeoNata Family
Рет қаралды 9 МЛН
LeetCode was HARD until I Learned these 15 Patterns
13:00
Ashish Pratap Singh
Рет қаралды 577 М.
Whiteboard Coding Interviews: 6 Steps to Solve Any Problem
15:18
Fullstack Academy
Рет қаралды 378 М.
5 Simple Steps for Solving Any Recursive Problem
21:03
Reducible
Рет қаралды 1,2 МЛН
How to Implement a Tree in C
14:39
Jacob Sorber
Рет қаралды 100 М.
8 patterns to solve 80% Leetcode problems
7:30
Sahil & Sarra
Рет қаралды 438 М.
5 Simple Steps for Solving Dynamic Programming Problems
21:27
Reducible
Рет қаралды 1,1 МЛН
Premature Optimization
12:39
CodeAesthetic
Рет қаралды 834 М.
Dynamic Programming - Learn to Solve Algorithmic Problems & Coding Challenges
5:10:02
C++ vs Rust: which is faster?
21:15
fasterthanlime
Рет қаралды 403 М.