Shell Sort - Data Structures & Algorithms Tutorial Python #18
HTML-код
- Опубликовано: 11 сен 2024
- 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'.
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
Why should someone pay to udemy, coursera etc etc. When we have good teacher like him? Definitely would recommend this to family and friends
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
This is by far the best video explaining Shell Sort
Very detailed explanation sir, thank you love from nigeria 🇳🇬
Your ability to communicate these concepts is totally out of this world! Thank you very much for the work that you're doing.
Glad it was helpful!
After surfing innumerable sources and not understanding a single shit, I am blessed to find you!
Glad it helped
Thank you so much for your effort :>
I'm studying for graduate school and I'm getting a lot of help from your videos.
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))
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.
It's absolutely fantastic series on data structures in Python. Everything got covered except selection sort and hashing in details. Thank you sir...!
I will be uploading more videos in this series and try to cover all remaining topics
@@codebasics Thank you so much sir..☺
for anyone struggling to understand the need for j, its essentially used to iterate through our shell/gap that we create each time
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.
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 .
This is the best video explaining Shell Sort
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....
Realy appreciate your idea of lecturs of DSA in python
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
Use set() in python to remove duplicate elements. I'm right ???
Amazing Video Sir HattsOff Sir
Sir can you suggest any textbook along with this course to understand more about data structures
Your videos are amazing. Could you please make some videos about Callbacks and how to use them?
Thanks for the video!
Thank you ❤️
why is the first element always ignored?
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?
shell_sort(elements)
print(list(set(elements)))
by these two lines i've got the same output of the exercise
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))).
Hello Sir, can you please create a video developing of project using only DSA ?
Hello sir, for the exercise what I did is I used the set function to remove the repeated elements. Is this a correct approach?
It will change the order of elements as in the original list
Thank!
U can explain well.
you should either code in java or c++;
*subarray -> subsequence
I generally like your videos but this is not a clear explanation.sorry
Thank you so much