Invert Binary Tree (LeetCode 226) | Full solution with diagrams and animations | Study Algorithms
HTML-код
- Опубликовано: 2 авг 2024
- Inverting a binary tree is more synonymous with mirroring a binary tree. Try to assume that there is a mirror in front of the tree and you need to return the reflection. This video explains beautifully with diagrams and animations how the reflection looks like and how to create one. All of this is done using a level order traversal technique.
Actual Problem: leetcode.com/problems/invert-...
Chapters:
00:00 - Intro
00:58 - Problem Statement and Description
03:15 - The thought behind the approach
05:44 - Recursive Solution
08:56 - Level Order Traversal Trick
12:05 - Dry-run of Code
14:28 - Final Thoughts
📚 Links to topics I talk about in the video:
LeetCode Problems: • Leetcode Solutions
Level Order Traversal: • Level order traversal ...
Post Order Traversal: • Post-order traversal o...
Tree Data Structure: • Understanding Tree Dat...
📘 A text based explanation is available at: studyalgorithms.com
Code on Github: github.com/nikoo28/java-solut...
Test-cases on Github: github.com/nikoo28/java-solut...
📖 Reference Books:
Starting Learn to Code: amzn.to/36pU0JO
Favorite book to understand algorithms: amzn.to/39w3YLS
Favorite book for data structures: amzn.to/3oAVBTk
Get started for interview preparation: amzn.to/39ysbkJ
🔗 To see more videos like this, you can show your support on: www.buymeacoffee.com/studyalg...
🎥 My Recording Gear:
Recording Light: amzn.to/3pAqh8O
Microphone: amzn.to/2MCX7qU
Recording Camera: amzn.to/3alg9Ky
Tablet to sketch and draw: amzn.to/3pM6Bi4
Surface Pen: amzn.to/3pv6tTs
Laptop to edit videos: amzn.to/2LYpMqn
💻 Get Social 💻
Follow on Facebook at: / studyalgos
Follow on Twitter at: / studyalgorithms
Follow on Tumblr at: / studyalgos
Subscribe to RSS feeds: studyalgorithms.com/feed/
Join fan mail: eepurl.com/g9Dadv
#leetcode #programming #interview
Others: Let's explain recursive approach, done.
Nikhil: also explains BFS approach!
That's why you are a gem!
Every videos has 110% of good explanation.
Glad you like them!
Thank you so much .After a long search I got clearly explained video
thanks, very comprehensible!!
Hi sir,
First of all big fan of your work🙌
Requesting you to solve "Sum of distances in tree" problem of leetcode...
I have gone through many videos but none of them are clear...
Looking forward for your explanation 😇
Very well explained. Thank you so much for such nice content 🎉
My pleasure 😊
Thanks
Sir at 13:42 you added 2 and 7 to the Queue but shouldn't 7 and 2 be added to Queue because you did swapping before this . I really liked your explanation but having this little doubt. Please clear this minor doubt.
yes you are right
Yep…sorry for the confusion
Thank you so much for video with explaination.
May I check with you, why you put the keyword "final" in front of Queue ?
you can remove the "final" keyword if you like. It is not necessary in this implementation. :)
if(root == null) {
return null;
}
TreeNode temp=root.left;
root.left=root.right;
root.right=temp;
invertTree(root.left);
invertTree(root.right);
return root;
Sir this one take o(1)space? Then why using queue sir? Please any one explain?
why is the Linked List implementation of the queue being used here? can we use other thing like deque or other implementation of queue also?
Yes
@@nikoo28 Thanks! Your explanations are awesome
😃😃😃😃😃😃😃😃😃