Merge Sort - How it works ? Algorithm + Code
Вставка
- Опубліковано 16 лип 2024
- In this tutorial, Prateek Bhayia takes through an interesting sorting algorithm Merge Sort, which sorts an array in O(nLogn) Time.
Code : codingblocks.com/ide/#/s/3832
Like our FaceBook Page - / codingblocksindia
Follow us on Instagram - / codingblocks
Follow us on Twitter - / codingblocksin
Source code available on -github.com/coding-blocks
For more interesting tutorials - / @codingblocksindia
Get the best Offers & Deals during the Big Diwali Sale: cb.lk/diwaliyt
Just awesome !! I've been watching videos and studying articles on Merge sort .......feeling relaxed to say that this video was last in understanding conceptually and crystal clearly !!! Thanks a lot mahn !!
You can check out complete online course on Coding blocks online.
@@CodingBlocksIndia Is it free or paid
One of the best video on merge sort I have ever seen!! Simply amazing! I was tensed as I could not understand the merge sort but you saved me! You are a lifesaver may God bless you!
This is by far the best code I have seen. Clean and simple.
100's of attempt to learn this thing and who knew that a UA-cam video will make it clear.. thank you sir
@@dhwajsharma oh really..are you replying to me or " your need of self validation which you are trying to satisfy by imagining someone below you" .🤗anyway i hope you get a life🙏🏿
And i love how you liked ur own comment
This is the best explaination of this sorting method i've seen so far!!
Thank you and ofcourse keep up the good work.
Easiest approach.
Understood in just one go.
Thanks.
Your approach is very nice sir instead of explaining a block of code you just explained by the concept and then written the code.really loved it.eagerly waiting for your upcoming videos.
Excellent video I have been wandering for a long time to understand this merge array concept but failed all the time.
This video at least gave me the confidence that with 2 or 3 times I will be able to understand this concept at 100 percent.
Thank You
Thanks Junaid Ali for the compliment 💯. Please subscribe us for more such videos ✌️
You absolute legend - I was watching a course where merge sort came up and the implementation they used deliberately only allowed it to function with a number of variables that were a factorial of 2 and it was absolutely bending my mind but this explained it beautifully and I FINALLY understand it 😂 If you have a tip jar for donations I'd love to drop you one - the least I can do is give you guys some coffee money!!
Why we are taking tempryory array can we assign the values into the same array ? And save the overwritten element before assigning the small value.
very simple explanation and simplest way to implement mearge sort.
appreciate it.
keep making videos like this.
thanks .
thanks a lot for awesome explanation!!!saw many videos but the concept was not cleared.but your video made it very easy
Checkout free course - cb.lk/cpcpli for amazing videos.
Do More, Eagerly Waiting !! AND also please publish videos on solutions to problems on Hackerank, Codechef ,etc...That Would Really Help !
i really appreciate your work, the way you write coding was awesome keep up the good work.
I feel lucky today coz when I liked your video it changed from 1.4k to 1.5k👍 indeed best explanation .... Thank you very much Sir
Great and explicit explanation. Thank you so much! Helps a lot!
Explanation is best in class!
Thank you very much for this video sir! Great explanation!
very nice explanation sir , thank you very much!!
Very nice... Please make more videos on data structures and algorithms...
+Abhishek Bhardwaj sure stay tuned.
Very clear explanation. THANK YOU!
Thanks Bhargavi ! Pls subscribe and spread the word about our channel with your friends.
- Prateek Bhayia
Loved it👍
Thank you so much for coding merge sort, I struggle understanding the code in the book
Thanks Michael for the compliment !!
Thank You Sir !!
Very helpful...
omg!!! you are soo good!!!!! excellent explanation....keep it up!!! and thankyou soooo much!!!
Thanks Athira ! Pls subscribe my channel and share with friends. - Prateek
Great job bro finally i understood
Excellent explanation !!!!
Glad it helped!
best explaination i think
Best explanation!
thank you so much bro...
awesome!
Superb Explanation Buddy Really Appreciate Your Work Thanks A Lot 😊👍👍
Thanks Ketul !
In 11:45 in the merge function just change the logical and with logical or then you don't have to write those extra while loops for one array exhausting
Nice explanation thank u
Thanks man awesome explanation
Quick question: Is the space complexity of your merge sort code is O(nlog(n))? n because of the temporary array and log(n) because of the recursive calls? Or would it be O(n) because of the temporary array? Thanks
thanks for the video
it's a nice explanation
You should explain how that recursive function worked in this case .... Basic functionality of merge sort is easy to understand but hard to code. I still didn't get the recursion calls
this is what exactly I came here for, I have been struggling to understand the mergesort function, as to how just bypassing left right and mid it will relate to index of the array. if u found out ans pls reply
Same problem, even I didn't get how that recursive function work.
@@MrDaksha77 I will explain plz watch.
Watch this video
Topic Merge Sort
ua-cam.com/video/4-J3ocFd98k/v-deo.html
Best of all...
Very nice explanation. Feels easy to understand. Main thing is that you have shown how to write the program for it. Many of the videos on UA-cam have just given theorotical explanation. 👍👍
Thanks Gauri. You can find more detailed videos on online.codingblocks.com
really great video! thanks!
nice.......please add a video on implementation of bubble sort on linked list and more on data structures like trees..!!
Really nice explanation ...Tq so much
Best explanation! thank you so much
Awesome
Thanks ! Like , Share and Subscribe.
awesome thankyou!
Bro u explained very well such lot of teacher teach like different behaviour u are awesome bro I got it this code how can we implement this thnks.
3 first lines
need to fix:
int a[n];
after you get n
Thank you sir
Thank you vary much
loved
Thanks ! Like , Share and Subscribe.
Can the elements be directly transferred in array a without using the temporary array?
thank you so much brother
Welcome Fatima.
thank you
thankyou so much
🙌
very good explanation! greetings from Germany :)
Thank you dear. - Prateek
Why do we need to to pass 's' and 'e' arguments seperately to the functions? Doesn't the the array already have information about its start and end? Just curious to see how can we approach this problem by just passing array to a single function rather that two functions.
I am implementing same code but not getting the same answer my answer is something -346521
I am also getting wrong output
this material provide in hindi so very helpful for student
will do in Hindi as well. Keep watching.
nice
Hello sir..i have a doubt tht why did u called merge(a,s,e) as already u gave it by dividing the array.then why did u call that above function..explain it sir
Best
One of best
💯💯
Why is the size of temp array fixed to 100? What if the number of elements are more?
Very low sound while you are explaining, in starting volume was loud and clear!
in merge function in parameters , why did you wrote int *a, why not int a[ ]?
Both are same.
its 2 am and thank you very much
5:00 I understand why we need the base case in the code, but I do not understand how that if statement reflects what we are trying to do at all. if (s>=e), then return . So for example, if the starting point was 4, and the ending point was 1 (so in this case the starting point is greater than the end point) why the hell do we NOT want to sort it, and why do we want to return it. Makes no sense, since we want the array in increasing order.
no the start and end point refers to the index of the array.... so when s=e then we dont divide it further....
what if elements of array are in odd no?then how to calculate mid point
Since the container is of int type... So 5/2 will return 2 instead of 2.5. so 2 will become the center meaning out of 5 elemnts left part will have 2 and right part array will have 3 elements
Since the container is of int type... So 5/2 will return 2 instead of 2.5. so 2 will become the center meaning out of 5 elemnts left part will have 2 and right part array will have 3 elements
Mid = s + e-1/2
I think it's pretty sad that almost no one makes mergesort that returns a list instead of a void.
not changing input is good practice
My left ear understood it😅🤣
can anyone explain to me why he use that *a pointer in place of the array as a parameter in marge function
you can use the array. both can be used interchangably
@@KM-sf6zy thanks..
@@ashirbad29 Both does the same work , putting an int arr[ ] , this will prompt the function to access the memory where int arr [ ] is stored, C++ does this without showing you so in background , if we use pointer *arr , then it directly points to the memory where the array is stored so the function can access it.
Sorting kyse ho rhi h
you are legend bro
Thank you so much Tanmay.
I couldn't find the code there so can u please write it in the comments?
Please check the description to get source code ☺️
In main why why do we pass (n-1) to mergesort why dont we pass n?
since the last index of array is at 'n-1' position not on 'n'. The 'n' is total length but there are 'n-1' indexes as array starts from 0.
@@raghavrajagarwal7074 ok so while comparing array we do it till n-1 and not n for all cases??
@@bobbytop6109 because array starts from 0 not from 1... so array size is n-1
Thanks quick sort plz
ua-cam.com/video/8isAsDxcXPo/v-deo.html Quick sort
#include
using namespace std;
void emerge(int *a,int s,int e)
{
int mid=(s+e)/2;
int i=s;
int j=mid+1;
int k=s;
int temp[100];
while(i
Hates off ❤️👏
sir pls use mic, background noise is hurting ears
Nice but more explanation is needed.
Please provide these videos in hindi.
Become a professional programmer with Coding Blocks' Online Courses. Visit cb.lk/2T7WP to explore all courses. Use Coupon Code "UA-cam" to avail 25% Off on Our Courses.
Mozart algorithm? ;)
its really sad, that most of those youtube videos are with strong accent, where you understand like 5% of anything.
That's bs.
@@oadka yeah, your comment is BS. especially when i look at your "native" level of english in your videos. so shut up on the cheap seats.
@@silenthive Hey hey free views for me! 😁
@@silenthive yeah man, i mean, He spent his time to explain this for free so why being so lazy to take some extra english classes so you can be pleased right? 🙄 Just shut up and be grateful for the time the guy took to explain it. This was clearer than any of the other explanations i found.
this code couldn't be run on hackerrank.com!!!!!!!!!!!!!!!!!!!!!!!!!!!!! so please sir , try with better approach!!!!!!!!!
Good tutorial. Much appreciated!!
Poor audio
i am thinking about students who paid for coding blocks courses. it's worse than random youtube video
nice