How to solve binary tree path-related problems - Inside code

แชร์
ฝัง
  • เผยแพร่เมื่อ 21 ก.ค. 2024
  • Source code: gist.github.com/syphh/30aa9ea...
    🔴 Learn graph theory algorithms: inscod.com/graphalgo
    ⚙ Learn dynamic programming: inscod.com/dp_course
    💡 Learn to solve popular coding interview problems: inscod.com/50problems_course
    ⌛ Learn time and space complexity analysis: inscod.com/complexity_course
    🔁 Learn recursion: inscod.com/recursion_course
    NB: This video is ad-free, you can choose to support Inside code by purchasing one of the courses above or dropping a super thanks!
    NB2: Discounts of courses above are permanent
    I also post content on LinkedIn (inscod.com/linkedin) and Instagram (inscod.com/instagram)
  • วิทยาศาสตร์และเทคโนโลยี

ความคิดเห็น • 29

  • @manulscode
    @manulscode 2 ปีที่แล้ว +6

    In 5 minutes there's more value in this video than in hours of other tutorials!

  • @tmanley1985
    @tmanley1985 3 ปีที่แล้ว +9

    This has to be the simplest explanation on youtube. The idea of taking an idea like DFS or BFS, and showing example after example of it being used with increasing complexity is the best way to learn. I bought your course on Udemy just to support you.

    • @insidecode
      @insidecode  3 ปีที่แล้ว +1

      Wow, thanks a lot!

  • @kalpeshsharma3446
    @kalpeshsharma3446 2 ปีที่แล้ว +1

    Brother you are a saviour...please do more videos like this only on all data structures, and common algorithms which can solve many questions.

  • @bitasadeghi5312
    @bitasadeghi5312 2 ปีที่แล้ว +2

    Your amazing tutorials helped me immensely, please keep them coming. Thank you!!!

  • @sainathsingineedi2922
    @sainathsingineedi2922 3 ปีที่แล้ว +1

    Nice explanation. Animations are 🔥

  • @PriyadarshiPrashant
    @PriyadarshiPrashant 2 ปีที่แล้ว

    i am glad that found your channel

  • @naveenkumarnalabothu9926
    @naveenkumarnalabothu9926 2 ปีที่แล้ว

    The code used for getting path array is returning empty array.., can you please check again

  • @somyagupta5491
    @somyagupta5491 2 ปีที่แล้ว +1

    Great explanation, one stop point for conceptual understanding of various path related problems

    • @somyagupta5491
      @somyagupta5491 2 ปีที่แล้ว

      Could you please make a video on construction of trees using various given traversals like preorder,postorder etc?
      That would be really helpful

    • @insidecode
      @insidecode  2 ปีที่แล้ว +1

      It would be interesting yes

  • @ISABELLEDUPONTTT
    @ISABELLEDUPONTTT 4 หลายเดือนก่อน

    for the Lca function basically in exam we can't use break; so what can i replace it with? if the path doesnt match?

    • @HOMMIAABIR
      @HOMMIAABIR หลายเดือนก่อน

      u can for example add a boolean, initialize it to true and add it as a condition in the while loop, if we reach the else condition(path1[i]path2[j])u can set it to false to exit the loop, hope i helped!

  • @anubhavsethi3416
    @anubhavsethi3416 3 ปีที่แล้ว

    good content btw !

  • @oussamabaadj9355
    @oussamabaadj9355 3 ปีที่แล้ว

    THE BEST ! "after me"

  • @nit_gaal
    @nit_gaal 2 ปีที่แล้ว

    I am ur new subscriber 🤗

  • @akshay5469
    @akshay5469 3 ปีที่แล้ว +3

    Can you make a video for tree problems where path doesn't necessarily pass through root? I struggle here thanks!

  • @motasemmeqbel6742
    @motasemmeqbel6742 3 ปีที่แล้ว

    Amazing

  • @subee128
    @subee128 2 หลายเดือนก่อน

    thanks

  • @akshay5469
    @akshay5469 3 ปีที่แล้ว +1

    Great

  • @pdfToMp3
    @pdfToMp3 2 ปีที่แล้ว

    Ur a hero

  • @mobeenegbaria1617
    @mobeenegbaria1617 2 ปีที่แล้ว

    I am wondering and trying to figure out What is the answer to the exercise 3:24 with just using dfs func with an additional parameter val2

    • @insidecode
      @insidecode  2 ปีที่แล้ว +1

      Any node in a binary tree is a root of a smaller tree, so we can just combine the search() and the get_path() function, we search for the source node, then we call get path on it once we find it

    • @Ikhideifidon
      @Ikhideifidon 2 ปีที่แล้ว

      All you just need to do is to search for the source node and make it the root of the tree.

  • @AinurEru
    @AinurEru 2 ปีที่แล้ว

    For lca there's no need to make 2 paths, here's a simple dfs that does it:
    def lca(root, val1, val2):
    if root in (val1, val2):
    return root
    left = root.left.lca(val1, val2) if root.left else None
    right = root.right.lca(val1, val2) if root.right else None
    return root if left and right else (left or right)

  • @oussamabaadj9355
    @oussamabaadj9355 3 ปีที่แล้ว

    L engineeeeer yah !