bro you can dry run for some input to give a proper understanding to your viewers .. this tutorial is good only for those who just need to revise the concept for someone who is first time seeing this problem this tutorial fails to teach them
your video is really amazing , I'm dealing with linked lists from last 2 days but didn't get the concept of merge sort for linked list . your video helps me to clear my concept .
this was asked in a coding competition in my college so i simply dumped all the linked list content into a vector, sorted the vector and copied the value back into linked list 🤣🤣😛😛
bro understand the video and then try to implement it yourself this will help me understanding the problem more clearly and also for long term it is recommended to implement it yourself
Bro, you are just reading the code. I learned nothing new here. If you want to make better videos then, explain key details like, why we are using pointer of pointer here? and Why we are using merge step recursively? can we do that as non recursive array type merge sort?
Maha bakwaas......what is the point if you are not explaining how the pointers move and arrange while merging back again, Its very easy to say to read the code and telling aisa ho jaega
bro you can dry run for some input to give a proper understanding to your viewers ..
this tutorial is good only for those who just need to revise the concept
for someone who is first time seeing this problem this tutorial fails to teach them
your video is really amazing , I'm dealing with linked lists from last 2 days but didn't get the concept of merge sort for linked list . your video helps me to clear my concept .
Sir, your videos are very very helpful,I had a great trouble in getting my doubts cleared, please continue posting these videos sir
class Solution{
public:
void MergeSorting(Node** head)
{
Node *cur = *head;
Node *first;
Node *second;
if(!cur or !cur->next) return;
FindMiddle(cur, &first, &second);
MergeSorting(&first);
MergeSorting(&second);
*head = MergeBoth(first, second);
}
Node* MergeBoth(Node* first, Node* second)
{
Node* answer= NULL;
if(!first) return second;
else if(!second) return first;
if(first->data data)
{
answer = first;
answer -> next = MergeBoth(first->next, second);
}
else{
answer = second;
answer -> next = MergeBoth(first, second -> next);
}
return answer;
}
void FindMiddle(Node* cur, Node** first, Node **second)
{
Node* fast;
Node* slow;
slow = cur;
fast = cur ->next;
while(fast != NULL){
fast = fast ->next;
if(fast != NULL)
{
slow = slow ->next;
fast = fast -> next;
}
}
*first = cur;
*second = slow -> next;
slow -> next = NULL;
}
//Function to sort the given linked list using Merge Sort.
Node* mergeSort(Node* head) {
// your code here
MergeSorting(&head);
return head;
}
};
class Solution{
public:
void MergeSorting(Node** head)
{
Node *cur = *head;
Node *first;
Node *second;
if(!cur or !cur->next) return;
FindMiddle(cur, &first, &second);
MergeSorting(&first);
MergeSorting(&second);
*head = MergeBoth(first, second);
}
Node* MergeBoth(Node* first, Node* second)
{
Node* answer= NULL;
if(!first) return second;
else if(!second) return first;
if(first->data data)
{
answer = first;
answer -> next = MergeBoth(first->next, second);
}
else{
answer = second;
answer -> next = MergeBoth(first, second -> next);
}
return answer;
}
void FindMiddle(Node* cur, Node** first, Node **second)
{
Node* fast;
Node* slow;
slow = cur;
fast = cur ->next;
while(fast != NULL){
fast = fast ->next;
if(fast != NULL)
{
slow = slow ->next;
fast = fast -> next;
}
}
*first = cur;
*second = slow -> next;
slow -> next = NULL;
}
//Function to sort the given linked list using Merge Sort.
Node* mergeSort(Node* head) {
// your code here
MergeSorting(&head);
return head;
}
};
Thank me later
thanks
can you please make a video on quick sort for linked list
Yes please
You deserve a thumbs up for creating these helpful videos 👍👍👍
this was asked in a coding competition in my college
so i simply dumped all the linked list content into a vector, sorted the vector and copied the value back into linked list 🤣🤣😛😛
Lol😂
but that wont work in o(1) space tho, the point is that u have to do without using any extra space :)
Piro
Inefficient solution
@@adityaagrawal190 here also we are making new node for each node.
Thank you. Very helpful video
Why you have taken fast pointer as head->next ??? In your "mid element in linked list" video you have taken it as head only ???
same doubt
Thank You So Much Yogesh bhaiya for this amazing content......🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻🙏🏻
bro how much time did it take u to finish love Babbar 450 questions.
You are doing an amazing job. Thankyou so much for helping out in these problems
Bhai Love babbar ki poori sheet bana de , sbka bhala ho jayega !!!!!
All the best for accolite internship,macha dena !!!!
I would like to recommend you to share the link for your code too for ease in understanding , this would be really helpful
Try to implement by yourself bro it would be helpful just write the approach and code it
bro understand the video and then try to implement it yourself this will help me understanding the problem more clearly
and also for long term it is recommended to implement it yourself
your videos are really helpful .Thanks for your help!!!
I am having a segmentation fault in this code
Really nice explaination. Can you make a video of quicksort for LinkedList
it's awesome bro help me alot in my Dsa journey
Which software you are using?, May I know pls .
find middle() me curr ko single pointer aur first and second double pointer kyu passkiye?
Thank you. I was struggling with this so much aaarrrggghh!!
Bro, you are just reading the code. I learned nothing new here. If you want to make better videos then, explain key details like, why we are using pointer of pointer here? and Why we are using merge step recursively? can we do that as non recursive array type merge sort?
Bhaiya... Why are we using Node** first .. It should be Node* na??
pass by ref hai node, isliye
i am getting segmentation error due to below code for finding middle element, can someone please point out the mistake?
void FindMiddle(Node *curr, Node **first, Node **second)
{
if (curr == NULL)
{
*first = NULL;
*second = NULL;
return;
}
Node *slow = curr;
Node *fast = curr;
while (fast && fast->next)
{
slow = slow->next;
fast = fast->next->next;
}
*first = curr;
*second = slow->next;
slow->next = NULL;
}
why no one explaining O(1) space comp solution ?
Bhaiya you are amazing... your videos are really helping a lot.... I have a request ...plz put the code in ur description or in the chat box plz
please make video on Quick sort for linked list
why are we using pointer of pointer here? we didn't we just use simple pointer instead?
whose sheet is this?
Where i got the code
thanks!
great explanation!!! and can u share the excel that u have containing all the problem links
link is given in the video description
@@shubhamsonawane967 yeah got it, thnx!
Bhaiya what is use of double pointer that i couldnt understand
double pointer is used for storing address of another pointer
Can you explain why did you use double pointer(** ) in the code? You didn't explain that and I did not get that.
because of call by reference
thankyou so much brother
bhai..wo excel sheet upload karde..net se kisi ne hata diya...abhi pdf hai, but excel nahi hai
TQSM......
ABCD
What about space complexity..
o(1)
bhai apne code ki link bhi share kar diya karo please...
space complexity??
o(1)
Baki sab to accha hai bas ek graphic pad le lo
Why fast is pointed to curr next why not to curr
yess please explain thus why is pointing it to curr gives a segmentation fault
@@Doraemon-em4fy you can do both but inboth cases condition of while loop differs
As in gfg expected space complexity is o(n)
lol
Fir se daily 2 videos kb aayegi 😥😥😥
Aj last exam tha...kal se a jaega😀
Segmentation fault 😭😭😭
me too bro
bhai koi force kr rha hai kya tumhe videos banane ke liye
Bro quick sort for LinkedList please!!
Maha bakwaas......what is the point if you are not explaining how the pointers move and arrange while merging back again,
Its very easy to say to read the code and telling aisa ho jaega
I second you.
this happens when you dont know how to merge two sorted linked list.
he already made video on it
Yeh sare videos konsi language me hai??
C++ language
1st view
source code pls
Bhai Jaldi ye sab khatam karke BST pe aa jao
Yaa we will come....have patience
bas tu short bolna band kar de bhai
solo
Bhai gfg se pura code copy kar k koi bhi samja skta hai
Apna code kudh bhi likha kar kabhi
class Solution{
public:
//Function to sort the given linked list using Merge Sort.
void MergeSorting(Node**head){
Node*cur=*head;
Node*first;
Node*second;
if(!cur || !cur->next) return;
FindMiddle(cur,&first,&second);
MergeSorting(&first);
MergeSorting(&second);
*head=MergeBoth(first,second);
}
void FindMiddle(Node*cur,Node**first,Node**second){
Node*slow;
Node*fast;
slow=cur;
fast=cur->next;
while(fast!=NULL){
fast=fast->next;
if(fast!=NULL){
slow=slow->next;
fast=fast->next;
}
}
*first=cur;
*second=slow->next;
slow->next=NULL;
}
Node*MergeBoth(Node*first,Node*second){
Node*answer=NULL;
if(!first){
return second;
}
else if(!second){
return first;
}
if(first->datadata){
answer=first;
answer->next=MergeBoth(first->next,second);
}
else{
answer=second;
answer->next=MergeBoth(first,second->next);
}
return answer;
}
Node* mergeSort(Node* head) {
// your code here
MergeSorting(&head);
return head;
}
};
can you please make a video on quick sort for linked list