He earned an Electrical engineering degree. His education is mostly math and programming
@rockingamingwiththesahit2145
4 жыл бұрын
I'm trying my luck to be a good programmer in Python by watching this Playlist.See me in 7 years or so
@codewithbrogs3809
4 жыл бұрын
hahahah! Good luck dude
@dijasoar
11 ай бұрын
How u doing broo
@kamaboko1
5 жыл бұрын
Sure, there may be a shorter (i.e., more dry way ) to do this, but the explanation is clear. Thanks.
@malteeaser101
8 жыл бұрын
def insertion_sort(A): for j in range(1, len(A)): key = A[j] i = j - 1 while i >= 0 and A[i] > key: A[i + 1] = A[i] i = i - 1 A[i+1] = key return A
@malteeaser101
8 жыл бұрын
Based on pseudo code from 'Introduction to Algorithms' and this vid.
@dgitpadre
8 жыл бұрын
+Controversy Owl Thanks for this!
@arkoraa
8 жыл бұрын
Good stuff. Taking a[i+1] = key out of the while loop structure is non-intuitive for a beginner like me, but it is more efficient
@paulcoffee77
4 жыл бұрын
lol, the code in the video didn't work for me, unless cause i'm on 3.8 , other wise, your code worked, thanks @Controversy Owl
@Stefan-ze3bc
2 жыл бұрын
@TheTenaciousE
13 жыл бұрын
Wow I just noticed this Computer Science playlist, I'm going to be studying this in university next year, so this will be some nice preparation! Thanks a lot! =)
@venom6054
Жыл бұрын
bruh we have this shi for a levels 💀
@jasmeetsingh5425
3 жыл бұрын
Back in the day when even python required 2 lines for swapping variables. :P
@navneetbharadwaj2169
4 жыл бұрын
please add more lectures on python programming as the content quality was amazing
@Gtajora
13 жыл бұрын
I love you Sal. I truly do.
@ayushmishra-on2cs
8 жыл бұрын
plz upload some more vidoes of python...... i want to learn everything from a to z in python..and u teach awesome!
@yusufdemir9345
8 жыл бұрын
def insertionSort(alist): for index in range(1,len(alist)): currentvalue=alist[index] position=index while position>0 and alist[position-1]>currentvalue: alist[position]=alist[position-1] position-=1 alist[position]=currentvalue
@ZokioThe
7 жыл бұрын
Copy paste from interactive python
@hafzasaleem6524
3 жыл бұрын
nice sharing
@techguy8856
6 жыл бұрын
This code doesn't work on my Apple device.
@BYZ1000
12 жыл бұрын
please please please give more lectures on algorithms :)
@mauroprovatos
13 жыл бұрын
by list[i+1] = list [i wont the initial value of list[i+1] be lost forevah?
@vijy9980
3 жыл бұрын
You are the best.
@siddharthmalik7244
6 жыл бұрын
Thanks bro you nailed it.
@unordinary0054
4 жыл бұрын
Still confused...bt love Khan academy
@DrStevoXD
10 жыл бұрын
a = [5,1,7,2,8,3,9] a.sort() print a done.
@NA0S90
9 жыл бұрын
That defeats the whole purpose of writing a sorting algorithm. Sure it's easy and does everything for you. But learning how to work with lists like this is quite important..
@FatSongProduction
9 жыл бұрын
yeap. Especially if you are taking a CS course, you can't use built-in method like this. This defeats the purpose of algorithm building. Try doing this on other languages, its not easy as Python. E.g, in Python, it does 'garbage collection' auto, but in some other popular language, it don't do it auto.
@budhabagchi3097
4 жыл бұрын
Sure, use this in an interview setting and then wonder why weren’t u selected
@rck109d
13 жыл бұрын
@mauroprovatos the part of the list to the left of index never decreases left-to-right when beginning the outer for loop (because the list is sorted from left to right). You can think of the inner while loop as marching what was originally list[index] to the left as far as it needs. For each step of that loop the same value is getting assigned from right to left. So list[i+1] == value (equals) will be true. If the left list part weren't already sorted then the algorithm wouldn't be correct.
@thepurplelefant
13 жыл бұрын
i wonder how many days a week Sal has
@saipranad4609
3 жыл бұрын
almost a decade later
@Giorgio279
4 жыл бұрын
Is this available with strings instead of numbers?
@angeluffviiz8451
5 жыл бұрын
Thank you so much for explaining this in detail. There's actually a minor problem with your code. The while loop doesn't break if the second item is greater than first item. So one suggestion is that you decrement i by 1 at the end of the while loop besides the decrement of i within if function.
@mitali_com
4 жыл бұрын
I dont think it should, because it still needs to check the rest of numbers
@GarouNguyen
11 ай бұрын
Thank you
@mohammadkhalili1289
2 жыл бұрын
Very useful
@lesleymitchell1024
9 жыл бұрын
I dont understand why you decrease i... it begins with value zero then later you minus 1... confused
@heartofmilk
8 жыл бұрын
+Lesley Mitchell It begins with 1 because the range is 1 to len(list). After that, you decrement the index to look for items LEFT of the list.
@karimkaan8700
6 жыл бұрын
HE IS INTO ALL
@parthsarathidixit5648
3 жыл бұрын
Any one during covid period
@hkdobrev
12 жыл бұрын
The if statement in the loop is obsolete. It could and should be included in the while condition. This way the break statement would be avoided.
@mostafahussien9325
3 жыл бұрын
Why you say i=i-1in last line
@TheTimeDilater
4 жыл бұрын
def sort(a): A=[] for i in range(len(a)): A.append(min(a)) a.remove(min(a)) return A this is even simpler
@mathewwade4679
4 жыл бұрын
The whole point of the video is explaining the insertion sort algorithm. Else we could have just done a.sort()
@BiranchiNarayanNayak
9 жыл бұрын
I am looking for more sorting algorithms like Bubble Sort, Selection Sort, Merge Sort, Quick Sort ... etc
@tombranson9341
7 жыл бұрын
for anyone else in the future: Joe James has got it: kzitem.info/news/bejne/r6GtnH6dmHmaZ6w
@triforcelink
13 жыл бұрын
Sooo... what DON'T you do???
@toprecbot
3 жыл бұрын
Hello.
@sahajkapoor4718
6 жыл бұрын
I think we can also use this program as it is much easier than one you show def insertion_sort(slist): for i in range(1,len(slist)): currentvalue = slist[i] position = i while position>0 and slist[position-1]>currentvalue: slist[position]=slist[position-1] position = position-1 slist[position]=currentvalueslist = [14,46,43,27,57,41,45,21,70] insertion_sort(slist) print(slist) It does not need to interpreted
@enigmatichorse8
11 жыл бұрын
Thanks
@ToastHatterAbC123
7 жыл бұрын
I thought insertion sort used two lists, one unsorted and one empty (where it will sort the data). this is essentially a bubble sort...
@andersonl.sergio166
7 жыл бұрын
That's what I was thinking. As far as I know, Insertion Sort, only inserts the value in the list again when it finds its correct position and not every time the values are changed
@RTAzeh
3 жыл бұрын
this is bubble sort not insertion sort
@dumkkid
9 жыл бұрын
What if the number is 0?
@mhashmi3593
9 жыл бұрын
+Alex D Zero terminates coz it can't have any answer neither any +- sign.
Пікірлер: 71