Reverse a Linked List: Recursive | Java

แชร์
ฝัง
  • เผยแพร่เมื่อ 7 ก.ย. 2024
  • Covers how to reverse a linked list using a recursive approach. Code in Java!
    Checkpoints:
    0:11 -- Concept Review (explaining the problem)
    2:30 -- Implementation (the code & reasoning behind it)
    13:30 -- Try it out on an example! (testing out our code)
    Notes for watchers:
    The signature for the Try It Out code implementation should be 'public Node reverse(Node curr)'. Sorry for the error!
    == Learn More! ==
    Iterative Solution:
    • Reverse a Linked List:...

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

  • @adamguida5910
    @adamguida5910 5 ปีที่แล้ว +14

    Really exceptional explanation. I'm not sure I've ever seen a better breakdown of the problem.

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

    Love that "Try It Out" part!!!!! extremely useful!!! I was eager to now how exactly the recursive program runs and those pointers are too much to keep tracking.

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

    Looked up several videos but was still confused until I watched yours, really helped me out of the day, thank you!☺

  • @bik8353
    @bik8353 5 ปีที่แล้ว

    many people have the skill but very few can teach it. You sir, are rare.

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

    Thank you so much!!!! Your explanation was the only one I understood out of all including my prof's lol.

  • @spartacusche
    @spartacusche 4 ปีที่แล้ว

    best explanation, the only one who mastered the recursive call explanation

  • @shahnawazhussain5538
    @shahnawazhussain5538 4 ปีที่แล้ว +1

    I have been looking for this explanation all over the internet and you were my savior. Could't get a better explanation. Subscribing to your channel.Looking forward to similar awesome content.

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

    Thanks for sharing this!
    This is the best explanation I've ever seen.

  • @atakan347
    @atakan347 4 ปีที่แล้ว

    Best explanation i’ve seen so far. The last solution of recursive calls made even more easier to understand it. Thanks for your effort

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

    This is great. You'd help a lot of people by creating more videos again for the channel!

  • @arfeenmalik8331
    @arfeenmalik8331 4 ปีที่แล้ว

    Best explanation I've come across for reversing a singly linked list. Thanks !

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

    Thanks, this was the best recursive explanation. Took me a while to find it!

  • @kedarnadkarni4627
    @kedarnadkarni4627 5 ปีที่แล้ว +1

    This is the best Explanation so far. Hatsoff Keep up the good work !

  • @alinawei7010
    @alinawei7010 4 ปีที่แล้ว +1

    your explanation is so clear, so good! please make more video (probably leetcode, so we can practice too)

  • @MrZZooh
    @MrZZooh 4 ปีที่แล้ว

    Amazing explanation. Recursion is a little beyond me but I can appreciate it. I liked and understood the iterative way better.

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

    Thank you for this wonderful explanation! I think it is really helpful to use some examples to explain recursion to beginners 'cause it's really generating some confusion. Now I'm clearer about it!

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

    This was very helpful to me!! I did this with Ruby and it worked!! thanks for uploading this video ;)😁

  • @jonmarkortiz
    @jonmarkortiz 5 ปีที่แล้ว

    Excellent, I only wish you had more whiteboard space. Toward the end things start to get to jumbled when you are reconnecting your nodes back. Again, excellent. You deserve a larger whiteboard.

  • @zmanneverdie
    @zmanneverdie 5 ปีที่แล้ว +1

    Very nice explanation! Thanks! Hope you can do more videos like this!

  • @vasupatel635
    @vasupatel635 4 ปีที่แล้ว +1

    Amazing men. you are eloborating problem such a great way.

  • @selvaganesan93
    @selvaganesan93 4 ปีที่แล้ว

    Liked your explanation about recursion. Awesome

  • @yugsoni2603
    @yugsoni2603 4 ปีที่แล้ว

    thank you so much this is the best explanation of recursive solution.

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

    Amazing explanation. Thanks a lot.

  • @anonymousvevo8697
    @anonymousvevo8697 4 ปีที่แล้ว

    really , the best explanation ever

  • @IvanyhwuWu
    @IvanyhwuWu 6 ปีที่แล้ว

    i like the way you explain it! it's much easier to understand! thank!

  • @ahmadsalah115
    @ahmadsalah115 5 ปีที่แล้ว +1

    Thank you very very much, you are a great Person

  • @okachobe1
    @okachobe1 6 ปีที่แล้ว

    The best explanation I've seen

  • @aravindhsaairavichandran8404
    @aravindhsaairavichandran8404 4 ปีที่แล้ว

    Beautiful explanation

  • @sabelozwane6917
    @sabelozwane6917 6 ปีที่แล้ว

    Such a nice and clear explanation. Thanks!

  • @priyam_1007
    @priyam_1007 4 ปีที่แล้ว +1

    Love you brother

  • @maggiexu1780
    @maggiexu1780 6 ปีที่แล้ว

    very clear and easy to understand!

  • @akshaybhoendie
    @akshaybhoendie 7 ปีที่แล้ว +1

    Very well explained friend! cheers!

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

    Beautifully done!

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

    i used this code but the last lane of code dose not work for me > i checked with debug and their next is still null so my output will be like -> input :(f, l, o, w)
    output:(f, )
    can u help me to solve this problem

  • @piyushsharma1638
    @piyushsharma1638 4 ปีที่แล้ว

    This is a pro explanation.nice

  • @TheCCBoi
    @TheCCBoi 5 ปีที่แล้ว

    Amazing video, I wish you would make more!

  • @prashantsishodhiya4412
    @prashantsishodhiya4412 5 ปีที่แล้ว +1

    Thanks allot for the awesome explanation 😃

  • @CodyCoding
    @CodyCoding 6 ปีที่แล้ว +1

    awesome explanation! thanks a ton :D

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

    thank you so much!!!

  • @anonymousvevo8697
    @anonymousvevo8697 4 ปีที่แล้ว

    Thanks a lot mate

  • @ravikrishna5204
    @ravikrishna5204 6 ปีที่แล้ว

    very well explained. Thanks so much

  • @leejohn6055
    @leejohn6055 5 ปีที่แล้ว

    Very Detailed!!

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

    Brilliant

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

    Just before you return rest, you have : "nextNode.next = curr " . I would have thought it would be rest.next = curr; (which does not work). can you explain how you came up with "nextNode.next = curr " instead of "rest.next = curr"

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

      Note that "rest.next" will point to the 2nd node in the reversed remainder of a list (this reversed remainder of the list begins at the last node in the original input list, and ends at "nextNode". To fully reverse the list, we need to incorporate "curr" into the fully reversed list. So we do "nextNode.next" = curr to append it to the end of the reversed list and make it fully reversed.

  • @zenetto9158
    @zenetto9158 5 ปีที่แล้ว

    Amazing explanation! Keep it up!

  • @mohammadasad6044
    @mohammadasad6044 5 ปีที่แล้ว +1

    thank you , i love you man.

  • @JoshuaDueck
    @JoshuaDueck 5 ปีที่แล้ว

    I doubt I'll get a response before the assignment is due, but I keep getting a nullpointerexception when I try using this method. I have copied it exactly as you've said (not to copy your work, just to better see how it works), the only difference is that I have getLink() and setLink() methods. Any clue as to why this may be happening?

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

    what is the time complexity?

  • @faezehdehghan5128
    @faezehdehghan5128 4 ปีที่แล้ว

    Thank youuuuuuuu......that was amazing.....short but very useful.......kiss:)

  • @jiamingchen7467
    @jiamingchen7467 6 ปีที่แล้ว

    Should the "return rest" be outside of the "else" bucket ?

  • @tmosestdev
    @tmosestdev 5 ปีที่แล้ว

    One thing to note is that you don't really need the else if and the else statement. Is that something you did to increase readability?

    • @chill_cs4627
      @chill_cs4627  5 ปีที่แล้ว

      Yup, you're right that we don't need the else statement (we need the logic, but don't need to wrap it in an else-clause)! However, we do need the else-if statement, in the case of our input being a single-node linked list (can you see why?). Having looked through some implementations of this algorithm, I've noticed some of them combine the if and else-if statements to just return 'curr'. In this case, I just left the if/else-if/else in to more clearly show the different cases.

    • @tmosestdev
      @tmosestdev 5 ปีที่แล้ว

      @@chill_cs4627 Cool thanks for the reply and the great video!

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

    tnx ♥

  • @binoysubhakumar9955
    @binoysubhakumar9955 6 ปีที่แล้ว

    Nailed it!

  • @jeanleconteii
    @jeanleconteii 7 ปีที่แล้ว

    Thank you!

  • @mdiftekhar8407
    @mdiftekhar8407 5 ปีที่แล้ว

    Gud explained

  • @harshipandey1977
    @harshipandey1977 6 ปีที่แล้ว

    complete code:goo.gl/wbdSux

  • @abdallahsafi2542
    @abdallahsafi2542 6 ปีที่แล้ว

    nice done

  • @rayaqin
    @rayaqin 4 ปีที่แล้ว

    neat

  • @balajig4684
    @balajig4684 7 ปีที่แล้ว

    super!

  • @rydmerlin
    @rydmerlin ปีที่แล้ว

    You don’t need else when you returning before it.

  • @pinghsu520
    @pinghsu520 7 ปีที่แล้ว

    nice

  • @tianyangren
    @tianyangren 6 ปีที่แล้ว

    tkx!

  • @ianchui
    @ianchui 6 ปีที่แล้ว

    subbbbbbbed

  • @anonymousvevo8697
    @anonymousvevo8697 4 ปีที่แล้ว

    thank you so much , why don't you male videos anymore ?

  • @ShubhamKumar-fn9cl
    @ShubhamKumar-fn9cl 3 ปีที่แล้ว

    lol