Binary Tree Algorithms for Technical Interviews – Full Course



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

This Post Has 45 Comments

  1. 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++.

  2. Sami Haroon

    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.

  3. Shivam Rastogi

    Hello, Why did the 3rd solution at 1:19:37 took less time to execute than the other two solutions?

  4. Kris Meister

    The shift operation runs in O(n) time. Why is your breadth first example running in O(n) instead of O(n^2) ?

  5. Anna M

    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.

  6. ShivTheDev

    Hi Sir,
    Python design patterns… is there a course already published?

  7. Rene Corrales

    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)])

  8. Mike Chung

    very soothing voice… good explanations as well

  9. Ash

    Hi, I'm thinking to buy full Structy course, Anyone wants to share it?

  10. Anand Bhat

    You guys are simply the best. Thank you very much for these wonderful gems.

  11. Rajmanov

    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
    }

  12. Mohamed Siddic

    hey man you rocking, since 3 years i am learning data structure and algorithm.. i never feel this much understanding.

  13. Inna Bulatova

    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?

  14. AJ

    Alvin is the king!! Waiting for more videos form you!

  15. Khai No

    This guy is the best data structure and algorithm instructor I have known so far….

  16. Golu

    Why everything in javascript?

  17. tagakosmos

    make videos on maps queues hash and all the other dsa topics

  18. Benjamin Taylor

    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)
    }

  19. Rokevh

    "push the children if they exist" sounds hilarious out of context

  20. Mwee

    Alvin = immediate upvote.

  21. J M

    fantastic explanations. i would like some more information on when and where i would use these in the real world.

  22. Andrii Keidon

    Good video but I'd like to see step by step in debugging to make it even more clear

  23. Gabriel Fermy

    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.

  24. Victor Von Doom

    so , there's this girl who keeps asking me how to invert a binary tree. well ?

  25. ChrisJ Fox

    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?

  26. Arnon Marcus

    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.

  27. dcts

    Loved that course, your teaching style is very clear and really easy to follow 💯🎉

  28. Eugeniu Rata

    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?

  29. Michael Vigato

    Well, I am 26 and, thanks to this video, recursion just clicked in my brain for the first time in my life. Thanks

  30. Fantastic! I learned a lot with this tutorial. Thanks for sharing your knowledge with us. God bless you forever! ❤💯❤

Leave a Reply