L9. Reverse a LinkedList | Iterative and Recursive
ฝัง
- เผยแพร่เมื่อ 9 ก.พ. 2025
- Problem Link: tinyurl.com/2a...
Entire LL Sheet: takeuforward.o...
Check our A2Z DSA Course: takeuforward.o...
Please do give us a like, and subscribe to us if you are new to our channel.
Do follow us on our socials: linktr.ee/take...
U r not only teaching linkedlist u r teaching values to give back to this community..
Thankyou Striver
Hands down, the best explanation on TH-cam!
00:10 Iterative Approach
14:39 Recursive Approach
very nice explanation Striver!
Understood!
I was confused until I watched the dry run of recursion... Thanks for having Striver!..
same
Awesome man. The way you tried to portray the recursive one is actually over the moon..
Right actually over the moon 🌝 sir 🙏🏻🙏🏻taught us the beauty of recursion beautifully and factually ❤😇
Was a bit confused regarding recursive approach of this problem for a while. Your explanation just cleared out all of it. Great video!!❤💯
If you are a beginner or even an intermediate this is the best playlist to follow for DSA
Logic are crystal clear with your perfection in explanation , i don't even
need to look code .
All the video lectures and the articles helped me a lot to gain confidence in DSA and will be helping me in the interviews. Thank you Striver bhaiya for bringing such amazing content for free.
recursive approach is explained crystal clear in the documentation article
Exceptional explanation !!! I've never intuitively understood recursive version of reversing a LinkedList, but this video helped me understand that too so easily🙇🙇
recursive approach of soving linked list is awesome non of any youtuber has explained it such fantastically
I am amazed by the recursive solution and loved the dry run...thank you so much!!!! :)
The dry run part is genius!! very nice explanation.
so beautiful so elegant just looking like a wow
explanation of the recursive approach was just exceptional .
thankyouu striver
Recursion approach is just LIT , bhai kamal kr diya striver bhai
Great explanation!!! The best i've ever seen on recursion !
Kudos from the entire community for such beautiful explanation.
Crystal clear !!! Thanks for explaining the recursion topic soo beautifully and making it easier to understand. ❤
Your DryRun thing in these recursion approaches is amazing
Brooo u are crazyyyy that dry run is the best i have seen thank you understood
Amazing explanation at recursive approach thank you striver for this amazing course😊🎉
The recursion code is always a delight to understand , coz you think that how could be solved soo elegantly
thankyou , tried to understand the recursive approach from everywhere before this since last night , finally understood
BEST VIDEO ON TH-cam SEEN ALL
Lecture successfully completed on 27/11/2024 🔥🔥
did u complete whole linked list playlist?
Is it me or anyone else also thinks that things have been a little tougher from Linked List
I think it's you only.
No man. I've given up on Linked last multiple times to reach this far (not even half).
@@vibhavsharma2724 🙂
Just you buddy
Thank you for putting so much hardwork!
Finally I understood this recursive concept.........Nice Explanation👍👍
bhaiyya thank u so much for this explanation tomorrow i have ds end sem exam and still this video helped me a lot . thank u so much.
Dry run part was actually brilliant
Amazingly explained, #Striver rocks, gold bless you & all
Loved the explanation for recursive solution, especially the DRY RUN
i love youuuu u r thee besttttt teacherrrrrrrr EVERRRRRRRRRRRRR
Broo your way of explaining is awesom👍👍
The way he explains sounds like Arnab Goswami highlighting the news ! 😂
Awesome and hats off 🙏🙏
thank you so much Striver.
greatest video superb sir !!
thank you man tanks for clarifying the recursion from scratch
0:00 -4:58 = Brute Force (Using Stack)
5:00 - 14:45 = Iterative
14:50 = Recursive
UNDERSTOOD, Thank You So Much for this wonderful video...........🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
Beautifully explained
head->next in recursive call is the head for base condition..so the function returns last node after head->next recursive call for the second last node is called.
I was very confused with this recursive method, how does it reverse. It is super clear after watching your video !
Excellent work. Thank you so much!!!
understood very much
thank you sir
Good Approach!
dry run was awesome
Simply the best!!!
best explanation ever!
Thanks a ton Striver
.
you are a genius
Thanks for that dry run approach
Awesome Explanation!
Even more concise:
function reverseList(head, prev=null){
if(head === null) return prev;
const next = head.next;
head.next = prev;
return reverseList(head.next, head);
}
12/22/2024 _Good Explanation Striver bhaiya ❤
Just Brilliant ❤
Wow great explanation
best explanation ever
Very well explained. Thanks
understood , best part was dry run of recursive code
Awesome teaching
excellent explanation was just fabbb
in the recursive code instead of assigning head->next as front everytime and then operating on front to point it to head we can do a simple more approach with just 2 lines. we can directly tell head's next pointer to point towards head and at last tell head to point towards null. easy peasy just 2 line code. Here is the code-
ListNode* reverse(ListNode* head){
if(head==nullptr || head->next==nullptr){
return head;
}
ListNode* newhead= reverse(head->next);
head->next->next = head; // Point the next node's next to the current node
head->next = nullptr;
return newhead;
}
will anyone tell me whats the benefit of learning recursive solution if its time complexity is still same as the simple method in which we were changing the links?
Superb!
Best video explanation
NICE LECTURE AND PLZ UPLOAD REMAINING LECTURES OF A TO Z SDA SHEET PLZ THEY ARE VERY HELPFULL FOR US
Amazing explanation
Great video
got it soo well❤
dry run makes the explanation clear.
t1 = head; // Initialize t1 to point to the head
t3 = NULL; // Initialize t3 as NULL (previous pointer)
t4 = t1->next; // Initialize t4 to the second node in the list
t2 = NULL; // Initialize t2 as NULL
int c = 1; // Start with c = 1
while (t4 != NULL) {
if (c == 1) {
c--; // Decrement c
t2 = t1; // Set t2 to point to t1
t4 = t2->next; // Move t4 to the next node
t1->next = t3; // Reverse the link for t1
t3 = t2; // Move t3 forward to t2
} else {
c++; // Increment c
t3 = t4->next; // Store the next node of t4 in t3
t1 = t4; // Move t1 forward to t4
t4->next = t2; // Reverse the link for t4
t2 = t1; // Move t2 forward to t1
t4 = t3; // Move t4 forward to the next node
}
}
head = t1; // Update head to the new first node after reversal
this might be a complex alternative , was for me when i deduced for the first time ;) and little bit of confusion removal by GPT my friend in need
using swapping the pointers and accessing their respected node's next for reversing the linked list
Recursive approach: 14:50
thanks for this explanation
Amazing !!!
what a man 👏👏
Striver i'm solving A2Z course and i'm at the strings but there is no video explanation for them. i searched videos on youtube but one explains in detail and clear like you. So can you PLEASE make videos on that topic(i will wait). Thank You
Same bro
Understood✅🔥🔥
bhaya u r the best
Understood Thanks a lot ❣❣
you are our god . thank you soo much
15:00 Recursion Starts
UNDERSTOOD SIR
the BEST💯
watched 2 times then i understood code flow completely
So Beautiful , So elegant just looking like a WoW
I understood bro...
you are god
bhaiyaa app great ho❤❤❤❤
Love you striver
Understand ❤❤
big fan bhai luv you bhai
Thank you striver😃😃
understood ❤
9:45 Take U Forward
Thanks 🙏 sir
Bro can you push the code ..The way you explain is very interesting to watch and learn the concepts.
thank you man
Thank you bhaiya