Тёмный

Merge Sort: Background & Python Code 

Brian Faure
Подписаться 13 тыс.
Просмотров 27 тыс.
50% 1

Опубликовано:

 

10 авг 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 59   
@s121003
@s121003 6 лет назад
Thank you Brian for the informative videos. Please use '//' to ensure the integer division.
@BrianFaure1
@BrianFaure1 6 лет назад
Glad I could help and thanks for the advice!
@RestlessSixtie
@RestlessSixtie 6 лет назад
Thanks a lot Brian for the explanation and s121003, correctly said.
@ishanahsi
@ishanahsi 6 лет назад
someday I want to code like you do .Truly mesmerised by the way you code. thank you for the video
@arindamjain1569
@arindamjain1569 2 года назад
your coding style is soo pythonic, Love it man!
@wajahatkhan9455
@wajahatkhan9455 5 лет назад
bundle of Thanks..... In literally minutes you done the job....Thanks sir
@logicNreason2008
@logicNreason2008 6 лет назад
Been watching your videos and your style of coding is pretty. Keep up the great work!
@BrianFaure1
@BrianFaure1 6 лет назад
Thanks!
@coladud7061
@coladud7061 3 года назад
Best tutorial I've come across. Simply amazing. Thank you
@MrAmbarish710
@MrAmbarish710 3 года назад
super easy explanation. And the comparison index between different sorting algo's really made a lot of things clear for me.
@Felipe-53
@Felipe-53 4 года назад
Thank you, my friend. Best implementation in Python on youtube!
@shreehari2589
@shreehari2589 3 года назад
Awesome explanation Brain thank you, i hope to see more data structures and algorithms tutorials from you
@nishuz
@nishuz 5 лет назад
Thanks dude! I found this tutorial _very_ helpful.
@salah4501
@salah4501 5 лет назад
This is an excellent video, thank you
@celina6204
@celina6204 4 года назад
This is awesome! Thank you sir
@Aditya-ne4lk
@Aditya-ne4lk 4 года назад
this is one of the most elegant implementations i have seen
@Felipe-53
@Felipe-53 4 года назад
I agree, my friend. It's very readable and understandable.
@Sindoku
@Sindoku 5 лет назад
Awesome video, you helped merge sort click for me, thanks.
@Eduardo-hv1yh
@Eduardo-hv1yh 4 года назад
Damn this is a great explanation! Thanks
@nashaeshire6534
@nashaeshire6534 4 года назад
Thank a lot. Now, I've trully understand the merge sort!
@BrianFaure1
@BrianFaure1 4 года назад
Thanks Nash!
@C-Swede
@C-Swede 6 лет назад
Had some trouble making this work in Python 3 at first. line 30, in merge_sort left, right = merge_sort(a[:(len(a)/2)]), merge_sort(a[(len(a)/2):]) Managed to fix this with a workaround: lgt = int(len(a) / 2) left, right = merge_sort(a[:lgt]), merge_sort(a[lgt:])
@jojoesekyisagoe
@jojoesekyisagoe 5 лет назад
You can also set a midpoint variable as below and use it midpoint = int(len(a)/2) # to cater for a being odd left, right = merge_sort(a[:midpoint]), merge_sort(a[midpoint:])
@johnduddy6455
@johnduddy6455 4 года назад
Or just use "//" left, right = merge_sort(a[:(len(a)//2)]), merge_sort(a[(len(a)//2):]) rather than....... left, right = merge_sort(a[:(len(a)/2)]), merge_sort(a[(len(a)/2):])
@Emresalur1882
@Emresalur1882 3 года назад
First I couldn't believe how fast you're typing but then realised that you speeded up.I was going crazy mate:)))) Thanks for the good explanation by the way.
@BrianFaure1
@BrianFaure1 3 года назад
Lmao! Glad it was helpful for you!
@vikashkumarchaurasia1299
@vikashkumarchaurasia1299 6 лет назад
Your video is very nice and we'll explained, please make lectures on graphs and priority queue
@lasergamer2869
@lasergamer2869 3 года назад
For the merge function we can just return c + a[a_idx] + b[b_idx]
@dweebosupremo5904
@dweebosupremo5904 2 года назад
This is a good video. I don't really like the key board noises, but that's just a personal preference.
@kevindoku1375
@kevindoku1375 3 года назад
I had to do a bit of work around but I got it. if you use len(arr)/2 in python 3, you'll get an index error so I did this instead def merge_sort(arr): if len(arr)
@bostevens236
@bostevens236 4 года назад
I needed to use floor division for indexing in the the recursive function calls on left and right. Why didn't you? In the case of odd numbers, I get an error.
@ligrt2426
@ligrt2426 3 года назад
yes me too i had some error with this. tnx
@gandhi1333
@gandhi1333 5 лет назад
Hi Brian, I am getting error while a_index
@almuhimen8023
@almuhimen8023 4 года назад
same
@shreekarshastry2307
@shreekarshastry2307 4 года назад
u would have missed return merge(left, right)
@BrianKTran
@BrianKTran 5 лет назад
How does one learn to write code like you?
@flarierza
@flarierza 5 лет назад
I'm just trying to understand this (learning MergeSort for the first time and your video is great). But I'm having trouble understanding this. Does your merge function assume that the left and right lists you are passing to it are already sorted? Because if your left list and unsorted, and your right list is unsorted - does this still work? I guess I'll test it and see.
@flarierza
@flarierza 5 лет назад
Mmm ok i just tested and it does not work. You also mentioned in the video that the lists you pass to your merge function are already sorted, so it doesn't work with unsorted lists. However, I don't see any pre-sort going on in your merge_sort function. It looks like the only thing you are doing is splitting up the input list into 2 halves, and then you call your merge function to merge them. Those 2 halves are most likely 2 unsorted lists, because they were generated by your create_array function, which is a randomized list. So based on that... I'm failing to understand how the 2 halves are sorted so that when passed to your merge function it works. It must mean that those 2 halves become sorted somehow within your "3 lines" of code within the merge_sort function - but i just can't see it, or I'm missing something here arghh
@flarierza
@flarierza 5 лет назад
Ah ok I see the secret is in your left, right = merge_sort(a....) line. This function is calling itself within itself. I'll need to visualize this for a bit to understand it mmm.
@BrianFaure1
@BrianFaure1 5 лет назад
Happy to see you understand it a bit more, the merge function will actually never (as long as everything is working) be passed two unsorted arrays. The first time merge is called it is passed two arrays of length 1, then 2, and so on, but every time the two inputs are always sorted. If you have any questions or need anything clarified let me know.
@flarierza
@flarierza 5 лет назад
Thanks. I was looking to learn BFS next and wanted to watch one of your videos on it (because I like your videos) - but it doesn't seem like you've done one on BFS?
@BrianFaure1
@BrianFaure1 5 лет назад
Yeah I haven't gotten around to it, still planning on putting one out though, just don't have as much time to make videos as I used to.
@omarkhan5223
@omarkhan5223 6 лет назад
I keep getting this error left,right = merge_sort(a[:len(a)/2]), merge_sort(a[len(a)/2:]) TypeError: slice indices must be integers or None or have an __index__ method
@omarkhan5223
@omarkhan5223 6 лет назад
Never mind, I fixed it by using the double / for dividing. A good work around.
@jojoesekyisagoe
@jojoesekyisagoe 5 лет назад
You can also set a midpoint variable as below and use it midpoint = int(len(a)/2) # to cater for a being odd left, right = merge_sort(a[:midpoint]), merge_sort(a[midpoint:])
@Abhi-qi6wm
@Abhi-qi6wm 2 года назад
I don't think the code'll work for arrays with odd number lengths. Using left, right= merge_sort(a[:len(a)//2]), merge_sort(a[len(a)//2:]) would do.
@MiravMehtaishere
@MiravMehtaishere 3 года назад
Please upload code in github
@loremis
@loremis 4 года назад
man, you type really quick
@moisesacero4995
@moisesacero4995 4 года назад
i'm sleepy
@abualasif
@abualasif 3 года назад
@@moisesacero4995 lmao ur faded
@moisesacero4995
@moisesacero4995 3 года назад
@@abualasif why TF DID HE HEART UR COMMENT?!?!?!?!
@abualasif
@abualasif 3 года назад
@@moisesacero4995 I guess we are even now :)
@moisesacero4995
@moisesacero4995 3 года назад
@@abualasif the war continues! i'm still sleepy 4 months later
@hdot2613
@hdot2613 4 года назад
8:01 - "because bubble, insertion and selection sort all suffer from exponential time complexity in the worst case..." Do you mean *quadratic time complexity* in the worst case? AFAIK those algorithms only need to traverse pair of nested loops, so their time complexity should be quadratic at worst: O(n^2).
@BrianFaure1
@BrianFaure1 4 года назад
Yes apologies I mean to say quadratic :)
@josephbrown7502
@josephbrown7502 5 лет назад
The audio levels are so low that the background hiss competes with the way too fast speech.
Далее
Quicksort: Background & Python Code
7:56
Просмотров 19 тыс.
10 FORBIDDEN Sorting Algorithms
9:41
Просмотров 835 тыс.
ДЖЕФ ВСЕМ ПОМОЖЕТ🤓
10:33
Просмотров 411 тыс.
Joker, what is this doing?!#joker #shorts
00:31
Просмотров 3,8 млн
Learn Merge Sort in 13 minutes 🔪
13:45
Просмотров 279 тыс.
Merge Sort In Python Explained (With Example And Code)
13:35
10 Sorting Algorithms Easily Explained
10:48
Просмотров 44 тыс.
Compiled Python is FAST
12:57
Просмотров 105 тыс.
Sort Lists with Heap Sort in Python
16:45
Просмотров 37 тыс.
I Solved The World's Hardest Maze (with Code)
9:54
Просмотров 130 тыс.
Merge Sort in Python
14:20
Просмотров 13 тыс.