Sorts 5 Shell Sort

Поделиться
HTML-код
  • Опубликовано: 8 дек 2016
  • Dr. Rob Edwards from San Diego State University summarizes shell sort - a tricky sort to get the complexity right

Комментарии • 115

  • @shinju7006
    @shinju7006 3 года назад +93

    Suppose to learn Shell sort but then I spent almost 10’ to know how learning glass works, 😂

    • @allankirui554
      @allankirui554 3 года назад +1

      How does it work?😂

    • @shinju7006
      @shinju7006 3 года назад +3

      @@allankirui554 Simply record a mirror. A mirror before them then a camera record the mirror.

    • @shinju7006
      @shinju7006 3 года назад +1

      @bismillah eng. no color

    • @ashmitchamoli781
      @ashmitchamoli781 3 года назад +11

      @@shinju7006 bruh just flip the video

    • @piyushanand7965
      @piyushanand7965 2 года назад +3

      😂😂 first record the video from oposite side to the glass then edit the video in right to left manner

  • @Tumbolisu
    @Tumbolisu 4 года назад +194

    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 года назад +12

      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 Год назад +5

      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.

  • @johnphillip9013
    @johnphillip9013 3 года назад +3

    Thank you so much for putting this on the Internet. Had problems grabbing the shell sort concept.

  • @Mars30999
    @Mars30999 3 года назад +25

    Anyone get distracted and impressed by how well he is writing in reverse?

    • @BartWillems1969
      @BartWillems1969 3 года назад +4

      And with his left hand as well!

    • @hudzell
      @hudzell 3 года назад +16

      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 2 года назад +4

      is he?

  • @FMgamer1
    @FMgamer1 6 лет назад +159

    how do you write backwards???

    • @sdagur
      @sdagur 6 лет назад +9

      Yeah ,same question??

    • @ozgunozerk334
      @ozgunozerk334 6 лет назад +67

      Its probably mirrored after the recording

    • @sebastianlacki8483
      @sebastianlacki8483 6 лет назад +38

      Stop, that makes too much sense

    • @HristoskoBG
      @HristoskoBG 6 лет назад +4

      Probably just learned to write backwards, because I suppose he has an auditory in front of him

    • @godofwinetits3826
      @godofwinetits3826 5 лет назад +59

      its another sorting algorithm

  • @Brlitzkreig
    @Brlitzkreig 2 года назад +5

    Genius idea with the glass wipeboard

  • @yesnickcarter
    @yesnickcarter 3 года назад +3

    I took Data Structures at SDSU almost 20 years ago. It was the class that changed my life. Loved it.

  • @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 .

  • @fedos
    @fedos 4 года назад +3

    Finally, an explanation that fully explains the algorithm.

  • @zerosandones701
    @zerosandones701 4 года назад +2

    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.

  • @m4h0r4ga
    @m4h0r4ga 4 года назад

    I love the presentation. Thank you very much.

  • @jans.2686
    @jans.2686 5 лет назад +12

    glad to see Jack Barker move on from his box idea into a new hobby of sorting

  • @ya00278
    @ya00278 4 года назад

    It's super clear! you deserve more likes!!

  • @jamband64
    @jamband64 6 лет назад +1

    Excellent work! Your glass presentations make comp sci concepts crystal clear

  • @XaxtonRevolution2
    @XaxtonRevolution2 2 года назад

    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.

  • @coltonbooth8633
    @coltonbooth8633 Год назад +1

    Im more impressed by how he writes backwards than anything else

  • @housemajaliwa
    @housemajaliwa Год назад

    That was wonderful to watch

  • @behmog
    @behmog 2 года назад

    Very nice method to sort numbers. Thank you. Is there any method to retrieve the original sequence of numbers from the sorted numbers?

  • @jigargadhia2093
    @jigargadhia2093 3 года назад

    how well you explained, thank you

  • @XnDxNdXnD
    @XnDxNdXnD 5 лет назад

    That was pretty intuitive explanation. Thx!

  • @olabanjistv4626
    @olabanjistv4626 6 лет назад +53

    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 лет назад +7

      yes

    • @future-daypharmacists6647
      @future-daypharmacists6647 5 лет назад

      true

    • @ElSkizzle
      @ElSkizzle 4 года назад

      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 3 года назад +11

      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).

  • @bridger4954
    @bridger4954 3 года назад +2

    Great explanation, probably the best and shortest one I've seen so far. Thank you!

  • @marcosnavarro9420
    @marcosnavarro9420 4 года назад +5

    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.

  • @xoxoo4877
    @xoxoo4877 5 лет назад +13

    you choose ---> gap=4 , then number 1 must goes in the first row (with 3, 7)

  • @IT_AvishkarBorkar
    @IT_AvishkarBorkar 3 года назад +1

    my guy is the most confusing teacher ive ever met

  • @amnahhamzah9613
    @amnahhamzah9613 3 года назад

    what is the best case?

  • @firstnamelastname4685
    @firstnamelastname4685 5 лет назад +1

    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."

  • @ishitagupta5959
    @ishitagupta5959 Год назад

    Thank you!

  • @bentroyer1
    @bentroyer1 6 лет назад +2

    how did he video tape this is that just a scary clear glass board?

  • @oggysaad1003
    @oggysaad1003 6 лет назад +8

    Very well explained sir :)

  • @user-ms3br4bh4e
    @user-ms3br4bh4e 6 лет назад

    THANK YOU!!!

  • @xoxoo4877
    @xoxoo4877 5 лет назад

    you are choosing a gap, as number of elements/2, and in every new iteration, you are dividing it with 2

  • @shariyashaikh3886
    @shariyashaikh3886 Год назад

    Thank you

  • @kurobros4791
    @kurobros4791 5 лет назад

    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

  • @giorgi23
    @giorgi23 4 года назад

    Now I understand why shell sort is not popular

  • @kailaspsudheer
    @kailaspsudheer 3 года назад

    This guy takes class like Tony stark

  • @harshitsinghai1395
    @harshitsinghai1395 6 лет назад +2

    How are these videos made ?

  • @shikharvasisht1
    @shikharvasisht1 6 лет назад +17

    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 6 лет назад +5

      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 5 лет назад +1

      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 4 года назад

      @@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 4 года назад

      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.

  • @johnpaulpineda9821
    @johnpaulpineda9821 2 года назад

    Wow! Very good explanation. Shell sort becomes easy to learn. Thanks a lot Sir!

  • @nimatagik7534
    @nimatagik7534 Год назад

    how can you write backward man ? its really hard

  • @ecksem
    @ecksem 3 месяца назад

    How are a bunch of students of a somewhat difficult engineering major freaking out about a mirrored video in the comments

  • @dakuisha5978
    @dakuisha5978 3 года назад +1

    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...

  • @welnyr
    @welnyr 3 года назад

    3:55 Element one is doubled

  • @hangchen6131
    @hangchen6131 6 лет назад

    Hahaha in the insertion sort

  • @hansu7474
    @hansu7474 5 лет назад +5

    Hm.. a lot of unanswered questions..

    • @BrennanDemarest
      @BrennanDemarest 4 года назад

      I believe if you want questions answered you'll have to take his course.

    • @hansu7474
      @hansu7474 4 года назад

      @@BrennanDemarest I don't have to. I was merely pointing out that he doesn't cover important parts in shellsort.

  • @fredtech6770
    @fredtech6770 3 года назад

    i like your blackboard.it is transparent

  • @sunnyshah9013
    @sunnyshah9013 5 лет назад +10

    is it just me or the algorithm explained here is a bit off than what shell sort is?

    • @TriachnidLOL
      @TriachnidLOL 5 лет назад +1

      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.

  • @amitshiksha
    @amitshiksha 6 лет назад +1

    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

  • @manjuegazos4672
    @manjuegazos4672 3 года назад

    Wait... there isn't 4

  • @karotto594
    @karotto594 3 года назад

    HOW ARE YOU WRITING BACKWARDS???!!

  • @sirhawkjames
    @sirhawkjames Год назад +1

    what da fuck my guy just writes backwards completely legibly casually

  • @TankNSSpank
    @TankNSSpank Месяц назад

    but why?

  • @diweiye8420
    @diweiye8420 8 месяцев назад

    Now this might be a good algorithm to think, but this is DEFINITELY NOT what shell sort it.

  • @marcelolopesdeamorimjunior9723
    @marcelolopesdeamorimjunior9723 2 года назад

    fanfic
    10/10
    \

  • @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

  • @josuejheymiticonaortiz3848
    @josuejheymiticonaortiz3848 2 года назад

    GAAA!!1

  • @MunyuShizumi
    @MunyuShizumi 3 года назад +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.

  • @srinivasasubramanyam5501
    @srinivasasubramanyam5501 3 года назад

    You missed the last swap in first round. You can't cheat me.

  • @leydensjar
    @leydensjar 4 года назад +5

    This is not a correct explanation of Shell Sort.

  • @s-.-8821
    @s-.-8821 4 года назад +3

    This is FALSE

  • @lucassmith6320
    @lucassmith6320 2 года назад +1

    This is wrong explanation go somewhere else

  • @TheNiczal
    @TheNiczal Год назад +1

    Very bad explanation and even worst example,

  • @ethan6708
    @ethan6708 5 месяцев назад

    THIS IS WRONG