Subsets - Leetcode 78 - Recursive Backtracking (Python)

Поделиться
HTML-код
  • Опубликовано: 25 дек 2024

Комментарии • 37

  • @GregHogg
    @GregHogg  5 месяцев назад

    Master Data Structures & Algorithms For FREE at AlgoMap.io!

  • @SHIHJUIheh
    @SHIHJUIheh 5 месяцев назад +6

    Thank you for explaining drawing part in detail, especially the recursive backtracking part ! You made this concept so much easier!!!

    • @GregHogg
      @GregHogg  5 месяцев назад

      You're very welcome 😎

    • @itsmenatika
      @itsmenatika 2 месяца назад

      I've started understanding backtracking by that. In only 12 minutes. Thanks

  • @NavneetKaur-x6q
    @NavneetKaur-x6q 3 месяца назад +1

    After looking at several other videos, I finally found one where all my questions were answered. Loved the simplicity of the explanation whether whiteboard, coding part or the complexity.

  • @vasachisenjubean5944
    @vasachisenjubean5944 10 дней назад

    Absolutely beautiful explanation. I loved it !!

  • @anothertechguy-q9g
    @anothertechguy-q9g 3 месяца назад +1

    Thank you a lot for explaining the transitive parts of backtracking!

  • @shubhambajaj4939
    @shubhambajaj4939 5 месяцев назад +1

    brilliant solution. you just got yourself a new subscriber :)

  • @chisomedoka5651
    @chisomedoka5651 6 месяцев назад +1

    this is gold, so intuitive . Thanks for this

  • @kenkaneki5433
    @kenkaneki5433 3 месяца назад +2

    better than stp neetcode guy explanation

  • @christianjt7018
    @christianjt7018 4 месяца назад +1

    thanks Greg your explanations are the best!

    • @GregHogg
      @GregHogg  4 месяца назад

      Bro I can see from the comments that you're just flying through these questions, good for you honestly!

  • @FZRides
    @FZRides 6 месяцев назад +3

    Hi Greg,
    I found your video very intuitive. Thanks for sharing such content. Can you please make a video on "Tower of Hanoi" problem using recursion. I am unable to catch the recursive logic behind it. Can you please do it Sir.

  • @dusvn1484
    @dusvn1484 2 месяца назад

    Nice video,helped me a lot!

  • @just4laughs140
    @just4laughs140 4 месяца назад +1

    what does backtrack(i +1) mean

  • @DivineEdoka
    @DivineEdoka 3 месяца назад +1

    I'll like to see how you slve subset ii with this pattern as well

  • @GarouNguyen
    @GarouNguyen 5 месяцев назад +1

    bro how do you move recursion left what is line 12 code back track i + 1 , why you have two backtrack(i+1) can you explain bro

  • @sampjm1898
    @sampjm1898 7 месяцев назад +1

    you can use a dp solution :
    fn(n)=fn(n-1)+{fn(n-1) and put element_n in every set that return by fn(n-1)},cache the result of f(n).,f(n-1).....
    consider you need to solve all the fn(n) you can write a bottom up dp solution,
    consider for each fn(n) only need f(n-1) you can just maintain one layer of cache
    so basic case is {[element_1],[empty]} for every element in the array add this element to each set and add this set back to the result:
    so the 2nd iteration: {[element_1],[empty],
    [element_1,element_2],[element_2]} and so on
    sorry for my English

    • @GregHogg
      @GregHogg  7 месяцев назад

      I'll have to look into this. Thanks so much for sharing!

    • @supremoluminary
      @supremoluminary 7 месяцев назад

      Do you have a link to this? I want to learn it. Thanks.

  • @phamh79
    @phamh79 2 месяца назад

    many thanks.

  • @m.y.7230
    @m.y.7230 5 месяцев назад

    thanks for explaning dfs in drawing

    • @GregHogg
      @GregHogg  5 месяцев назад

      No problem!

  • @Alex-tm5hr
    @Alex-tm5hr 2 месяца назад

    Can you pls make a vid for subsets 2?

  • @anti-dn541
    @anti-dn541 7 месяцев назад +1

    Easy to understand for noob like me 👍🏻

    • @GregHogg
      @GregHogg  7 месяцев назад

      Oh that's so great to hear 😊

  • @olaf9063
    @olaf9063 7 месяцев назад +1

    Great explanation, thanks. Is the time complexity not O(n * 2^n) - reason being that at each of the terminal nodes you need to copy the list, which is an O(n) operation?

    • @henryhan8838
      @henryhan8838 7 месяцев назад

      You've inspired me, I was just wondering why we multiplied it by n.

    • @tauicsicsics
      @tauicsicsics 22 дня назад

      indeed, I thing Gregg forgot the "n *" part of the time complexity, it's not O(2^n)

  • @maskedoni3229
    @maskedoni3229 8 месяцев назад

    Great solution

    • @GregHogg
      @GregHogg  8 месяцев назад +1

      Thanks so much!

  • @nav213
    @nav213 4 месяца назад

    Would backtracking have to do with recursion? Is it possible to solve this in a non-recursive way? I am asking because it's really difficult to understand the recursive implementation of the code unless you memorize it. Thanks again for you awesome tutorials!!!! cheers

    • @GregHogg
      @GregHogg  4 месяца назад

      You can memorize the template for how this is done, I promise the best way is through recursion

  • @GarouNguyen
    @GarouNguyen 5 месяцев назад

    bro why don't pick and pick is same backtrack(i+1) and why you recursion left i + 1 i don't understand

  • @hrushik10
    @hrushik10 4 месяца назад

    thanks

  • @Antinormanisto
    @Antinormanisto 7 месяцев назад +1

    I don't understand(

    • @GregHogg
      @GregHogg  7 месяцев назад

      Maybe try watching it again? Backtracking is REALLY confusing at first