Insertion Sort Algorithm Explained (Full Code Included) - Python Algorithm Series for Beginners

แชร์
ฝัง
  • เผยแพร่เมื่อ 21 ก.ย. 2024

ความคิดเห็น • 136

  • @maanyapuri8311
    @maanyapuri8311 4 ปีที่แล้ว +86

    Oh god, you explain this way better than my Software teacher. Thank you so much!

  • @Caimille
    @Caimille ปีที่แล้ว +7

    Thank you so much for your video! I was having a hard time understanding the insertion sort algorithm and now I have a much better handle on it.

  • @Aflesyn
    @Aflesyn 4 ปีที่แล้ว +11

    I fell in love with your tutorials, thank you very much for your work! you also have an amazing voice, which makes watching videos especially enjoyable. Love, Jam

  • @b.f.skinner4383
    @b.f.skinner4383 3 ปีที่แล้ว +17

    This is the first sorting algorithm I've attempted to learn, this video has been a tremendous help. Thank you

  • @timohelasvuo9650
    @timohelasvuo9650 5 ปีที่แล้ว +17

    Thanks for the video! Another golden nugget :)

  • @peterfrancisrobante8830
    @peterfrancisrobante8830 3 ปีที่แล้ว +1

    having an explanation that only takes a minute is the best. keep it up!!

  • @abhinandanmohanty3833
    @abhinandanmohanty3833 3 ปีที่แล้ว +10

    Can you please explain why i=i-1 make the next iteration??

    • @arunbalakrishnan8978
      @arunbalakrishnan8978 5 หลายเดือนก่อน

      That is moving towards left side in sorted list to check where should we insert the current unsorted element.

  • @moritzwolff9383
    @moritzwolff9383 4 ปีที่แล้ว +6

    There is an implementation of insertion sort that is almost twice as fast:
    def insertion(list):

    for i in range(1,len(list)):
    temp = list[i]
    index = i - 1

    while index >= 0 and list[index] > temp:
    list[index + 1] = list[index]
    index -= 1
    list[index + 1] = temp
    return list
    This is because Derricks implementation needs almost twice as many steps for each iteration of the while-loop compared to the implementation proposed here (two assignment statements: list_a[i] to list_a[i-1] and vice versa). You can confirm this for yourself comparing the running times of both implementations: you will see that the second implementation is almost twice as fast.

    • @stillbald5827
      @stillbald5827 4 ปีที่แล้ว

      This is pretty clever. Thanks!

  • @Captainfeso
    @Captainfeso 4 ปีที่แล้ว +6

    You explained this so well! Even a 10 year old would understand!

  • @naitikmundra8511
    @naitikmundra8511 3 ปีที่แล้ว +24

    Hey guys, optimized version of the code:
    def insertion_sort(list_to_be_sorted):
    for i in range(1, len(list_to_be_sorted)):
    key = list_to_be_sorted[i]
    j = i - 1
    while j >= 0 and key < list_to_be_sorted[j]:
    list_to_be_sorted[j + 1] = list_to_be_sorted[j]
    j -= 1
    list_to_be_sorted[j + 1] = key
    return list_to_be_sorted

    • @MrKB_SSJ2
      @MrKB_SSJ2 ปีที่แล้ว

      This code really is good. Thanks a lot !

  • @emeryli2331
    @emeryli2331 3 ปีที่แล้ว +1

    i love your voice, it's so calm, clear and comfortable

  • @swatiruhela655
    @swatiruhela655 2 ปีที่แล้ว +3

    So nice explanation .. I was finding insertion sort very tough , but your interpretation made me easy to understand .. Thanks a lot Derrick..

  • @naiadbaksh3996
    @naiadbaksh3996 3 ปีที่แล้ว

    As much as your explanations are great, your editing makes these videos a cut above the rest! That green screen (?) at the beginning is just *chef's kiss*

  • @huzaifaalam1328
    @huzaifaalam1328 3 ปีที่แล้ว

    Can't believe i understood all of it in less than 6 minutes THANK YOU

  • @nathanellis7819
    @nathanellis7819 4 ปีที่แล้ว +6

    Thank you mate. These are great!

  • @HanisaMohamed
    @HanisaMohamed 4 ปีที่แล้ว +1

    I can always rely on your videos to give a good explanation! Thanks!!!

  • @Maks-wp2wj
    @Maks-wp2wj 4 ปีที่แล้ว +4

    I dont really understand what " i = i - 1" stands for. Coz the only thing i can actually see, is we subtract 1 from "i" each time, which makes us to stay at the same exact number everytime. Can someone please this like you would do it for a child? Thank you

    • @parthbhodia9575
      @parthbhodia9575 3 ปีที่แล้ว

      same doubt

    • @cosmicbandido8186
      @cosmicbandido8186 3 ปีที่แล้ว

      @Maks Have exactly the same question. unfortunately you didnt get an answer

    • @kushalpaudel4802
      @kushalpaudel4802 หลายเดือนก่อน

      In the top level loop, we are moving left to right, where we are accepting one new element from unsorted part of list to sorted and on second level loop, we are comparing between the numbers in the sorted part of the list that why we use i = i -1

  • @shivaay.4565
    @shivaay.4565 11 หลายเดือนก่อน +1

    KNOWLEDGEABLE CONTENT KEEP IT UP BROTHER😎 #I AM FROM INDIA

  • @mohammadaltaha8386
    @mohammadaltaha8386 4 ปีที่แล้ว +3

    YOU ARE A LEGEND!
    Thank you so much

  • @harshyadav1214
    @harshyadav1214 9 หลายเดือนก่อน +1

    Great Content man

  • @AmanSharma-ht5zq
    @AmanSharma-ht5zq 4 ปีที่แล้ว +2

    Thank you so much, bro. I see the neatest codes in your videos. Keep making videos on more difficult topics.

  • @nitesharu1269
    @nitesharu1269 3 ปีที่แล้ว +2

    It's confirm now, every guy with a dead face and freakin light speed brain is a developer

    • @studiesonly565
      @studiesonly565 3 ปีที่แล้ว

      Yeah...they said learning to code was free but took away my childhood :/

  • @SuperBhavanishankar
    @SuperBhavanishankar 3 ปีที่แล้ว +2

    Hi. can we do as simple as:
    for i in range(0,len(lst)):
    while (lst[i-1]>lst[i] and i>0):
    lst[i-1],lst[i]=lst[i],lst[i-1]
    i-=1
    print(lst)

  • @indianyoyoer
    @indianyoyoer 4 ปีที่แล้ว +25

    Who else watching from india 🇮🇳

  • @sahilnagpal007
    @sahilnagpal007 4 ปีที่แล้ว +1

    Dude you are awesome, believe me, and mark my words.

  • @kvelez
    @kvelez ปีที่แล้ว

    This is the best video, I finally understood it. You made it very easy, I'll subscribe.
    I recreated it, hope it looks good:
    list = []#list
    limit = int(input("Amount of elements to sort? "))#only int
    for _ in range(limit):#repetition
    item = input("Type the element: ") #int or str
    list.append(item)#addition to the list
    for i in range(1,len(list)):#looping through list
    value_to_sort = list[i]#element to the right.
    while list[i-1] > value_to_sort and i > 0: #compare left to right elements
    list[i-1], list[i] = list[i], list[i-1] #Ascending
    # list[i-1], list[i] = list[i], list[i-1] #Descending
    i -=1
    print("List: ", list) #output

  • @kunalmeshram2323
    @kunalmeshram2323 2 ปีที่แล้ว

    I just went through 10 videos but this video is just got throw too my head and other's were bounces over 🤣 thanks man

  • @verceti7
    @verceti7 4 ปีที่แล้ว +2

    You're awesome dude! Thanks! Keep the videos up

  • @kilsat5030
    @kilsat5030 4 ปีที่แล้ว +2

    So Good. Keep Going Bro

  • @emmanuelugwu918
    @emmanuelugwu918 2 ปีที่แล้ว

    if i could like this video a million times i would.. thank you soo much

  • @sambhavbhalla2697
    @sambhavbhalla2697 3 ปีที่แล้ว +1

    Hey , this helped me a lot , but I still couldn't figure out one thing , why you wrote i = i -1. I didn't understand this line of code, could you help me out?

  • @zaedis5629
    @zaedis5629 3 ปีที่แล้ว

    Thank you so much. The material I was given to teach me this only explained the concept and didn't explain the example code at all.

  • @abdullahshahid6216
    @abdullahshahid6216 3 ปีที่แล้ว +1

    This has the best time and space complexity
    Run this code into Pythontutor to understand
    for i in range(1,len(arr)):
    current = arr[i]

    while i > 0 and arr[i-1] > current:
    arr[i] = arr[i-1] # shifting larger number to the right
    i= i-1
    arr[i] = current

  • @Aflesyn
    @Aflesyn 4 ปีที่แล้ว +2

    really want to see merge sort & depth-first search by you! such a cool explanation

  • @jessijasa
    @jessijasa ปีที่แล้ว

    Thanks for the video! Very pleasant to watch. You explained everything in detail.

  • @nellamain5744
    @nellamain5744 ปีที่แล้ว

    THANK YOU YOU'RE SO GOOD AT EXPLAINING.

  • @adeli583
    @adeli583 4 ปีที่แล้ว +5

    quick question: at the end why it is i = i - 1 instead of i = i + 1 ??

    • @aditim7430
      @aditim7430 4 ปีที่แล้ว

      i have the same doubt... so if you get the answer pls let me know as well

    • @plackowsky4198
      @plackowsky4198 4 ปีที่แล้ว +8

      Because that while loop works like this : if value at index i is smaller than value at i-1 it switches places. Then we need to check if our original value at i (actual i-1) is maybe smaller than value at i-2. And so it goes until our original value is greater than value at index i on the left. Then if our value is greater than the one with index-1 we exit while loop and get to the next value. Sorry if i mispelled something wrong, i understood this code today :p

    • @jackzero5230
      @jackzero5230 3 ปีที่แล้ว +1

      @@plackowsky4198 you have explained it very well, infact @Derric Sherrill missed it, thanks Bro!

  • @divyanshgupta748
    @divyanshgupta748 4 ปีที่แล้ว +1

    This is sooo nicely explained. Thanks.

  • @no0gon
    @no0gon 4 ปีที่แล้ว +1

    this is what i looking for similar to macro SAS and i can test in python, thank you for your guide sensei

  • @sagarsingh-jv5fn
    @sagarsingh-jv5fn 2 ปีที่แล้ว

    Simplest explantion avaliable online, Thanks!

  • @alenjose3903
    @alenjose3903 หลายเดือนก่อน

    wouldnt this algorithm keep decrementing the value of x even though it is clear no more checking is required in that particular iteration ?

  • @amulyatiwari3019
    @amulyatiwari3019 3 ปีที่แล้ว

    Man, what a jawline!!

  • @shrvansudhakar7514
    @shrvansudhakar7514 3 ปีที่แล้ว

    thanks a lot Derrick, please keep on doing gr8 stuff.

  • @rhondan181
    @rhondan181 ปีที่แล้ว

    Great vid, thank you!

  • @guilhermesanchez9051
    @guilhermesanchez9051 4 ปีที่แล้ว +1

    That was really helpful. Thanks

  • @fourten0410
    @fourten0410 3 ปีที่แล้ว +4

    Outstanding content, very clear and organized, thank you!

  • @jimmygizmo
    @jimmygizmo 2 ปีที่แล้ว +1

    People who produce coding tutorials can learn a lot of excellent things from how you do yours. Thanks for the great videos! I think this series is great. Some requests for your next videos in this series (more for keeping a nice set of algos for your viewers rather than my own needs) .. but I think it would be nice to add maybe some of these: Linked List, Tree Traversal (maybe in the context of walking a directory structure. in other words, DAGs, Directed-Acyclic Graphs), maybe also parsing of tag pairs like matching parentheses or brackets or similar, since this basically is a common and juicy little application of stacks, pushing/popping arrays etc. My suggestions are coming from algorithms I was tested on during assessments at Apple, Google and Yahoo for senior roles, but also those are elegant ones I like and can be either simple or very challenging so there is a lot to work with in those. Again, thanks a lot for the excellent videos. The content, presentation and topics are excellent and also, I really love the visuals, colors and fonts etc. No time wasted on irrelevant content. You've removed all the barriers to learning the quality content in an enjoyable, fast way and that is what it is all about. One final thought. For getting a job, people must master as many of the popular algorithms as they can. The best jobs always hinge on this, regardless of experience level. (I'm not saying that's how it should be but that is the reality of algorithms and software engineering jobs.)

  • @Tory_Rainman
    @Tory_Rainman 2 ปีที่แล้ว

    Nice video man, thank you for the clarity

  • @Metrotouille2243
    @Metrotouille2243 3 ปีที่แล้ว

    Thanks! was struggling to understand this one, but it was so simple!

  • @GeronimoLTondato
    @GeronimoLTondato 2 ปีที่แล้ว

    Not going to code it but you can use binary search to find the position for "value_to_sort" into the sorted array. That way the algorithm performs at O(n+log(N)), of course, you also need to leave gaps between the sorted elements to prevent new insertions to trigger array shifting.

  • @robertomanrique8004
    @robertomanrique8004 2 ปีที่แล้ว

    Thank you bro for these python algorithm, great explained, please bro if you might do more videos of this topic 'Python Algorithm Series for Beginners', I'll apreciate it a lot.

  • @zakiquereshy3170
    @zakiquereshy3170 4 ปีที่แล้ว

    So much better than my professor !

  • @kenjikakashi
    @kenjikakashi 2 ปีที่แล้ว

    Love your explanation. Please keep making more videos like this

  • @prasadxev
    @prasadxev 11 หลายเดือนก่อน

    great explanation

  • @estebanlopez8927
    @estebanlopez8927 2 ปีที่แล้ว

    I would like to congratulate you on your hands

  • @kenadams9024
    @kenadams9024 3 ปีที่แล้ว +3

    Hey! Thankyou so much for the wonderful tutorial. I got the concept but I'm having a small doubt that If we are going ahead in the list shouldn't it be i = i + 1 as we are going to the next element?

    • @mohameduvais1821
      @mohameduvais1821 3 ปีที่แล้ว

      for loop will take care of traversing through the list. i=i-1 is to compare the element from the unsorted list to sorted list one by one(it will move in left direction)

    • @sambhavbhalla2697
      @sambhavbhalla2697 3 ปีที่แล้ว +1

      @@mohameduvais1821 but the for loop moves to the right , so idk this is confusing didnt understand that part

    • @CRISTIANO18786
      @CRISTIANO18786 2 ปีที่แล้ว

      @@sambhavbhalla2697 essentially the while loop is a makeshift nested for loop. So for every iteration of the outer loop (the for loop) we are moving forward in the sequence and and we want to find the right slot for the current item therefore in the while loop we are going backwards or leftward so that we can check the current element against all elements that have already been sorted and find the correct spot. It seems to be rather inefficient tho, given its time complexity is O(n^2) worst case because you appear to have the identity 1+2+3+... n

  • @kanechulchulikpongse9549
    @kanechulchulikpongse9549 4 ปีที่แล้ว +1

    why do we need to impose i>0? and i=i+1 works?

  • @dantedt3931
    @dantedt3931 3 ปีที่แล้ว

    Great explanation, thanks.

  • @samuel2318
    @samuel2318 2 ปีที่แล้ว

    clear explanation, thank you

  • @TheTeenKitchen
    @TheTeenKitchen 4 ปีที่แล้ว +2

    Great! Can you teach insertion sort program without function?

    • @Narendiranath
      @Narendiranath 4 ปีที่แล้ว

      Without function then you need to directly provide the list instead of the function. millioninformations.com

    • @καλαμ
      @καλαμ 4 ปีที่แล้ว

      @@Narendiranath That's an easy way to get your email spammed

    • @Narendiranath
      @Narendiranath 4 ปีที่แล้ว

      @@καλαμ Thanks

    • @καλαμ
      @καλαμ 4 ปีที่แล้ว

      @@Narendiranath No worries.

  • @KM-nx5sh
    @KM-nx5sh 4 ปีที่แล้ว +1

    Thanks so much !

  • @ameerhbaig
    @ameerhbaig 3 ปีที่แล้ว

    great explanation. Thanks!

  • @mohammadalagha1582
    @mohammadalagha1582 2 ปีที่แล้ว

    Does this work for strings too? I want to sort a list alphabeticly

  • @danigetpeace3514
    @danigetpeace3514 ปีที่แล้ว

    Thankyou Very much

  • @cigxhang486
    @cigxhang486 2 ปีที่แล้ว

    why is it i = i - 1 instead of i = i + 1?Aren't we going to the right to check?

  • @handle-2
    @handle-2 3 ปีที่แล้ว

    how does line 8 exactly work? I know you said it swaps them but how

  • @michaelscarn7375
    @michaelscarn7375 3 ปีที่แล้ว

    Seems like indexing_range should be equal " range(1, len(list_a)+1)". Without "+1" last item won't be reached and hence sorted

  • @shounaugustine5320
    @shounaugustine5320 4 ปีที่แล้ว

    Thanks man keep making videos

  • @xerostat8961
    @xerostat8961 3 ปีที่แล้ว

    this is great, but can you do the same with for loop?

  • @ariskoutsoukis7849
    @ariskoutsoukis7849 4 ปีที่แล้ว

    def insertionSort(array):
    index = 0
    for item in range(index , len(array) ):
    first_ptr = index
    second_ptr = index - 1
    while second_ptr > -1:
    if array[first_ptr] < array[second_ptr]:

    array[second_ptr] , array[first_ptr] = array[first_ptr] , array[second_ptr]
    else:
    break
    second_ptr = second_ptr - 1
    first_ptr = first_ptr - 1

    index = index + 1

  • @kasyapdharanikota8570
    @kasyapdharanikota8570 3 ปีที่แล้ว

    why was i=I-1 written ?

  • @parthrohit4614
    @parthrohit4614 3 ปีที่แล้ว

    Can you make a RSA algorithm and SDES key generation with Inception and Description please .

  • @toprecbot
    @toprecbot 3 ปีที่แล้ว

    Hello good explanation,

  • @chillprogrammer
    @chillprogrammer 2 ปีที่แล้ว

    thanku so much bro

  • @robertovillanueva7077
    @robertovillanueva7077 3 ปีที่แล้ว

    Thanks a ton!

  • @salikmalik7631
    @salikmalik7631 3 ปีที่แล้ว

    I confused, We have builtin sort function in python so why we need that too much code.

  • @nerapelin8851
    @nerapelin8851 2 ปีที่แล้ว

    Thank you very much this helped a lot :))

  • @s-1374
    @s-1374 2 ปีที่แล้ว

    Thank you

  • @Silentmjrt
    @Silentmjrt 3 ปีที่แล้ว

    I have a quick question, it may seem stupid to ask but I cannot see it.
    I don't understand why the i = i - 1 is necessary?
    I thought the incrementing step through the list was the job of the for i in range() operation?
    I am a complete noob to all this stuff. Thank you for your great content, it's really helping me grasp applications of the foundations I've been building.

    • @varunbisht8576
      @varunbisht8576 3 ปีที่แล้ว

      Range function only generates a sequence of values. for loop makes sure that operation in body of for loop is carried out on all the values generated by range function. it doesn't do anything related to increment until specified in body of for loop

  • @yashmetha1232
    @yashmetha1232 4 ปีที่แล้ว +1

    Thanks bruh pls do videos on matplotlib and seaborn

  • @JT2751257
    @JT2751257 3 ปีที่แล้ว

    Wrote this before looking at your solution :)
    list_nos = [10,16,8,12,15,6,3,9,5,100]
    def insertion_sort(list_nos):
    list_new=[]
    for i in range(len(list_nos)):
    list_new.append(list_nos[i])
    while i>0:
    if list_new[i]

  • @destined0645
    @destined0645 2 ปีที่แล้ว

    why are u swappig it in that way ,i thought it was meant to be the reversed way of yours?
    n

  • @sanketgore2515
    @sanketgore2515 4 ปีที่แล้ว

    Nice one👍

  • @zakirhossain7413
    @zakirhossain7413 4 ปีที่แล้ว

    it runs fine without declaring list_a as an additional variable.
    is this bad practice?
    def insertion_list(list_a):
    # indexing_len = range(1, len(list_a))
    "program runs just fine without declaring this variable. can anyone please explain if it's bad practice?
    for i in range(1, len(list_a)):
    value_sort = list_a[i]
    while list_a[i - 1] > value_sort and i > 0:
    list_a[i], list_a[i - 1] = list_a[i - 1], list_a[i]
    i = i -1
    return list_a

  • @abbaashussain6163
    @abbaashussain6163 2 ปีที่แล้ว

    What if you want the numbers ordered as high to low? How would you do that?

    • @alenjose3903
      @alenjose3903 หลายเดือนก่อน

      just perform this same code and then reverse the list. voila.

  • @itech40
    @itech40 4 ปีที่แล้ว +1

    thanks! :)

  • @ontogeekchic
    @ontogeekchic ปีที่แล้ว

    Great

  • @subhansaadat4548
    @subhansaadat4548 3 ปีที่แล้ว

    Can anyone let me know why did we write i=I-1 ??

    • @cosmicbandido8186
      @cosmicbandido8186 3 ปีที่แล้ว

      As far as I understand you check with i = i-1 the same element again against the next possible element on its left side until the while condition is False.

  • @polymorph5067
    @polymorph5067 3 ปีที่แล้ว

    4:34 This code is not bad but I think there's no reason to create new variables here. Just have a look at my code below:
    def ins_sort(arr:list) -> list:
    for i in range(1, len(arr)):
    for j in range(0, len(arr[:i])):
    if arr[i] < arr[j]:
    arr[i], arr[j] = arr[j], arr[i]
    return arr
    I use slicing of a list instead of creating new variables

    • @kenadams9024
      @kenadams9024 3 ปีที่แล้ว

      I think this one takes more time

  • @hocosta1
    @hocosta1 4 ปีที่แล้ว

    Hey Derik,
    my name is Henrique, found you on youtube and have been watching your videos a lot, and I am loving it, you are doing a great job!
    Found your videos when researching how to automate some basic stuff of my daily activities I own a small distribution business where I sell construction items to small traders and I have a problem I would like to solve.
    with around 200 customers listed on my spreadsheet I sell to around 5 of day everyday, I could be selling much more as my customers need products to do their job, however is very hard to predict when they need (hard to remember last time they bought and if they are running out of material)
    I got 2 problems that I am sure could be easily sorted with 2 spreadsheets and some Python
    Problem 1, when I m out for a delivery I usually know there are some of my customers around that might want to buy my products, however as I am driving is just impossible to stop my car and try to call one by one to figure out who needs my products.
    On my spreadsheet I could sort the list of potential customer using the first 3 characters of their POSTCODE as it would tell me how close they are, I could pick the 3 customers below and 3 customers after the postcode I am delivering.
    customer_name Cust_whatsapp Customer_Postcode Jan_purc Feb_Pur
    John +551196194988 03650000 Paint Glue
    Mary +5511999054333 03750000 Paint none
    Paul +5511999999999 03760000 Glue none
    Question 1 - what can I do in Python to go to my sheet and select a group of customer's postcode by proximity of address I am delivering ( It would be also nice if they could be automatically sent to web.whatsapp so I could send them a message.
    Problem 2
    On a second spreadsheet I have the purchase history, I woul love to be able to predict when my Customer is ready to buy again.
    Question 2- Is it possible to create a simple code to read all purchase history from columns and give me a hint of when they are more likely to buy again? some output in a third spreadsheet with a list ordered by most likely to need, this way I dont need to do it by chance and keep skipping customers to my competitors
    Hey Man, even if I don't get a reply, I still love what you do, sharing knowledge is the best thing a person can do! Sooner or later I will figure out how to do it.
    Cheers
    Henrique

    • @cosmicbandido8186
      @cosmicbandido8186 3 ปีที่แล้ว

      I would suggest you hire a coder for your needs. Because as far as I see your business is selling items and not coding.
      In python maybe Pandas and some grafic plot modules like matplotlib can help. Not sure about your live location tracking and clients nearby though.
      Good luck

  • @rajarshimondal1343
    @rajarshimondal1343 3 ปีที่แล้ว

    i like it

  • @knightr1der
    @knightr1der 4 ปีที่แล้ว

    What's the text editor name??

    • @CodeWithDerrick
      @CodeWithDerrick  4 ปีที่แล้ว +1

      Sorry for the delay! I use Atom in my tutorials with the platformio-ide-terminal package for the little terminal at the bottom. Happy Coding!

  • @LownerCZ
    @LownerCZ 4 ปีที่แล้ว +1

    Shorter code(Not faster though):
    def insertion_sort(lst):
    for i in range(1, len(lst)):
    while i > 0 and lst[i] < lst[i-1]:
    lst[i], lst[i - 1] = lst[i - 1], lst[i]
    i -= 1
    return lst

  • @leetcode_solutions
    @leetcode_solutions 2 ปีที่แล้ว

    💯

  • @genericstospecifics1856
    @genericstospecifics1856 4 ปีที่แล้ว

    why are we using i = i-1 ??

    • @anshulvairagade1604
      @anshulvairagade1604 4 ปีที่แล้ว +1

      We have to compare the current element with the left element down the list

    • @atod2572
      @atod2572 4 ปีที่แล้ว +1

      Even I didn't get it. Coz we are already comparing elements to left in the while loop itself so why i=i-1 again?

    • @anshulvairagade1604
      @anshulvairagade1604 4 ปีที่แล้ว +3

      @@atod2572 we are using i=i-1 coz we are not just using the left element, I'd the left element is not larger it will check the left of left till zeroth index
      Hope you got it now.
      Don't check for just i=1
      Check for say i=4 or 5
      Then you will get it.
      Website: visualgo.com
      And check for insert sort

    • @atod2572
      @atod2572 4 ปีที่แล้ว

      @@anshulvairagade1604 thanks 👍🏻

  • @abdullahwasim7284
    @abdullahwasim7284 3 ปีที่แล้ว

    he looks exactly like luke from percy jackson

  • @vidyaselvakumar7044
    @vidyaselvakumar7044 4 ปีที่แล้ว

    Is this code correct?(it's too easy n small. i have exams today and can't afford a mistake) . No offense.thanks.

  • @r.a.a.6472
    @r.a.a.6472 9 หลายเดือนก่อน +1

    Why do you always look like if you were drowning in the sea and subtly emerged to take air

  • @amanahmed6057
    @amanahmed6057 4 ปีที่แล้ว +1

    anyone is forcing u to SPEAK

    • @CodeWithDerrick
      @CodeWithDerrick  4 ปีที่แล้ว +1

      SPEAK master anyone has instructed long ago

    • @amanahmed6057
      @amanahmed6057 4 ปีที่แล้ว

      @@CodeWithDerrick SIR PLZ BE ENERGETIC
      AND PLZ ADD SOUND BEHIND YOUR VOICE

    • @genericstospecifics1856
      @genericstospecifics1856 4 ปีที่แล้ว +7

      @@amanahmed6057 Let him teach the way he does without music, most of us here are not to spend some good time listening to music but to learn concepts that are skipped or explained casually by professors at our universities.

    • @msms3260
      @msms3260 4 ปีที่แล้ว

      @Aman Ahmed. No music needed thank you. Calm soft voice is good for such topics.