accha explanation tha bs thoda code dry run kr k batate tho zyada accha hota
@akshaykumar192 Жыл бұрын
Kahe ka acha kuch samaj ni aata 😢
@achabacha3809 Жыл бұрын
@@akshaykumar192 😅😅😅😅
@mrpandey73122 жыл бұрын
thanks to all who created this free of cost course
@tywarinabin2 жыл бұрын
It is difficult topic but this lecture of 15 minutes make it easier and make program just in 10 minutes. Thanks Apna College Team and Aman bhaiya.
@turbo4free6312 жыл бұрын
is this course for beginner.....
@amritpoudel69292 жыл бұрын
@@turbo4free631 NO BIG NO
@sleepypanda71722 жыл бұрын
her voice!!! too sweet! Great explanation!
@BEESaiShivam3 жыл бұрын
87k views and only 2.5k likes shows that this series is not for beginners but for who already know the basics!!!!
@shishirshekhar3 жыл бұрын
yes
@IFYatharthAurangpureIT Жыл бұрын
very correct
@Lack_Of_Enemies5 ай бұрын
bhai lekin sorting to beginner stuff h
@BEESaiShivam5 ай бұрын
@@Lack_Of_Enemies rhne do bhai ab fms me pdta hu cat 99.5% lol maa chudaye coding
@eros40822 жыл бұрын
Code is giving undesired output if array elements are other than descending order. I have checked many testcases.
@vindhyakumar3434 Жыл бұрын
bro after seeing your comment i realised the same mistake i made , maybe in int main you forgot to put mergesort(arr,0,length-1) and instead wrote mergesort(arr,0,length)
@prabhatjha25223 ай бұрын
@@vindhyakumar3434 then also It didn't work
@nithinshukla46793 жыл бұрын
fr i couldnt understand anything after didi stopped teaching😂🤣🤣🤣
@AbdUllah-m2j3j8 ай бұрын
Only one of you can teach me correctly so proud you
@sajankumarkar82373 жыл бұрын
Just another way to merge. We can take a single array of size n instead of 2 of n1 and n2. What we do is we divide the original array by marking them with the pointers i,j(not the * pointers xD). We merge and store them in the temp array and at the end we store the values in the original array. void merge1(int a[], int l, int mid, int h)// low, mid, high { int i=l, j=mid+1, k=0, n=h-l+1; int temp[n]; while(i
@adityagupta38703 жыл бұрын
brother....can you explain me why the size of " n1=mid-l+1" array is taken? and in your problem also n=h-l+1?..please help I am confused
@sajankumarkar82373 жыл бұрын
@@adityagupta3870 ok let's say the array we take has size 10. While calling the function the value passed to low is 0 and the value passed to high is n-1(cuz if size 10 means from 0 to 9), i.e. 9 in this case. Now in the function, n denotes the size of our array(specifically size of the part of the array corresponding to the merge but here i will explain for the entire array cuz its easier to understand that way). So n needs to be 10. now low=0 and high=9, so high-low=9-0=9. So we add 1. High-low+1=9-0+1=10.
@adityagupta38703 жыл бұрын
@@sajankumarkar8237 damn bro!!!.. Thanks!!!... Can I have your id or something ... So that we can start with dsa together?
@rutvikrana5124 жыл бұрын
Mergesort vs quicksort Quicksort will give average time complexity of O(N*log(N)) and worst case O(N*N) But mergesort gives best case as well as average case complexity O(n *log(n)) It means mergesort will not take less than this time but in average case it will be n log(n)... so if your array is small, you will still need this much time, but qsort is much faster for smaller size array because it can take O(N) in sorted array while mergesort will take n log(n) for this. So quicksort is faster than mergesort. So why use mergesort ? It is used to know inversion count. Qsort :- Fast and used in small arrays Mergesort :- stable and used for big arrays and linked list.
@veeresh44414 жыл бұрын
Could u tell what is inversion count ?
@rutvikrana5124 жыл бұрын
@@veeresh4441 ... inversion count is numbers of swaps needed to sort an array. We can easily count swaps in bubble sort also. But if we need less time complexity than we can use merge sort algorithm.
@abhigujjar74394 жыл бұрын
Not average, quicksort bestcase is O(nlogn)
@rutvikrana5124 жыл бұрын
@@abhigujjar7439 ... yes and no. It’s about practical results. In practice, average time of qsort is less than mergesort. Read in a book, I didn’t practice myself though 😂
@abhigujjar74394 жыл бұрын
According to books the average and best case for quick sort is O(nlogn)
@Annu_Chaudhary2004 Жыл бұрын
Best m best ma'am 10 marks sure ho gye isse pdh kr thanks 🙏👍
@AmanTheDisciple2 жыл бұрын
Awesome video, thanks for the easy explanation! :)
@WinaTechnologies5 ай бұрын
it was a verry good video, yet , consider using meaningfull variable names , i mean a[i] = arr[l + i] seems confusing isnt it ? avoid using variable names like a and b instead use for example left_array and right_array or whatever the key point is using meaningfull variable names , otherwise i see the explanation was just clear thank you so much ❤❤❤
@code-a-mania41002 жыл бұрын
For Time comple. We get fractional part and n so it is simple it is logn*n
@pritishpattnaik46744 жыл бұрын
instead of using 2 more while loops in merge( ) , u can simply just change the && with || , so..we do not need those extra while loops.
@sourabhchoudhary72893 жыл бұрын
I also thought so does it worked??
@amanns70803 жыл бұрын
No it won't work, might give a segmentation fault/ wrong answer as you are accessing element of an array outside its bounds. Suppose, i has reached n1 but j hasn't reached n2, by replacing "and" with "or" in while loop, you would still enter the loop, but this time you would be checking a[n1] with b[j], a[n1] might contain garbage value. Same case if j reaches n2 first, b[n2] contains garbage value. Hope this clears your doubt.
@shreyasingh46802 жыл бұрын
no we can't do that because we would have 0 element in either array so we can't compare
@maheriyajatinbharatbhai35383 жыл бұрын
thanks for this amazing playlist!
@anujjadhav27713 жыл бұрын
I am in love with this series ❤
@artirani38064 жыл бұрын
It's special for me because it is on Apna College Video.....first time ever😇1 comment, 1st like😄
@ankurmishra11754 жыл бұрын
kzbin.info/www/bejne/aJyaoYZvrLyDiqs
@shubhamkale7353 жыл бұрын
Documentation of our program is very important thing because it reminds us the logic behind program make sure everyone will write reason after each code using commenting
@joebale96702 жыл бұрын
ji sir jaisa aap kahen😶
@subratadas84083 жыл бұрын
Explained well thanks .
@samridhisaini61472 жыл бұрын
explanation is just so clear
@maazahmed6634 Жыл бұрын
Microsoft Wali didi is helping Pakistanis as well❤️
@ashishbohare88642 жыл бұрын
Love u didi 😘 bdiya pdhaya
@shaktirajsinhzala45884 жыл бұрын
merge is done with only one extra array. it is not necessary to take 2 extra arrays and then merge.
@nikunjjain23824 жыл бұрын
Yes ,by using two pointer
@sourabhchoudhary72893 жыл бұрын
we are using two arrays of size n1 and n2 that is n1+n2=n. so basically we are using O(n) extra space that is equal to one array of size n.
@MohammadKhan-ld1xt3 жыл бұрын
how?
@yashvats8242 жыл бұрын
@@MohammadKhan-ld1xt #include using namespace std; void merge(int a[],int s,int m,int e) { int temp[e-s+1]; int p1=s; int p2=m+1; for (int i=0;im) { temp[i]=a[p2]; p2++; } else if (p2>e) { temp[i]=a[p1]; p1++; } else if (a[p1]>n; int arr[n]; for (int i=0;i>arr[i]; merge_sort(arr,0,n-1); for (int i=0;i
@rohandhale9766 Жыл бұрын
Best explaination Of Logic And TimeComplexity
@leenagupta78013 жыл бұрын
wow... Nicely explain....
@subratakundu7323 жыл бұрын
Thanks didi for good explanation with less time.
@sjr20013 жыл бұрын
In the int main func when we write mergesort func then copy of arr should be sent . Then how does the sorted array got print by for loop not original array ???
@aayushsharma51333 жыл бұрын
Super animation🔥🔥
@sakshidurve12113 жыл бұрын
merge function is not only to to merge 2 arrays, its is also to sort and merge
@sohammukherjee_21933 жыл бұрын
But in which portion is the sorting occuring???
@cswd428-yaswanth33 жыл бұрын
@@sohammukherjee_2193 in the merge fn
@UIEC_MANESH_RAM-tb1hb3 жыл бұрын
your absolutely right and maybe didi missed it
@AmanKumar-nb4oh2 жыл бұрын
Yeah u can say like that while merging we sort them first
@Special_moment_ Жыл бұрын
very good explanation . I really enjoyed.
@technicalknowledge90803 жыл бұрын
Bhaiya this code is working correctly only for the input (5,4,3,2,1) while we are changing this input then this code is not giving the correct output so please look into this matter. and please highlight this comment so that bhaiya can read this comment Thank you
@rishankbhatnagar65603 жыл бұрын
mera bhi output nahi aa raha hai
@divyangbhamat12283 жыл бұрын
Yes same problem anyone found solution so please help
@sohammukherjee_21933 жыл бұрын
Bro which part sorts the arrays of size n1 and n2???
@irshadali-xx1ms3 жыл бұрын
#include #include using namespace std; void merge(int arr[],int l,int mid,int r) { int n1=mid-l+1; int n2=r-mid; int a[n1]; int b[n2]; for (int i = 0; i < n1; i++){ a[i]=arr[l+i]; } for ( int i = 0; i < n2; i++){ b[i]=arr[mid+1+i]; } int i=0; int j=0; int k=l; while (i
@technicalknowledge90803 жыл бұрын
@@irshadali-xx1ms thank you bhai 😀😀
@abdulkareemabid21323 жыл бұрын
kal exam hai aur bahi kasam se iss se jayada madad mujhe kine nahi ke thanks a lot sis
@harshal.rathore3 жыл бұрын
there could be a much better explanation the animation didn't help much in understanding the flow of whole code
@sambhavgandhi65533 жыл бұрын
true
@shahriar55704 ай бұрын
Give me a video link if you found a better explanation for the code.. I actually need it
@mallikarjunpidaparthi4 жыл бұрын
Excellent and clear explanation. Thank you.
@pankaj.yadav13 жыл бұрын
Ma'am bhut axa smjhati h
@aswinbarath4 жыл бұрын
🔥🔥🔥Verithanam🔥🔥🔥
@harshitnema41973 жыл бұрын
For those who are having doubt in line of code where: n1 = mid-l+1; see initially we have given l = 0, r = 7 in the array of length 8. then we will get mid = (l+r)/2 as (7+0)/2 = 3; so n1 = mid - l +1; will be 3 - 0 + 1 = 4;
@harshitnemaa3 жыл бұрын
If you guys have any doubt you can reply to this comment.
@shubhammahakal18172 жыл бұрын
Here, mid is pointer and n1 is length from 0 to 3 (0,1,2,3)
@anantsinghal31804 жыл бұрын
Please upload web development course...🙏🏻🙏🏻
@nikunjjain52124 жыл бұрын
@Nikunj Manhas thanks Nikunj 😂
@Tenohekabanzai3 жыл бұрын
if this programme was Apple, Neha maam would be Siri We want Neha maam in all videos :) :) :)
@PulkitMalhotra4 жыл бұрын
1no. Content 🔥
@khuramkhalid539611 ай бұрын
THANK YOU SO MUCH!!
@mdminhaj85673 жыл бұрын
Thank you so much sister for your informative speech.
@faizansaqeeb33903 жыл бұрын
Amazing👍😍🤩
@tarun-prakash2 жыл бұрын
AMAZING ROCKET SCIENCE
@avijitdey69982 жыл бұрын
Great explanation maam, it's clear all of my doubts
@dhobi-the-tiger-692 жыл бұрын
Love dey. 🤡
@vaibhav74535 ай бұрын
Take input from user
@govindjangra6002 жыл бұрын
can anyone tell the problem that i faced in running the same code in the video my output is 5 2 5 5 5
@nishantyadav74613 жыл бұрын
Aman bhaiya ❤️❤️❤️❤️❤️❤️ I want to know the concept of Int**arr =new*arr
@vrajeshmodi49283 жыл бұрын
if you want to pass 2D array in any function you have to assign int** arr /*pointer*/ = new *[n] /* your main arr of size n */;
@subhammishra3163 жыл бұрын
@@vrajeshmodi4928 thanx bro
@yogendrarajput59292 жыл бұрын
Test Cases Not included-- Code is Below---> void merge(int input[], int low, int mid, int high){ int b[high-low+1]; int l1=low,l2=mid+1,i=0; while(l1
@krishnaanasurya3549 Жыл бұрын
Thx for Desi explanation , Ghusenge ghusenge...
@anuragtyagi11113 жыл бұрын
When God come to help poor students ❤️
@lakshtrivedi0044 жыл бұрын
Can we get backtracking part 2?
@cmcatholic17983 жыл бұрын
Mergesort() function seems bit odd for me, since there is no returning statement🤔. I think it should return 0 at end
@zubinshah45893 жыл бұрын
its a void function bro
@praveenawesome21823 жыл бұрын
well yes but actually no !! Firstly mergesort is a void function so it should not return anything but let's say if it wasn't a void function and something happened in the function but it doesn't return anything,in that case, no one knows for sure what will happen. The program may or may not run i.e it can result in a crash so to avoid that situation we always have return statements even after giving a return in a conditional statement inside a function.
@praveenawesome21823 жыл бұрын
ps: I am not sure if the above claim made by me is totally correct and maybe there is good logic behind it, suggestions will be appreciated.
@gauravupreti93403 жыл бұрын
there are two ways in which a function frame can be destroyed, either if return statement is encountered or if nothing is left in function. Try to think with a stack diagram. Hope it will help.
@harshdeep73123 жыл бұрын
@@praveenawesome2182 definitely u r correct i encounter many time no output wthout return statement bt after return statement program gives correct output
@zackcarl78612 жыл бұрын
What does( mid-l+1 ) mean how can I substrate l from mid
@himanshuwarkade43182 жыл бұрын
As l always starts from 0. Suppose the value of Mid is 3 so "3-0+1" is equal to 4 which should be the size of first part of the array.
@priyanshuhazarika99683 жыл бұрын
A smaller function is below. merge function is reduced void merge(int arr[], int l, int mid, int r) { int n1 = mid - l + 1; int n2 = r - mid; // different from video --> one extra element int a[n1 + 1]; int b[n2 + 1]; //maximize the extra element a[n1]=INT_MAX; b[n2]=INT_MAX; for (int i = 0; i < n1; i++) { a[i] = arr[l + i]; } for (int i = 0; i < n2; i++) { b[i] = arr[mid + 1 + i]; } int i = 0; int j = 0; int k = l; // different from video --> using or ( || ) while (i < n1 || j < n2) { if (a[i] < b[j]) { arr[k] = a[i]; k++; i++; } else { arr[k] = b[j]; k++; j++; } } }
@zackcarl78612 жыл бұрын
What is array size (mid-l+1)
@amitkumarlkr2 жыл бұрын
Int arr ko apne void function me kaise change kar diya array ka to sirf value jata hai nai dusre function me ????
@rohitsaini74273 жыл бұрын
Isn't the L pointer going to be zero and in what case it will be non zero?
@coder90093 жыл бұрын
Thanks a lot for this video
@ishitabisaria64374 жыл бұрын
Sir notes of this lecture??
@AG-kw1rb4 жыл бұрын
Bhaiya Please upload the NOTES OF LECTURE 31 - Strings in c++
@aadityasharma68553 жыл бұрын
Its 13
@AG-kw1rb3 жыл бұрын
@@aadityasharma6855 Its Lecture 31
@AG-kw1rb3 жыл бұрын
@@saimadhumita2144 yeah
@AG-kw1rb3 жыл бұрын
Thank you Aman Bhaiya and Apna College team as now the Notes of Stings in C++ are uploaded
@jyothishkamal82553 жыл бұрын
Suggestion: please use comments to explain what the variables are
@kimjongun22174 жыл бұрын
Thumbnail dek k hi samj aa gya🔥🔥🔥
@felizmonk53832 жыл бұрын
Don't we have to take dynamic temp array in merge function. Why didn't you get errors?
@VishalGupta-oh7mb2 жыл бұрын
space complexity ne allow kr dia On ko isl;ie
@virendraverma585510 ай бұрын
Function Mergesort how it working samajh nahi aaya
@vatsalpoddar66602 жыл бұрын
In the Merge function, why did we initialize k with L and not 0
@derekflix3 жыл бұрын
Kyo karna hai merge sort jab hum pehle hi Selection Sort, Bubble Sort aur Insertion Sort padh chuke hai ????
@mansoorahmad57743 жыл бұрын
Due to time Complexity. Most efficient sorting technique as compared to others.
@vibhashkumar55544 жыл бұрын
Only legends know video length is 17:10 ,before the video premiere
@niladriroy16654 жыл бұрын
Kaise bata rha hai bhai tu?
@mohammadejaz5404 жыл бұрын
Kaise?
@II_xD_II4 жыл бұрын
define "legend"
@neerajkrishnan85744 жыл бұрын
@@II_xD_II map ke icons ko identify krne waaala chart lol
@imranimmu47143 жыл бұрын
expecting better explanation for time complexity
@ambujsharma764225 күн бұрын
Could you please explain merge sort example with ecmascript 6
@AkashKumar-lg5po3 жыл бұрын
You beat Abdul Bari explanation . Wowwwww
@RudranshSharma3 жыл бұрын
Backtracking ke baad toh kuch samajh nhi aa raha!! What to do?? Ek baar poora course dekhlu aur uske baad phirse dekh lunga..... Yaa fir abhi poora concept clear karte huye chalu?
@strokeadda013 жыл бұрын
Bhai clear krta chal abhi se wrna pura dekhne tkk itna frustrate ho jaega ki kr nhi paega🤐
@thetypicalone25253 жыл бұрын
Sorry ur eplanation was right ,😙😙😙😙😙😅😅😅👍👍👍👌I was doing in the wrong way
@rexstark53193 жыл бұрын
Why do u not get errors, even if u declare size of arrays as variables at runtime
@paramrajsinghchadha19573 жыл бұрын
varies from compiler to compiler
@dibyarupnath3 жыл бұрын
you need to declare and take input the variable, which you use as the size of the array, while declaring the array.
@rishabarya13792 жыл бұрын
THEY SKIP TO THE PART WHEN CODE IS RIGHT YOU CAN SEE IT FOR YOURSELF EXAMPLE THE VEDI THEY TYPE "mergeSort(arr,0,4);" BUT AFTER EXECUTION WHEN YOU CAREFULLY LOOK IT IS SUPPOSED TO BE " mergeSort(arr,0,5);"
@twodimensions4592 жыл бұрын
This code is not fully optimized.. it is showing time limit exceeded
@dhairyashah58863 жыл бұрын
classic video!!!!!
@chanduchandrakanth51313 жыл бұрын
Is mergesort sort itself
@vinayakjalan56964 жыл бұрын
Didi iss lecture ke notes add kardo description box main .. Woh blank reh gaya hh
@alpha183_i9 ай бұрын
Thank you mam
@kartikey143 жыл бұрын
aced it...!!❤
@SobhitPanda3 жыл бұрын
Sir, time complexity nahi samjh aai? Please elaborate, the procedure. Or please suggest some materials to practice from.
@sachinbairi63533 жыл бұрын
Are voh keh raha hai ki humne pehele n length ki array ko divide kiya half mai toh hum abb left array ko sort karne ko humko t(n/2)time lagega some for the right half of that array jab hum dono side ko plus karenge tab yee ayega -->>> i.e. t(n) = t(n/2)+t(n/2) = 2t(n/2) but hum divide karne ke baad merge bhi kar rahe hai toh usko humko merge karne ko linear time lagega i.e 'n' toh final recurrence relartion atta hai ki t(n) = 2 t(n/2) + n ...eq1 yee aaya hai for the first split jo humne kiya n ko n/2 mai but hum mergeSort mai we divide the input list of length n in half successively until there are n lists of size 1. so, if humko left or right half of the array ke liye recurrence relation chahiye toh follow same procedure but iss baar n half hai. replace n by n/2 in the eq 1
@hrithikjaysingpure96233 жыл бұрын
@@sachinbairi6353 thnx bro
@shamshuddinshaikh47743 жыл бұрын
@@sachinbairi6353 tumne toh bade acche se samjhaya bro
@anaskaratela71713 жыл бұрын
any better approach than this while using functions in recursive way??
@deepjyotikoley84993 жыл бұрын
for better time complexity use quick sort
@gourav79213 жыл бұрын
Int n1 = mid - l + 1 Didi ne 8:24 par (mid - l )mein 1 kyo plus Kiya hai agar kisi Ko iska reason pta hai toh pls jrur btana
@puneetfanspage Жыл бұрын
ma you telling the code in right way but you don't understand us the clear topic when you teach us that in merge function that int n1= mid-l+1 you just telll us but you don't cleariy that so please understand this song this is the feed back of all video because you doing same mistake all in this video i'm not blame you i appreciate your experience but please ensure that before teaching that are this topic is really i know and i will teach this with very clearification thanks mam for this code
@Dont_know_wt3 жыл бұрын
Mam u r keep saying pointer.. Is that pointer or index? Bcz pointer should have Asterix(*) sign
@harshitrathi30773 жыл бұрын
Aree Bro Pointer Doesn't Only Means That U have To Take a * Sign , Pointer also Means To Pointing something
@Dont_know_wt3 жыл бұрын
@@harshitrathi3077 acha
@subodhsingh92872 жыл бұрын
when 2 and 8 are merged then we should get 8 and 2 .RIGHT??? but slides shows 2 and 8 at 3:18
@animegod52953 жыл бұрын
why is it showing expression must have a constant value while declaring temp array? pls help somebody
@_rahulsain4 жыл бұрын
animation se time complexity smj aaygi
@mancunianswagger36683 жыл бұрын
It is important for us not gonna lie but this is hard. If it wasn't this important most of us would've skipped this right???
@darshantrivedi53904 жыл бұрын
Thanks 🔥☺️
@bhimashankarhalasage22673 жыл бұрын
Why we passing mid to merge?
@iffattuli86763 жыл бұрын
Thanks! :)
@rivines3 жыл бұрын
Ma'am aap thoda tez bolti to shi rhta
@oqant04243 жыл бұрын
thanx a bunch
@hemant-li1gp Жыл бұрын
in mergeSort function we pass arr of main function by value, then how did this changed the array in main function
@StoryGicRohit3 жыл бұрын
shukriya
@sabyasachidas45722 жыл бұрын
Can you just tell me why n1=mid-l+1??
@patil_ji2 жыл бұрын
getting output only when I give input as same you have given but whenever I change my input array sequence or give a sorted array as input code is not working
@djpro64132 жыл бұрын
mam we have to lesan the synatx of code of n1 and n2 otherwise how this logic is made😡 😡