Sorts 5 Shell Sort

  Рет қаралды 204,550

RobEdwards

RobEdwards

Күн бұрын

Dr. Rob Edwards from San Diego State University summarizes shell sort - a tricky sort to get the complexity right

Пікірлер: 118
@Tumbolisu
@Tumbolisu 4 жыл бұрын
This video doesn't actually explain the algorithm correctly. Shell sort doesn't take 2 elements at a time like this. It simply takes all elements that are a certein gap size appart, and then performs an insertion sort on these. Thus, the final insertion sort only ever has to move elements that are very close together. How close depends on the previous gap size. Also, the time complexity of shell sort is a bit harder to describe, as it depends on the gap sizes used. Halfing the gap size each time will indeed result in the worst case being O(N²). However, many different gap sizes have been tested in the past. Some have a worst case of O(N^3/2), others O(N^4/3). Some number sequences for gap sizes have an unknown time complexity, but tests show that they are even better than that!
@basselkordy8223
@basselkordy8223 4 жыл бұрын
Thank you! i just learned about it and was looking for another resource so i watched this and got confused because my main source explained it like you did (which makes much more sense)
@danielfernandes1010
@danielfernandes1010 2 жыл бұрын
Thank you. It's unfortunate that this is one of the top videos when I look up for "shell sort".
@student4373
@student4373 Жыл бұрын
I was wondering why every other video explained it differently. Thank you.
@ilovee271
@ilovee271 2 күн бұрын
Yes, I think there's a bit complex but reasonable sequence formula that seems to get really close to O(n log n)!
@Mars30999
@Mars30999 3 жыл бұрын
Anyone get distracted and impressed by how well he is writing in reverse?
@BartWillems1969
@BartWillems1969 3 жыл бұрын
And with his left hand as well!
@hudzell
@hudzell 3 жыл бұрын
The video is mirrored. He's writing normal for himself with his right hand and the video is flipped so we can read it.
@TharaMesseroux1
@TharaMesseroux1 3 жыл бұрын
is he?
@shinju7006
@shinju7006 4 жыл бұрын
Suppose to learn Shell sort but then I spent almost 10’ to know how learning glass works, 😂
@allankirui554
@allankirui554 3 жыл бұрын
How does it work?😂
@shinju7006
@shinju7006 3 жыл бұрын
@@allankirui554 Simply record a mirror. A mirror before them then a camera record the mirror.
@shinju7006
@shinju7006 3 жыл бұрын
@bismillah eng. no color
@ashmitchamoli781
@ashmitchamoli781 3 жыл бұрын
@@shinju7006 bruh just flip the video
@piyushanand7965
@piyushanand7965 3 жыл бұрын
😂😂 first record the video from oposite side to the glass then edit the video in right to left manner
@Brlitzkreig
@Brlitzkreig 3 жыл бұрын
Genius idea with the glass wipeboard
@johnphillip9013
@johnphillip9013 4 жыл бұрын
Thank you so much for putting this on the Internet. Had problems grabbing the shell sort concept.
@fedos
@fedos 4 жыл бұрын
Finally, an explanation that fully explains the algorithm.
@FMgamer1
@FMgamer1 7 жыл бұрын
how do you write backwards???
@sdagur
@sdagur 7 жыл бұрын
Yeah ,same question??
@ozgunozerk
@ozgunozerk 7 жыл бұрын
Its probably mirrored after the recording
@sebastianlacki8483
@sebastianlacki8483 7 жыл бұрын
Stop, that makes too much sense
@HristoskoBG
@HristoskoBG 6 жыл бұрын
Probably just learned to write backwards, because I suppose he has an auditory in front of him
@godofwinetits3826
@godofwinetits3826 6 жыл бұрын
its another sorting algorithm
@coltonbooth8633
@coltonbooth8633 Жыл бұрын
Im more impressed by how he writes backwards than anything else
@jans.2686
@jans.2686 6 жыл бұрын
glad to see Jack Barker move on from his box idea into a new hobby of sorting
@dariuselijah9277
@dariuselijah9277 4 жыл бұрын
UNDERRATED COMMENT
@HarshSharma-rw3vh
@HarshSharma-rw3vh 3 жыл бұрын
😂😂😂😂
@yesnickcarter
@yesnickcarter 3 жыл бұрын
I took Data Structures at SDSU almost 20 years ago. It was the class that changed my life. Loved it.
@xoxoo4877
@xoxoo4877 6 жыл бұрын
you choose ---> gap=4 , then number 1 must goes in the first row (with 3, 7)
@liquicitizendirk2147
@liquicitizendirk2147 5 жыл бұрын
exactly my thought
@bridger4954
@bridger4954 4 жыл бұрын
Great explanation, probably the best and shortest one I've seen so far. Thank you!
@zerosandones701
@zerosandones701 5 жыл бұрын
Why does this decrease the time complexity? How many ops do you have to spend swapping? Which gap size should you use? Why is the complexity what it is? Great intro to the algorithm and thank you for creating the content... would love to see more detail.
@marcosnavarro9420
@marcosnavarro9420 4 жыл бұрын
Your explanation helped me understand the selection sort very well but I believe you might have made a mistake on your first round when gap = 4. When gap = 4 it should have compared 7 and the 1. After comparison the 7 would then be inserted to where the one is and the loop should run one more time after that comparing the 3 and the one. Effectively putting the 3 where the seven originally was at the start and replacing the 3 at the start of the array with a 1. I may be wrong but after tracing the algorithm that is the answer I got and the shell sort worked.
@sunflowerglaxy6735
@sunflowerglaxy6735 2 жыл бұрын
yesss i am trying to fix it frrfrfr
@shikharvasisht1
@shikharvasisht1 7 жыл бұрын
At 3:03, I could not understand why you compared 10 to 1, after 8 to 6. Shouldn't this be 5 to 10, 7 to 9, and 6 to 1?
@SignzNSymbolz
@SignzNSymbolz 7 жыл бұрын
It was a mistake on the professor's part. He went back and said "somehow i ended up with two number ones" and then erased the comparison so that the 10 was on its own.
@TrevorHigbee
@TrevorHigbee 6 жыл бұрын
I assume you don't compare 5 with 10 because 3 is already being compared to 5. And 6 is already in a relationship w/ 8.
@coolgorillaz9624
@coolgorillaz9624 5 жыл бұрын
@@TrevorHigbee i guess it depends on how you implement it, in Robert Sedgewicks Algorithms for c++ book, , the for-loop doing the swapping shown here goes up to
@Brettsauces
@Brettsauces 5 жыл бұрын
Basically, Dont compare the same number twice. So if say 8 is compared to 6, then next is 6 is compared to 1, dont compare the 6 again. Instead, start on the next uncompared number, which happens to be 10 in this case.
@olabanjistv4626
@olabanjistv4626 7 жыл бұрын
In the second round of the sort, where you not suppose to compare with the length of 2. Which is half of 4 that you started with 🤦🏽‍♂️
@juancruzinfante6321
@juancruzinfante6321 6 жыл бұрын
yes
@future-daypharmacists6647
@future-daypharmacists6647 5 жыл бұрын
true
@ElSkizzle
@ElSkizzle 5 жыл бұрын
He did it correctly. He went from gap-size 4 to gap-size 2.
@elemindustries5540
@elemindustries5540 4 жыл бұрын
@@ElSkizzle the first gap-size was 3, second one was 2. -> No, he didnt take the half of the first gap-size.
@Truchasgl3
@Truchasgl3 4 жыл бұрын
You dont need to take the half. You can select any gap as long as you do a gap 1 insertion sort at the end. The gaps used before it make the vector be "more sorted" to decrease the iteration needed in the 1gap sort. Taking the half helps. But you can do it with any sequence (some of them are more efficient than others).
@jamband64
@jamband64 6 жыл бұрын
Excellent work! Your glass presentations make comp sci concepts crystal clear
@XaxtonRevolution2
@XaxtonRevolution2 3 жыл бұрын
At the last step, when you switched the 2 and the 3, it wasn't a swap, the end result is the same as if you swapped. But the steps of your decision tree are to insert each number in its correct place by comparing it to all of the numbers to the left of it. If the numbers were simply being swapped at the last step, it would be a bubble sort.
@ya00278
@ya00278 4 жыл бұрын
It's super clear! you deserve more likes!!
@TruthTiger
@TruthTiger 4 жыл бұрын
This helped me out a lot. Thank you Dr. Edwards
@tylerforrester743
@tylerforrester743 5 жыл бұрын
your videos rock i was totally lost when it came to BigO and now from your vids i get. thanks for sharing the knowledge .
@IT_AvishkarBorkar
@IT_AvishkarBorkar 3 жыл бұрын
my guy is the most confusing teacher ive ever met
@kurobros4791
@kurobros4791 6 жыл бұрын
Wait, I just can't fucking understand how he is writing all the letters in backwards.... Respecc. He already got a sub for that mad skill right there. Nothing else matter. Mad lad
@housemajaliwa
@housemajaliwa 2 жыл бұрын
That was wonderful to watch
@micahjacobson8533
@micahjacobson8533 Ай бұрын
if the gap was halved to two, shouldn't you have been comparing 3 and 8, 2 and 5, etc?
@kailaspsudheer
@kailaspsudheer 3 жыл бұрын
This guy takes class like Tony stark
@giorgi23
@giorgi23 4 жыл бұрын
Now I understand why shell sort is not popular
@firstnamelastname4685
@firstnamelastname4685 6 жыл бұрын
where could I know the calculation of the time complexity of shell sort? I know it may be too advance to be explained in this video , so I just would like someone to tell me where is a good step by step guide of calculating the complexity.
@fedos
@fedos 4 жыл бұрын
Wikipedia has worst case complexities for various popular gap sequences. en.wikipedia.org/wiki/Shellsort#Gap_sequences Sedgewick, in the third edition of Algorithms in C++, explains "Our description of the efficiency of shellsort is necessarily imprecise, because no one has been able to analyze the algorithm. This gap in our knowledge makes it difficult not only to evaluate different increment sequences, but also to compare shellsort with other methods analytically."
@sirhawkjames
@sirhawkjames Жыл бұрын
what da fuck my guy just writes backwards completely legibly casually
@dakuisha5978
@dakuisha5978 4 жыл бұрын
In loop 1 why do you just leave the one hanging? In loop 2 why does the 10 and the 1 connect??? Thats a gap of 1 not a gap of 2. Also why do you just leave 9 alone? This is important info that you just kinda skipped...
@MunyuShizumi
@MunyuShizumi 3 жыл бұрын
This is an extremely inaccurate and misleading Shell sort explanation (honestly, just downvote the video), so here's a corrected version.. During the very first iteration (gap = 4), 1 is sitting isolated on the bottom for some odd reason at position 9 (one-based numbering, 1 = first position), where in reality it would've been compared with its left pair at position 5 (which has already been swapped during the first step!). Since a swap occurs (@5@9), position 5 is then checked against its left pair (@1) again. You might notice that this looks a bit like insertion sort now, and it is (in fact, Shell sort with gap = 1 is quite literally insertion sort). In short, you're adding a gap to insertion sort, each conceptual "nth element" subarray is just being insertion-sorted. Comparison/swap steps should look like this with gap = 4: italic = comparison only bold = (after) swap 7 6 8 9 3 2 10 5 1 *3* 6 8 9 *7* 2 10 5 1 3 *2* 8 9 7 *6* 10 5 1 3 2 _8_ 9 7 6 _10_ 5 1 3 2 8 *5* 7 6 10 *9* 1 3 2 8 5 *1* 6 10 9 *7* *1* 2 8 5 *3* 6 10 9 7 What now? You don't reduce the gap sequentially 4->3->2->1 as shown in the video. The very point of Shell sort is skipping gaps in large steps (typical sequences look something like 1, 4, 10, 23, 57, 132, 301, 701, ...), and optimizing this can be a little bit like dark magic sometimes. Any sequence that ends with gap = 1 will technically work in the end (at that point it's just an insertion sort), but the sequence shown in the video makes the algorithm stupidly inefficient and is entirely missing the point of Shell sort. After gap = 4, switching to gap = 1 should be most efficient, which turns this into insertion sort: _1_ _2_ 8 5 3 6 10 9 7 1 _2_ _8_ 5 3 6 10 9 7 1 2 *5* *8* 3 6 10 9 7 1 _2_ _5_ 8 3 6 10 9 7 1 2 5 *3* *8* 6 10 9 7 1 2 *3* *5* 8 6 10 9 7 1 _2_ _3_ 5 8 6 10 9 7 1 2 3 5 *6* *8* 10 9 7 1 2 3 _5_ _6_ 8 10 9 7 1 2 3 5 6 _8_ _10_ 9 7 1 2 3 5 6 8 *9* *10* 7 1 2 3 5 6 _8_ _9_ 10 7 1 2 3 5 6 8 9 *7* *10* 1 2 3 5 6 8 *7* *9* 10 1 2 3 5 6 *7* *8* 9 10 1 2 3 5 _6 7_ 8 9 10 Sorted.
@m4h0r4ga
@m4h0r4ga 4 жыл бұрын
I love the presentation. Thank you very much.
@SumitDavdra
@SumitDavdra 6 ай бұрын
I come here for shell sort, but know i thinking about glass board. Any one answer?
@BelegaerTheGreat
@BelegaerTheGreat 5 ай бұрын
What an unnecesarily complex way to do something suboptimally.
@behmog
@behmog 3 жыл бұрын
Very nice method to sort numbers. Thank you. Is there any method to retrieve the original sequence of numbers from the sorted numbers?
@amnahhamzah9613
@amnahhamzah9613 3 жыл бұрын
what is the best case?
@amitshiksha
@amitshiksha 7 жыл бұрын
java code for shell sort: private void shell(int[] a) { int n=a.length; for(int gap=n/2;gap>0;gap=gap/2) //To create gap and reduce it by half { for(int i=gap;i=gap&&temp
@georgecarlson3606
@georgecarlson3606 5 жыл бұрын
those are some big words for a CHEAT
@nimatagik7534
@nimatagik7534 Жыл бұрын
how can you write backward man ? its really hard
@johnpaulpineda9821
@johnpaulpineda9821 2 жыл бұрын
Wow! Very good explanation. Shell sort becomes easy to learn. Thanks a lot Sir!
@xoxoo4877
@xoxoo4877 6 жыл бұрын
you are choosing a gap, as number of elements/2, and in every new iteration, you are dividing it with 2
@jigargadhia2093
@jigargadhia2093 4 жыл бұрын
how well you explained, thank you
@sunnyshah9013
@sunnyshah9013 6 жыл бұрын
is it just me or the algorithm explained here is a bit off than what shell sort is?
@TriachnidLOL
@TriachnidLOL 6 жыл бұрын
Yeah seems kinda weird. Not really consistent i guess.
@Whiteowl116
@Whiteowl116 4 жыл бұрын
yes i think he should compare the smallest number to its left neighboor after each swap to see if it should be moved further back.
@bentroyer1
@bentroyer1 7 жыл бұрын
how did he video tape this is that just a scary clear glass board?
@ishitagupta5959
@ishitagupta5959 Жыл бұрын
Thank you!
@welnyr
@welnyr 4 жыл бұрын
3:55 Element one is doubled
@shariyashaikh3886
@shariyashaikh3886 2 жыл бұрын
Thank you
@XnDxNdXnD
@XnDxNdXnD 5 жыл бұрын
That was pretty intuitive explanation. Thx!
@ecksem
@ecksem 10 ай бұрын
How are a bunch of students of a somewhat difficult engineering major freaking out about a mirrored video in the comments
@KennyWhizz-m7k
@KennyWhizz-m7k 5 ай бұрын
Exactlyyyy
@manjuegazos4672
@manjuegazos4672 4 жыл бұрын
Wait... there isn't 4
@karotto594
@karotto594 3 жыл бұрын
HOW ARE YOU WRITING BACKWARDS???!!
@oggysaad1003
@oggysaad1003 7 жыл бұрын
Very well explained sir :)
@harshitsinghai1395
@harshitsinghai1395 7 жыл бұрын
How are these videos made ?
@darkinferno4687
@darkinferno4687 6 жыл бұрын
magic
@TankNSSpank
@TankNSSpank 8 ай бұрын
but why?
@diweiye8420
@diweiye8420 Жыл бұрын
Now this might be a good algorithm to think, but this is DEFINITELY NOT what shell sort it.
@fredtech6770
@fredtech6770 4 жыл бұрын
i like your blackboard.it is transparent
@БилалКиут
@БилалКиут 6 жыл бұрын
THANK YOU!!!
@singsarav
@singsarav 4 жыл бұрын
Simply, by looking at at, I can say shell sort is least efficient compared to other methods. I have find the exact reason. I think binary tree is efficient in sorting. I don't have to do so many comparisons and swaps. I am looking for multithreaded binary tree sorting in java / javascript
@srinivasasubramanyam5501
@srinivasasubramanyam5501 3 жыл бұрын
You missed the last swap in first round. You can't cheat me.
@marcelolopesdeamorimjunior9723
@marcelolopesdeamorimjunior9723 2 жыл бұрын
fanfic 10/10 \
@lucassmith6320
@lucassmith6320 3 жыл бұрын
This is wrong explanation go somewhere else
@leydensjar
@leydensjar 5 жыл бұрын
This is not a correct explanation of Shell Sort.
@TheNiczal
@TheNiczal 2 жыл бұрын
Very bad explanation and even worst example,
@hangchen6131
@hangchen6131 7 жыл бұрын
Hahaha in the insertion sort
@s-.-8821
@s-.-8821 5 жыл бұрын
This is FALSE
@josuejheymiticonaortiz3848
@josuejheymiticonaortiz3848 2 жыл бұрын
GAAA!!1
@ethan6708
@ethan6708 Жыл бұрын
THIS IS WRONG
Sorts 6 Merge Sort
6:48
RobEdwards
Рет қаралды 55 М.
2.6.3 Heap - Heap Sort - Heapify - Priority Queues
51:08
Abdul Bari
Рет қаралды 2,3 МЛН
The Best Band 😅 #toshleh #viralshort
00:11
Toshleh
Рет қаралды 22 МЛН
Сестра обхитрила!
00:17
Victoria Portfolio
Рет қаралды 958 М.
Что-что Мурсдей говорит? 💭 #симбочка #симба #мурсдей
00:19
A Very Nice Exponential Equation
8:51
SyberMath
Рет қаралды 1,8 М.
Learn Quick Sort in 13 minutes ⚡
13:49
Bro Code
Рет қаралды 445 М.
7.11 Shell Sort | Sorting Algorithms | Full explanation with Code | DSA Course
34:07
Shell sort vs Insertion sort
6:23
udiprod
Рет қаралды 149 М.
10 Sorting Algorithms Easily Explained
10:48
Coding with Lewis
Рет қаралды 128 М.
Sorts 8 Quick Sort
9:12
RobEdwards
Рет қаралды 198 М.
Learn Merge Sort in 13 minutes 🔪
13:45
Bro Code
Рет қаралды 383 М.
2.8.1  QuickSort Algorithm
13:43
Abdul Bari
Рет қаралды 3,4 МЛН
Shell Sort - Data Structures & Algorithms Tutorial Python #18
18:33
SHA: Secure Hashing Algorithm - Computerphile
10:21
Computerphile
Рет қаралды 1,2 МЛН
The Best Band 😅 #toshleh #viralshort
00:11
Toshleh
Рет қаралды 22 МЛН