Sorting Algorithm | Shell Sort – step by step guide

49
2



In this video we will learn about Shell Sort algorithm.

Shell Sort Code

Algorithm Playlist

Data Structure Playlist

Heap Sort

Quick Sort

if you find my videos interesting and enjoy watching them then please give a thumbs up, share and subscribe my channel and comment.

click the following link to subscribe my channel

thanks for watching
see you in the next video
stay happy and keep smiling 🙂

Nguồn: https://khudothidongvan.com/

Xem thêm bài viết khác: https://khudothidongvan.com/cong-nghe/

49 COMMENTS

  1. If we are going to end up with an Insertion Sort at the last pass anyway, why are we doing this at all? To reduce number of swaps during the Insertion Sort at the end?

  2. I don't get it.. after he reaches "end" he goes back to compare other elements before going for pass 2 and 3? What decides that?

  3. the best explanation ever.im learning in Chinese and when the lecturer was teaching it was all weird.good video

  4. I searched everywhere. Thank you for this helpful explanation. 🙂
    Note: What helped me understand this is that this works similarly to Insertion Sort.

  5. please increase the speed of your video and also add sound. But still the algorithm is easy to understand.

  6. Hi, do you mean that it uses the same concept as the BUBBLE sort, rather than the INSERTION sort? These are two different types of sorting methods if I am not mistaken.

  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<n;i++) // To go though all the element distant at specified gap
    {
    int j;
    int temp=a[i];
    for(j=i;j>=gap&&temp<a[j-gap];j=j-gap) //Element swapping in case of greater element exist prior to smaller element in list
    {
    a[j]=a[j-gap];
    }
    a[j]=temp;
    }
    }

    }

  8. VISIT HOME PAGE: http://cprogramaboutexample.blogspot.in/
    DATA STRUCTURE: http://cprogramaboutexample.blogspot.in/2017/07/data-structure.html
    BEGINNER PROGRAMMER & COMPUTER SCIENCE STUDENTS FOR

  9. why make a video if not saying anything………we can read from a websitre or book!!!! we come here to get better explanation

  10. Note that the performance of Shell sort depends very much on the gap function used. In the video he uses 2^n as the the gap function which is not a very good function since it compares odd positioned elements only in the end. Better go with Knuth's function (3n – 1) which performs way better than this one.

  11. thank u ..
    i implement shellsort method after watching your video ..
    template <typename T>
    void ShellSort(T arr[],int size){
    int gap;
    int firstgap=0;
    int endgap=0;
    gap=floor(size/2); // calc gap
    firstgap=0;
    endgap=gap; // end gap
    int index;
    while (gap>0){ // we will divide gap until gap be less then zero gap=gap/2
    while(endgap<size){ // we increment endgap till reach size
    if (arr[firstgap]>arr[endgap]){ // compare between firstgap and endgap if first bigger swap
    T temp=arr[firstgap];
    arr[firstgap]=arr[endgap];
    arr[endgap]=temp;
    int i=firstgap;
    index=i;
    while (i>=0){ // we still need to compare all otherside gap
    if (arr[i]<arr[index])
    break;
    else if (arr[i]>arr[index]) {
    T temp=arr[i];
    arr[i]=arr[index];
    arr[index]=temp;
    index=i;
    }
    i-=gap;
    }
    }
    endgap++;
    firstgap++;
    }
    gap=gap/2;
    firstgap=0;
    endgap=gap;
    }
    }

  12. Man i wish you were my university teachers. Iface a lot of problems in C. Let me know if you can take some online classes.

LEAVE A REPLY

Please enter your comment!
Please enter your name here