Shell Sort - Data Structures & Algorithms Tutorial Python #18

Поделиться
HTML-код
  • Опубликовано: 7 фев 2025
  • Shell sort is a customization over insertion sort. Insertion sort requires many swaps and comparisons if heavy elements are located towards the end of an array. Shell sort will initially sort subarrays that are equal distance apart. The distance here is referred to as a gap. We will than keep on reducing the gap until it is 1. With gap=1 it becomes insertion sort but this time due to optimization we have performed earlier, sorting the array would require very less comparisons and element swaps.
    Code: github.com/cod...
    Exercise: github.com/cod...
    Data structures and algo in python playlist: • Data Structures And Al...
    🔖Hashtags🔖
    #Shellsort #datastructures #algorithms #python #Shellsortpython #sortalgorithm #pythonShellsort #Shellsort #datastructure #Shellsortcode #Shellsortprogram
    Do you want to learn technology from me? Check codebasics.io/ for my affordable video courses.
    Website: codebasics.io/
    Facebook: / codebasicshub
    Twitter: / codebasicshub
    Linkedin: / codebasics
    Discord: / discord
    DISCLAIMER: All opinions expressed in this video are of my own and not that of my employers'.

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

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

    Do you want to learn python from me with a lot of interactive quizzes, and exercises? Here is my project-based python learning course: codebasics.io/courses/python-for-beginner-and-intermediate-learners

  • @surajvijay1937
    @surajvijay1937 4 года назад +18

    Why should someone pay to udemy, coursera etc etc. When we have good teacher like him? Definitely would recommend this to family and friends

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

    This is by far the best video explaining Shell Sort

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

    After surfing innumerable sources and not understanding a single shit, I am blessed to find you!

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

    Your ability to communicate these concepts is totally out of this world! Thank you very much for the work that you're doing.

  • @헬롱-g1s
    @헬롱-g1s Год назад +1

    Thank you so much for your effort :>
    I'm studying for graduate school and I'm getting a lot of help from your videos.

  • @mohammadpatel2315
    @mohammadpatel2315 3 года назад +5

    Below is my code to the exercise: works nicely without creating a separate array to keep track of the index, deletes duplicates on the fly. Thanks for the video and the short exercises at the end of each video.
    def shell_sort(arr):

    size = len(arr)
    i = 0
    gap = size//2
    while gap > 0:
    i = 0
    while(i

  • @GeneralShark-404
    @GeneralShark-404 Год назад +1

    Very detailed explanation sir, thank you love from nigeria 🇳🇬

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

    You're an amazing teacher, thank you so much. All of the other videos were not helpful

  • @mahesht6055
    @mahesht6055 4 года назад +1

    It's absolutely fantastic series on data structures in Python. Everything got covered except selection sort and hashing in details. Thank you sir...!

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

      I will be uploading more videos in this series and try to cover all remaining topics

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

      @@codebasics Thank you so much sir..☺

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

    A Big thanks for your playlist...... It really helped me to understand the dsa concept in python
    The code for the exercise. I hope it help others
    def shellsort(arr):
    size=len(arr)
    gap=size//2
    while(gap>0):
    for i in range(gap,len(arr)):
    anchor=arr[i]
    j=i
    while(j>=gap and anchor=2:
    x.remove(j)
    c-=1
    for i in element:
    print(shellsort(i))

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

    for anyone struggling to understand the need for j, its essentially used to iterate through our shell/gap that we create each time

  • @RohitKumar-dz8dh
    @RohitKumar-dz8dh 2 года назад +2

    Thank you so much sir . I have completed the exercise you have given for Shell sort but the main thing i learnt in this exercise is difference between "for loop and while loop" i.e Lazy evaluation . I solved this exercise by using while loop on deleting index on same array if any duplicate value occured.

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

    This is the best video explaining Shell Sort

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

    better explained that in my university, it was looking so complicated but its actually easy

  • @younesizeria4375
    @younesizeria4375 2 года назад +2

    guys i know it's weird to talk about that here in a programation video but i have been watching this playlist from a long ago and been reading some of your comments, and I am feeling toward you like kind of classroom mates haha, and I am gonna address my paroles to all people looking for the truth behind the universe and God and the purpose of life, my man and my sis !! there is an after-life and we will all face our God ''Allah'' after we die, that's a thing we should be aware of, so at that case we must review our self and our duties toward our God, our selves and our family, etc. you and me remember this point. if you heard about religions, maybe you had some stereo type about Islam that it's a bad religion but bro all other religions are based on people opinions and their desires except the Islam is the only true religion that if you follow you will succeed both in life and after-life.... So, if you are looking for the truth of the universe, I am gonna advise you to read Quran to see the truth all of it. the Quran is the God's paroles and instruction to succeed.... and also go read about the prophet Muhammed the best of all humanity, how he sacrificed all his life for us next generations to know the true meaning of life together with his friends, and how he turned the Saudi island from a small retarded village to a big nation with a great story of success .

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

    In for loop it will be (gap, size,gap) .else it will start with gap doing comparisons till end la. So it will same as insertion sort.

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

    Realy appreciate your idea of lecturs of DSA in python

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

    Thanks for the video!

  • @ganesh.majety5260
    @ganesh.majety5260 4 года назад +1

    Thank you ❤️

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

    Thank!

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

    U can explain well.

  • @Anushka-or9ih
    @Anushka-or9ih 4 месяца назад

    When the gap was reduced to 1 ,
    Only 4 and 9 got sorted ... but 38 and 32 remained unsorted only ...
    So in this example , the last step involves 2 swaps ?

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

    Use set() in python to remove duplicate elements. I'm right ???
    Amazing Video Sir HattsOff Sir

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

    def shell_sort(a):
    size=len(a)
    gap=size//2
    while gap>0:
    for x in range(gap,size):
    j=x-gap
    if a[j]>a[x]:
    temp=a[j]
    a[j]=a[x]
    a[x]=temp
    gap-=1
    # it's work
    this is right? or anything problem here....

  • @Sayonora
    @Sayonora 6 месяцев назад

    For exercise, can't I use set on the list to remove duplicates??
    edit: I can't as it can't index addressed, though I used set(x) then list (X) in some places and it worked

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

    Your videos are amazing. Could you please make some videos about Callbacks and how to use them?

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

    shell_sort(elements)
    print(list(set(elements)))
    by these two lines i've got the same output of the exercise

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

      Man the point is doing it by an algorithm. Otherwise, you can also use the sort()/sorted(*args) function in order to sort the list :) you can do it in one line print(sorted(list(set(elements))).

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

    why is the first element always ignored?

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

    Hello Sir, can you please create a video developing of project using only DSA ?

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

    Sir can you suggest any textbook along with this course to understand more about data structures

  • @AbdullahAnsir-y4c
    @AbdullahAnsir-y4c 3 месяца назад

    It solution is just convert in set

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

    *subarray -> subsequence

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

    you should either code in java or c++;

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

    Hello sir, for the exercise what I did is I used the set function to remove the repeated elements. Is this a correct approach?

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

      It will change the order of elements as in the original list

  • @siddharthnahata757
    @siddharthnahata757 4 года назад +1

    Can i learn data structures and algorithms in python? Is it helpful? Or should i prefer java for data structures for coding round in interviews?

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

    I generally like your videos but this is not a clear explanation.sorry

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

    Thank you so much