Learn how to implement binary tree algorithms and how to use them to solve coding challenges. 🌳
✏️ This course was developed by Alvin Zablan from Structy. Check out Alvin’s channel: https://www.youtube.com/c/AlvinTheProgrammer
🔗 Learn data structures and algorithms: https://structy.net/
⭐️ Course Contents ⭐️
⌨️ (0:00:00) Course Introduction
⌨️ (0:01:09) What is a Binary Tree?
⌨️ (0:11:28) Binary Tree Node Class
⌨️ (0:14:19) Depth First Values – (https://structy.net/problems/depth-first-values)
⌨️ (0:36:00) Breadth First Values – (https://structy.net/problems/breadth-first-values)
⌨️ (0:47:43) Tree Includes – (https://structy.net/problems/tree-includes)
⌨️ (1:05:35) Tree Sum – (https://structy.net/problems/tree-sum)
⌨️ (1:19:53) Tree Min Value – (https://structy.net/problems/tree-min-value)
⌨️ (1:34:16) Max Root to Leaf Path Sum – (https://structy.net/problems/max-root-to-leaf-path-sum)
⌨️ (1:48:28) Conclusion
🎉 Thanks to our Champion and Sponsor supporters:
👾 Wong Voon jinq
👾 hexploitation
👾 Katia Moran
👾 BlckPhantom
👾 Nick Raker
👾 Otis Morgan
👾 DeezMaster
👾 AppWrite
—
Learn to code for free and get a developer job: https://www.freecodecamp.org
Read hundreds of articles on programming: https://freecodecamp.org/news
And subscribe for new videos on technology every day: https://youtube.com/subscription_center?add_user=freecodecamp
source
Hey Programmers! Thanks for watching. Head to Structy for more data structure and algorithm tutorials from me. Link available in the description. There you'll find animated explanations and video walkthroughs for data structures and algorithms in JavaScript, Python, and C++.
Covered this video in one night 😀
Amazing by the speed and quality of teaching from Alvin.
Really helpful stuff, and recommend Alvin for getting prepared for DS&A.
Hello, Why did the 3rd solution at 1:19:37 took less time to execute than the other two solutions?
Awesome!!!
The shift operation runs in O(n) time. Why is your breadth first example running in O(n) instead of O(n^2) ?
I love that he goes over all the common mistakes people often make on the first try! It's very normalizing to see him show those mistakes, makes me feel much better lol, and also the explanations of those mistakes dig deeper and improve our understanding.
Hi Sir,
Python design patterns… is there a course already published?
How to do the magic trick (selecting and editing both 'a' in one line) at 12:48
You are getting my money, I'm being this course.
Alvin, you are the best. Thank you
Thank You Alvin..
Which editor is this?
I think this looks better for the last one
def maxPath(root):
if root == None: return 0
return root.val + max([maxPath(root.right), maxPath(root.left)])
I love when he says Alright
very soothing voice… good explanations as well
Hi, I'm thinking to buy full Structy course, Anyone wants to share it?
You guys are simply the best. Thank you very much for these wonderful gems.
thanks , very easy to understand
I just what to add the code in kotlin for the Iterative case for the Max root to leaf Path Sum problem:
fun maxRootDFSIterative(root: TreeNode<Int>?):Int{
var maxSumPath = Int.MIN_VALUE
val stack = ArrayDeque<TreeNode<Int>>()
root?.let { stack.push(it) }
while (stack.isNotEmpty()){
val currentNode = stack.pop()
currentNode.right?.let {
it.value += currentNode.value
stack.push(it)
}
currentNode.left?.let {
it.value+=currentNode.value
stack.push(it)
}
if (currentNode.right==null && currentNode.left== null){
maxSumPath = max(maxSumPath, currentNode.value)
}
}
return maxSumPath
}
hey man you rocking, since 3 years i am learning data structure and algorithm.. i never feel this much understanding.
Hi, I am a bit lost at 32:46. How come leftValues recursive solution would give you 'e' node if it is a right node on the left side?
Alvin is the king!! Waiting for more videos form you!
Excellent!!
This guy is the best data structure and algorithm instructor I have known so far….
Why everything in javascript?
make videos on maps queues hash and all the other dsa topics
const bredthFirstRecursive = (queue, values) => {
if (!queue.length) return values
const last = queue.pop()
values.push(last)
if (last?.left) queue.unshift(last.left)
if (last?.right) queue.unshift(last.right)
return bredthFirstRecursive(queue, values)
}
Every while loop can be converted to a recursion.
Excellent!!!!!!
"push the children if they exist" sounds hilarious out of context
Alvin = immediate upvote.
fantastic explanations. i would like some more information on when and where i would use these in the real world.
Good video but I'd like to see step by step in debugging to make it even more clear
This is a very greate tutorial and explaination. This video describe how a programmer mind set should be when facing problems in step by step.
so , there's this girl who keeps asking me how to invert a binary tree. well ?
In using the LIFO Stack for Depth-First Search, it seems redundant to me that the removal of nodes from the Stack is the indication that its been visited. Decision criteria must exist to determine which got added to the Stack next to begin with so why not declare it visited based on the conditional then?
Using the value of a node when visiting instead of when pushing doesn't always produce the most optimal solution – for "sum" it doesn't matter, but for "includes" it does matter if using depth-first, because the "target" may at a shallow level, and if it's sub-tree is very large it'll have to be traversed in-full before realising that the root of that sub-tree already was the target. That's not an asymptotic-complexity issue though, as that only deals with worst-case, but it IS a real-world consideration for performance, so should not be just relegated to a "matter of style" – writing the code that does the optimal thing may be slighly more ugly but will be more performant in many cases, so the correct way of presenting that is as a performance vs. cleanliness tradeoff, not a stylistic choice.
We must go deeper
thank you alvin, and free code camp
Loved that course, your teaching style is very clear and really easy to follow 💯🎉
to complicate the things, for the Max sum of paths, I'd like to also get the actual node values in an array. How would I do this?
Great way of explaining binary treees
Well, I am 26 and, thanks to this video, recursion just clicked in my brain for the first time in my life. Thanks
Fantastic! I learned a lot with this tutorial. Thanks for sharing your knowledge with us. God bless you forever! ❤💯❤
Thanks