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
The world changed, ppl studied and revolutionalized the world's technology; every day, a new algorithm is released and ppl try to improve themselves to become better person. Every second a person dies and borns, and yet, here I am, as always, trying to learn everything just before the night of exams... some things never changed... and your videos have helped me a lot. Thank you for the hard work!
well I tried it by myself first ,wrot a 30-35 lines of code still was'nt able to pull this off , and you did it in within 5-6 lines truly amazing love your videos.
i'm watching his data structures and algorithms playlist before taking a data structures and algorithms course.... failed it the first time but i think that i will pass this time, his videos are super helpful
my solution to exercise def insertion_sort(element): total = 0 for i in range(len(element)): for x in range(i): if element[i] < element[x]: element.insert(x,element.pop(i)) break if i%2 ==0: index = i/2 print(element[int(index)]) else: index = i//2 print((element[int(index)] + element[int(index)+1]) /2)
Hi Dhaval, We can write sort function in this way as well, it passed the edge cases, let me know if you found any bug in this: def insertion_sort(lst): for i in range(len(lst)): for j in reversed(range(i)): if lst[j+1] < lst[j]: lst[j+1], lst[j] = lst[j], lst[j+1] return lst
Hi Sir, your videos are explanatory and quite informative. I request you to kindly share other sorts such as shell sort, comb sort, counting sorts etc as well.
another approach : def insertion_sort(arr): new_arr = [arr[0]] for i in arr[1:]: if new_arr[0] > i: new_arr.insert(0,i) continue elif new_arr[len(new_arr)-1] < i: new_arr.append(i) continue else: for idx , k in enumerate(new_arr): if k > i: new_arr.insert(idx,i) break return new_arr
I am 60 years old in Canada. I started learning coding 2 months ago. Does this work? import statistics my_list = [] elements = [2,1,5,7,2,0,5] for i in range(len(elements)): my_list.append(elements[i]) print(statistics.median(my_list)) Thank you so much.
Bubble sort checks from the first element if the first number is greater than the second then swaps the first number with the second and continues like that
my code for insertion sort: def insertion_sort(element): for i in range(len(element)): for x in range(i): if element[i] < element[x]: element.insert(x,element.pop(i)) break
For the exercise, I'm not that sure if i'm correct or not. Shouldn't the quotient of len(array) % 2 == 0 instead of 1. Can someone please confirm which is correct?
Sir, thank you for such an amazing series so far. In this video's exercise, I don't think the problem statement is consistent with the output expected or the solution given. Can you please check it and let me know if I'm wrong?
Can any one pls explain the solution of the problem which was given i was not able to solve it. and cant understand the solution code provided by daval sir
import statistics unSortedArray=[2,1,5,7,2,0,5] index=0 for i in range(len(unSortedArray)): current=unSortedArray[i] j=i-1 while j>=0 and unSortedArray[j]>current: unSortedArray[j+1]=unSortedArray[j] j=j-1 index+=1 print(statistics.median(unSortedArray[:index])) unSortedArray[j+1]=current print(unSortedArray) For beginner
#implementing the insertion sort in python a=list(map(int,input().split())) m=[] for i in a: c=0 for j in range(len(m)): if m[j]>i: m.insert(j,i) print(m) c+=1 break if c==0: m.append(i) print(m) print(m)
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
The world changed, ppl studied and revolutionalized the world's technology; every day, a new algorithm is released and ppl try to improve themselves to become better person. Every second a person dies and borns, and yet, here I am, as always, trying to learn everything just before the night of exams... some things never changed... and your videos have helped me a lot. Thank you for the hard work!
Same here :)
Thank You Sir. I just completed the whole Data Structure and Algorithms Playlist. Your videos are very informative and well explained.
👍😊
well I tried it by myself first ,wrot a 30-35 lines of code still was'nt able to pull this off , and you did it in within 5-6 lines truly amazing love your videos.
why am I paying to attend university , when I get classes like this !! This series is really helpful!!
👍😃
i'm watching his data structures and algorithms playlist before taking a data structures and algorithms course.... failed it the first time but i think that i will pass this time, his videos are super helpful
@@jonathanmeza5807 All the best !
ruclips.net/video/lzS_DiMlR2Q/видео.html
ruclips.net/video/lzS_DiMlR2Q/видео.html
My best part was the very last commentary, I'm cracking up. Greate Video!!
4:45 sampoornesh babu rocks
Just finished the whole series. Very informative. Thank you very much.
my solution to exercise
def insertion_sort(element):
total = 0
for i in range(len(element)):
for x in range(i):
if element[i] < element[x]:
element.insert(x,element.pop(i))
break
if i%2 ==0:
index = i/2
print(element[int(index)])
else:
index = i//2
print((element[int(index)] + element[int(index)+1]) /2)
Very helpful Sir. Looks like you are continuing both the Dara Structures and Deep Learning series. Thank you sir😁
yup those are my two active series right now
In every video,i will laugh in middle..that is the beauty of your videos...loved it..
👍🏼😀
Thank you Sir. 🙏🙏
Very helpful and detailed explaination and also easy to understand. 🙏🙏
If this would have been pretty big unsorted list then which algorithm you would have suggested?
your powerpoint skills seems so good, can you make a powerpoint tutorial on how you make these slides in powerpoint it would be really helpful
beautiful piece......Just found it difficult understanding the question in the exercise
exercise
def insertion_sort(arr):
for i in range(1, len(arr)):
count = i
while count > 0 and arr[count - 1] >= arr[i]:
count -= 1
arr.insert(count, arr.pop(i))
a = len(arr)
return arr[int(a / 2)] if a % 2 == 1 else (arr[int(a / 2)] + arr[int((a / 2) - 1)]) / 2
# for median
if __name__ == '__main__':
elements = [9, 5, 3, 2, 1, 10, 11, 12]
print('median: ' ,insertion_sort(elements))
print(elements)
Hi Dhaval, We can write sort function in this way as well, it passed the edge cases, let me know if you found any bug in this: def insertion_sort(lst):
for i in range(len(lst)):
for j in reversed(range(i)):
if lst[j+1] < lst[j]:
lst[j+1], lst[j] = lst[j], lst[j+1]
return lst
is this bubble sort?
Hey, I know this was posted a while ago but can you confirm if this is the right way to do insertion sort?
@@justsomerandomguy6719 running nested loops is not optimal his method is correct however it's not optimized.
@@marshai8611 okay. Thank you for your insight.
It's most beautiful video on DSA actually your explanation makes us motivated learn best practice of Software Industry
Thanks Vinay :)
Hi Sir, your videos are explanatory and quite informative. I request you to kindly share other sorts such as shell sort, comb sort, counting sorts etc as well.
Self-note: tricky concept, come back and review again.
You are a phenomenal teacher, thank you so much. And hilarious lol
we can also use two pointer approach that will be more optimizing and better approachable method
I can't tell you what pain I went through to solve the exercise on my own. Took me 3 hours of trial and error.
I am confused why worst case performance is n^2 ?
another approach :
def insertion_sort(arr):
new_arr = [arr[0]]
for i in arr[1:]:
if new_arr[0] > i:
new_arr.insert(0,i)
continue
elif new_arr[len(new_arr)-1] < i:
new_arr.append(i)
continue
else:
for idx , k in enumerate(new_arr):
if k > i:
new_arr.insert(idx,i)
break
return new_arr
I am 60 years old in Canada. I started learning coding 2 months ago. Does this work?
import statistics
my_list = []
elements = [2,1,5,7,2,0,5]
for i in range(len(elements)):
my_list.append(elements[i])
print(statistics.median(my_list))
Thank you so much.
Did it work
Is below code is sufficient
How is it different than Bubble Sort ?
Bubble sort checks from the first element if the first number is greater than the second then swaps the first number with the second and continues like that
i love your exercises!!!!!!!!!!! sir thank you
Hello Sir, can you please create a video developing of project using only DSA ?
my code for insertion sort:
def insertion_sort(element):
for i in range(len(element)):
for x in range(i):
if element[i] < element[x]:
element.insert(x,element.pop(i))
break
This gives u time Complexity of O(n^2) ,
4:42 jai samppornesh babu 😂😂
For the exercise, I'm not that sure if i'm correct or not. Shouldn't the quotient of len(array) % 2 == 0 instead of 1. Can someone please confirm which is correct?
Sir, thank you for such an amazing series so far. In this video's exercise, I don't think the problem statement is consistent with the output expected or the solution given. Can you please check it and let me know if I'm wrong?
very good explanation. can you please provide the PPT
I confused, We have builtin sort function in python so why we need that too much code.
My dear friend,This class only for understanding how the sorting function works,
In future we cannot implement this method because it is O(n**2)
But why j = j-1
ok so we give the exercise a try and then how do we check your code solution after? is there a link?
Check video description. When you .md file with exercise description at the end there is blue solution link. You just click on that
Can any one pls explain the solution of the problem which was given i was not able to solve it.
and cant understand the solution code provided by daval sir
import statistics
unSortedArray=[2,1,5,7,2,0,5]
index=0
for i in range(len(unSortedArray)):
current=unSortedArray[i]
j=i-1
while j>=0 and unSortedArray[j]>current:
unSortedArray[j+1]=unSortedArray[j]
j=j-1
index+=1
print(statistics.median(unSortedArray[:index]))
unSortedArray[j+1]=current
print(unSortedArray)
For beginner
we double the array size without using an extra array, what a spectacular idea right
Thank you sir
thank you so much
Sir please make more videos on ds algo topic
anyone else learning these in the era of CHATGPT ?
Sir your exercise solutions should contain comments else its difficult to interpret your thought process
sir please continue uploadin
Yes next one on merge sort coming soon
Why do we reduce j by 1 in the end? 🥺
As the loop is going backwards for checking the elements we are reducing j by 1
Is this the last topic Or still topics are their to upload please reply?
I will be uploading mor videos
7:48 lmao😂😂😂😂😂
#implementing the insertion sort in python
a=list(map(int,input().split()))
m=[]
for i in a:
c=0
for j in range(len(m)):
if m[j]>i:
m.insert(j,i)
print(m)
c+=1
break
if c==0:
m.append(i)
print(m)
print(m)
Sir, Hindi m video bnao
Yes sir
that moving gif is creepy and annoying,
Point noted.
you really need to stop seeing memes!!!!!!!!
i watched it at 1.75 x and it still feels slow , come on man, just get to the f* point.
thank you sir