Subsets - Leetcode 78 - Recursive Backtracking (Python)

Sdílet
Vložit
  • čas přidán 23. 04. 2024
  • Master Data Structures & Algorithms for FREE at AlgoMap.io/
    Code solutions in Python, Java, C++ and JS for this can be found at my GitHub repo here: github.com/gahogg/Leetcode-So...
    Complete DSA Pathway Zero to Hero: • Data Structures & Algo...
    Please check my playlists for free DSA problem solutions:
    • Fundamental DSA Theory
    • Array & String Questions
    • 2 Pointers Questions
    • Sliding Window Questions
    • Binary Search Questions
    • Stack Questions
    • Linked List Questions
    • Tree Questions
    • Heap Questions
    • Recursive Backtracking...
    • Graph Questions
    • Dynamic Programming (D...
    My Data Science & ML CZcams Playlist: • Greg's Path to Become ...
    Learn Python and Data Science FASTER at mlnow.ai :)
    Support the content: / @greghogg
    Follow me on Instagram: / greghogg5
    Connect with me on LinkedIn: / greghogg
    Follow me on TikTok: / greghogg5
    Coursera Plus: imp.i384100.net/P0E3J6
    My Favorite Courses:
    Data Structures & Algorithms:
    - UCalifornia San Diego DSA: imp.i384100.net/LP31oV
    - Stanford Algorithms: imp.i384100.net/vNBoxd
    - Python Data Structures: imp.i384100.net/NkZn47
    - Meta Coding Interview Prep: imp.i384100.net/Y96rBJ
    Python:
    - UMichigan Python for Everybody: imp.i384100.net/QOLM73
    - Python Mastery from MLNOW.ai: mlnow.ai/course-material/python/
    - Google IT Automation w/ Python: imp.i384100.net/5g6Xyj
    Web Dev / Full Stack:
    - Meta Front-End Developer: imp.i384100.net/q4Jemy
    - IBM Full Stack Developer: imp.i384100.net/Gj9dMn
    - Meta Back-End Developer: imp.i384100.net/xkW0r5
    - John Hopkins HTML, CSS & JS: imp.i384100.net/QyoRAA
    - IBM DevOps: imp.i384100.net/kjd2r0
    Cloud Development:
    - AWS Fundamentals: imp.i384100.net/anqBjZ
    - GCP Cloud Engineer: imp.i384100.net/g1jvqB
    - Microsoft Azure Fundamentals: imp.i384100.net/EKm5O4
    Game Development:
    - Michigan State Unity Development: imp.i384100.net/6eOBnr
    - UColorado C++ for Unreal Engine: www.coursera.org/specializati...
    SQL & Data Science:
    - SQL by MLNOW.ai: mlnow.ai/course-material/sql/
    - Python for Data Science by MLNOW.ai: mlnow.ai/course-material/data...
    - Google Data Analytics: imp.i384100.net/1rkWAR
    - IBM Data Science: imp.i384100.net/P0ZRL6
    - IBM Data Engineer: imp.i384100.net/4PbZyZ
    Machine Learning & AI:
    - ML Mastery at MLNOW.ai: mlnow.ai/course-material/ml/
    - ML w/ Andrew Ng: www.coursera.org/specializati...
    - Deep Learning w/ Andrew Ng: imp.i384100.net/a1kjJj

Komentáře • 21

  • @GregHogg
    @GregHogg  Před dnem

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

  • @SHIHJUIheh
    @SHIHJUIheh Před 12 dny +1

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

  • @chisomedoka5651
    @chisomedoka5651 Před měsícem

    this is gold, so intuitive . Thanks for this

  • @shubhambajaj4939
    @shubhambajaj4939 Před dnem

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

  • @FZRides
    @FZRides Před měsícem +1

    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.

  • @sampjm1898
    @sampjm1898 Před 2 měsíci +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  Před 2 měsíci

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

    • @supremoluminary
      @supremoluminary Před 2 měsíci

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

  • @olaf9063
    @olaf9063 Před měsícem +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 Před měsícem

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

  • @user-hu9nu8xu5g
    @user-hu9nu8xu5g Před 15 dny

    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

  • @m.y.7230
    @m.y.7230 Před 17 dny

    thanks for explaning dfs in drawing

  • @maskedoni3229
    @maskedoni3229 Před 3 měsíci

    Great solution

  • @user-hu9nu8xu5g
    @user-hu9nu8xu5g Před 15 dny

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

  • @anti-dn541
    @anti-dn541 Před 2 měsíci +1

    Easy to understand for noob like me 👍🏻

    • @GregHogg
      @GregHogg  Před 2 měsíci

      Oh that's so great to hear 😊

  • @Antinormanisto
    @Antinormanisto Před 2 měsíci

    I don't understand(

    • @GregHogg
      @GregHogg  Před 2 měsíci

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