Merge Sort is a divide-and-conquer sorting algorithm that recursively divides an array into two halves until single elements remain, then merges them back together by comparing elements and placing the smaller one first; it is stable (preserves original order of equal elements), has O(n log n) time complexity in all cases, and requires O(n) additional space for merging.
Approfondir
Prérequis
- Pas de données disponibles.
Prochaines étapes
- Pas de données disponibles.
Approfondir
Merge Sort in 2 Minutes | All You Need to Know #mergesort #dsa #daa #shorts #coding #recapAjouté :
Hello everyone.
Let's just have a quick recap about merge sort and let me tell you what are the points you need to remember whenever you hear the word merge sort.
First of all, what is merge sort?
It is an algorithm that is used to sort the elements in either ascending or in descending manner.
This particular merge sort works in data structures like array as well as linked list.
And this merge sort follows the divide and conquer paradigm.
How does it work basically? There are two functions. One is the merge sort function itself, another is the merge function. How does this merge sort function work?
It finds the middle element of the array and then it breaks it down into two parts, the left part and the right part, and then it keeps on calling itself recursively on the left sub part as well as on the right sub part. And it breaks the array until and unless it cannot break anymore. That is, it reaches the base condition, only one element is left.
At that point, it starts merging back.
And it calls a merge function. How does the merge function work? It basically suppose there are two arrays, two sorted array. There are two pointers. One is at the first array's first index, another is the second array's first index. So, it will be comparing those two elements.
Whoever is smaller, that will be going to the final array.
And whoever is going to the final array, that particular pointer will be moved to one step ahead. And this process will keep on repeating until and unless we're getting the final desired outcome.
This merge sort is also known as stable sorting because whatever be the input, if there are two similar elements, say there are two 23s, so in that case, they will be preserving their order whenever the output is generated.
Whichever 23 has came first in the input, that will be there in the first in the output as well.
This merge sort, because it is recursive, so it has a recurrence relation, that is, T of N, that is the time taken for N elements equals to 2 T N by 2 plus N.
What is that two in front of the T? That is it is dividing into two sub parts and n by two is nothing but the size of each sub parts at every time.
And what is that plus n? That plus n is the time taken for merging all these things back.
And what is the worst case, best case, and average case time complexity of merge sort? Everything is order of n log n.
And what is the time and space trade off? That is this particular merge sort works really, really fast in order of n log n time, but it takes extra array.
That is while merging back we need the help of an extra array. So, the space complexity is order of n.
So, that is all about merge sort and whatever I have talked about in this video, all these videos are detailed available in my data playlist. So, you can check out. I am pinning them down in the pinned comment. Thank you for watching.
Vidéos Similaires
Re: 🗣️📍theprophedu📍2026 GST 103 CLASS (E-EXAM REVISION)
theprophedu
636 views•2026-06-04
WEB TECHNOLOGIES UNIT-2 | Degree 4th sem BCOM Computers web technologies unit-2 full explanation💯✅
LearnwithSahera
1K views•2026-05-29
More tests are always better? How to use AI to identify tests that bring little value
Alliance4Qualification
335 views•2026-05-29
Search Algorithms Explained in 60 Seconds! 🤖💨
samarthtuliofficial
218 views•2026-06-01
Making Minecraft Clone with C++ & Raylib
PecaCSLive
686 views•2026-06-04
People of Game of Thrones using JavaScript DOM
AltCampus
296 views•2026-05-30
Instagram accounts got PWNed
EricParker
13K views•2026-06-03
Introduction to Problem Solving Part - 1 | Lecture 1 | Intermediate DSA
ascensionix
107 views•2026-05-29











