Understanding Mergesort: Sorting Made Simple | Recursion Series

  Рет қаралды 18,982

WilliamFiset

WilliamFiset

Күн бұрын

Mergesort is a well-known and efficient sorting algorithm that follows the divide-and-conquer paradigm. It aims to sort a given array or list of elements by dividing it into smaller subarrays, sorting those subarrays recursively, and then merging them back together to obtain the final sorted result.
The algorithm begins by repeatedly dividing the input array into two halves until each subarray contains only one element or is empty. This process is known as the "divide" step. Then, it merges adjacent pairs of these subarrays, comparing and rearranging the elements in a sorted order. This merging process continues until a single sorted array is obtained, hence the term "merge" in mergesort.
One of the key advantages of mergesort is its stability, meaning that elements with equal values retain their original relative order after sorting. This property makes mergesort particularly useful in scenarios where preserving the original order of equal elements is crucial.
Mergesort exhibits a time complexity of O(n log n), where "n" represents the number of elements in the input array. This efficiency makes mergesort suitable for sorting large datasets, and it is often used as a standard benchmark for other sorting algorithms.
Overall, mergesort's simplicity, stability, and efficient performance have made it a popular choice in various applications, ranging from general-purpose sorting to applications in data analysis, parallel computing, and more.
0:00 Mergesort overview
2:15 Algorithm animation
3:35 The divide phase
5:10 The conquer phase
5:53 Mergesort pseudocode
7:46 Merge function
Source code repository:
github.com/williamfiset/algor...
Video slides:
github.com/williamfiset/algor...

Пікірлер: 19
@user-sf9zb5rm5u
@user-sf9zb5rm5u 8 ай бұрын
Cool, with animated explanation it`s so much easier to understand!
@zxzDanielDefo
@zxzDanielDefo 10 ай бұрын
Hi, appreciate your work! Here's the list of topics I'd love you to make videos on: 1. Complexity theory: P, NP, etc problems, categorization and how they relate to coding interviews 2. Cover problem solving techniques: sliding window, two pointers, backtracking, etc 3. Cover all sorting methods and their applications 4. Bit manipulations, performance gains, how to optimize a solution to use bits ❤
@levon9
@levon9 3 ай бұрын
Really nicely done, very clear. Thank you for sharing.
@user-bs3wz1vp6g
@user-bs3wz1vp6g Ай бұрын
great explanation and pseudocode example! Thankyou!
@kaushikkundu
@kaushikkundu 5 ай бұрын
First time watching video of yours. Great video
@shnerdz
@shnerdz 8 ай бұрын
Love your videos! Please consider making some on segment trees. I feel like there aren't great ones out there right now
@fromjavatohaskell909
@fromjavatohaskell909 Жыл бұрын
4:24 please consider updating formula for mid point calculation mid = (lo + hi) /2 that might overflow with mid = lo + (hi - lo) / 2
@dansmar_2414
@dansmar_2414 7 ай бұрын
The best!
@talhataki5855
@talhataki5855 Жыл бұрын
I was wondering which software you use for creating such vibrant illustrations? Is it free to use or open-sourced?
@WilliamFiset-videos
@WilliamFiset-videos Жыл бұрын
I use Keynote
@talhataki5855
@talhataki5855 11 ай бұрын
@@WilliamFiset-videos Thank you for sharing
@AbhishekS-cv3cr
@AbhishekS-cv3cr 9 ай бұрын
Please make more videos!
@vidorg5574
@vidorg5574 7 ай бұрын
Do you have videos about amotized analysis?
@JohnSVENAhn
@JohnSVENAhn Жыл бұрын
@BlueRS123
@BlueRS123 10 ай бұрын
Could you do splay tree?
@joelsanfeliu7213
@joelsanfeliu7213 9 ай бұрын
I comment here because it's your last video and i don't know how to reach to you. If you or actually anyone can help me with this i'll be very greatful. Given a input of a lot of words and an NxM dimension i have to create an algorithm that designs the best (if possible, or one of the bests) sigle-finger NxM keyboard layout for mobile. Which means that, for example, given a letter in the keyboard it's better to have closer letters that you know that with highly probability will come next. An other statement could be that the middle part of the keyboard is best to reach from the finger so it should be the most freqüent letter, so the most important letters should councentrate in the middle meanwhile you consider what i said before about you have closer letters that you know that with highly probability will come next and also you consider the NxM keyboard layout. The frequency of each letter and what letters come next after a certain letter it's easy to get by reading the input words and storing it in a data structure, but once i have this i don't know how to do this algorithm. Obviously you have to find the best combination of letters in the keyboard layout so this if you do it by bruteforce it's exponential and it's impossible to do it in an efficient way. But even if i could, i don't even know how to judge each combination and know which one is the best. I though about making it a graph and get something or even the google's pagerank algorithm which has a similarity, but i got stuck. I also thought about genetic algorithms which would be so efficient to find the best or one of the best, which that's enough. I don't know if i explained myself clearly, if not i'll try to explain it in different words or something. Thanks.
@novascotia2015
@novascotia2015 Жыл бұрын
luv u bro
@kvelez
@kvelez 7 ай бұрын
def merge(left, right): sorted_list = [] l, r = 0, 0 while l != len(left) or r != len(right): if l == len(left): sorted_list.append(right[r]) r += 1 elif r == len(right): sorted_list.append(left[l]) l += 1 elif left[l] < right[r]: sorted_list.append(left[l]) l += 1 else: sorted_list.append(right[r]) r += 1 return sorted_list print(merge([1, 3, 5, 7], [2, 4, 6, 8]))
Learn Merge Sort in 13 minutes 🔪
13:45
Bro Code
Рет қаралды 257 М.
Василиса наняла личного массажиста 😂 #shorts
00:22
Денис Кукояка
Рет қаралды 4,7 МЛН
How Dijkstra's Algorithm Works
8:31
Spanning Tree
Рет қаралды 1,3 МЛН
Merge Sort Algorithm in Java - Full Tutorial with Source
23:02
Coding with John
Рет қаралды 168 М.
Topological Sort | Kahn's Algorithm | Graph Theory
13:32
WilliamFiset
Рет қаралды 113 М.
Why Is Merge Sort O(n * log(n))? The Really Really Long Answer.
36:50
Back To Back SWE
Рет қаралды 112 М.
Merge sort algorithm
18:20
mycodeschool
Рет қаралды 2,2 МЛН
The Art of Linear Programming
18:56
Tom S
Рет қаралды 625 М.
Mastering Dynamic Programming - How to solve any interview problem (Part 1)
19:41
Learn Quick Sort in 13 minutes ⚡
13:49
Bro Code
Рет қаралды 288 М.
Tiling problems [1/2] | Dynamic Programming
16:38
WilliamFiset
Рет қаралды 37 М.