A Detailed Algorithmic Analysis of Insertion Sort. Best Case & Worst Case.

Поділитися
Вставка
  • Опубліковано 18 жов 2024
  • Free 5-Day Mini-Course: backtobackswe.com
    Try Our Full Platform: backtobackswe....
    📹 Intuitive Video Explanations
    🏃 Run Code As You Learn
    💾 Save Progress
    ❓New Unseen Questions
    🔎 Get All Solutions
    Question: Give exact comparisons and moves that happen in the best, average, and worst case of insertion sort.
    Gauss' Trick: mathcentral.ure...
    Bubble Sort Analysis: • An In-Depth Algorithmi...
    I'm so sorry that my camera was about to die. I had to cut the video short. The average case is the hardest part to understand so this video also would have been much longer.
    I'm not sure if I will ever cover it in a video...so there's a really hard challenge. What's the amount of comparisons and moves for the average case? (the hard part is calculating the expected value for the total while loop comparisons)
    ++++++++++++++++++++++++++++++++++++++++++++++++++
    HackerRank: / @hackerrankofficial
    Tuschar Roy: / tusharroy2525
    GeeksForGeeks: / @geeksforgeeksvideos
    Jarvis Johnson: / vsympathyv
    Success In Tech: / @successintech

КОМЕНТАРІ • 153

  • @BackToBackSWE
    @BackToBackSWE  5 років тому +22

    Table of Contents:
    We Have Come A Long Way pt. 1 0:00 - 0:37
    Behind The Scenes 0:37 - 1:00
    We Have Come A Long Way pt. 2 1:00 - 1:23
    What We Are Going To Cover In This Video 1:23 - 2:02
    Walking Through The Pseudocode 2:02 - 3:08
    What Is A Sentinel? 3:08 - 3:37
    The 2 Fundamental Operations: Moves & Comparisons 3:37 - 4:59
    Starting The Actual Insertion Sort Walkthrough 4:59 - 14:25
    Best Case: Exact Amount of Comparisons 14:25 - 17:28
    Best Case: Exact Amount of Moves 17:28 - 21:08
    Worst Case: Exact Amount of Comparisons 21:08 - 28:55
    Worst Case: Exact Amount of Moves 28:55 - 34:45
    Sorry...The Camera Was About To Die 34:45 - 35:06
    Wrap Up 35:06 - 36:19
    The code for this problem is in the description. Fully commented for teaching purposes.

    • @rishabhjha447
      @rishabhjha447 4 роки тому

      Watch Ravindra Babu Ravula's Video on UA-cam.

    • @rishabhjha447
      @rishabhjha447 4 роки тому

      ua-cam.com/video/BO145HIUHRg/v-deo.html

  • @sushruttabakade6088
    @sushruttabakade6088 5 років тому +43

    I'm crying here, for the past one hour I was struggling with all of these complex concepts and how wonderfully you in just half an hour taught me everything. Thank you man, excellent video!

  • @dreamzsiva
    @dreamzsiva 5 років тому +24

    I love how this young guy who is still pursuing his degree is so well articulated in his thoughts as a teacher and proficient as a coder. You will go a long way buddy! I am buying your interview class.

    • @BackToBackSWE
      @BackToBackSWE  5 років тому

      hahahahaha, ok, I'm just a dude...and I'm wrong a lot

  • @mariasandru5566
    @mariasandru5566 5 років тому +43

    These videos are so underappreciated. I can t believe it.

  • @superchillh3o
    @superchillh3o 4 роки тому +7

    I love the way you explain things, the clarity is unmatched, thanks so much.

  • @GamerGabbar
    @GamerGabbar 5 років тому +11

    THANK YOU SO MUCH FOR MAKING VIDEOS LIKE THIS!
    I'm an Indian but I don't live in India and most videos like these are made by people from india, They're excellent videos but hard to understand.
    This is super nice! Again, Mad Thanks! 🙏

  • @fortresssanitarium2205
    @fortresssanitarium2205 3 роки тому +2

    This is what I'm talking about when I tell my parents what a teacher should be like. The passion that u display is alluring. Thanks for doin this buddy

  • @leahkelley8452
    @leahkelley8452 5 років тому +5

    I am a CS major and your videos have honestly clarified the majority of the concepts that my professors failed to teach. Thank you for doing this. It is extremely helpful. :)

    • @BackToBackSWE
      @BackToBackSWE  5 років тому +2

      I think we are in the same class probably. I go to UMD. In algos rn.

    • @leahkelley8452
      @leahkelley8452 5 років тому +1

      Why are you in algorithms? I thought you were a grad student?

    • @BackToBackSWE
      @BackToBackSWE  5 років тому

      I'm a 2nd year.

    • @leahkelley8452
      @leahkelley8452 5 років тому +1

      Are you in Teli’s class? Did you transfer from a different school?
      ... what is your name?

    • @BackToBackSWE
      @BackToBackSWE  5 років тому +1

      Yes. I'm in your class probably haha. Section #0201. My name is Ben.

  • @dead_gawk
    @dead_gawk 8 місяців тому +2

    The thought of putting in 6 hours of work everyday, just so that some random person on the internet would get free education is amazing. Respect to you, Champ.

    • @tegathemenace
      @tegathemenace 3 місяці тому +1

      Fr. I hope to remember their names and donate when I make it

  • @anrihek5701
    @anrihek5701 5 років тому +4

    351 has just been such a confusing thing for me, even though I take a lot of notes and read through them I just don't get it. The analysis videos have been really helpful and they are much easier to understand than lectures. I know making these videos must be really time consuming and youtube channels seem to grow really slow sometimes, so I just want to say again how much I appreciate this and your work has been so meaningful.

    • @BackToBackSWE
      @BackToBackSWE  5 років тому +2

      sure. Yeah, I assume you have Teli...I personally like Teli as a fundamental human being but his speed sometimes loses people. The problem is conceptual examples. If you speak what you see in your head...you have very few sentences before you begin to lose half the audience who weren't paying attention to your entry into a conceptual explanation...if that makes sense.
      This is why, when teaching it is critical to use visuals, be slow, and make sure that what is in your head...is on the board...not in words. Words lose people.

  • @warrenbinder3612
    @warrenbinder3612 3 роки тому +1

    This is one of the best and most detailed videos about the best and worst cases of Insertion Sort. You explained the topics really well, they were easy to understand. F in the chat for your camera battery, the average case sounds interesting!

  • @zainabsherani8950
    @zainabsherani8950 5 років тому +3

    You're in my Algorithms class!!! WOW! Keep up the good work! The analysis portion helped me out!

    • @BackToBackSWE
      @BackToBackSWE  5 років тому +1

      Hey, good. Sometimes I wish I could go up there and hammer out tiny things I KNOW are confusing students. Everything should be taught the way a student can pick it up quickly.
      I wish I could post in Piazza, but I don't wanna spam people. But I really think these videos would help people. I want to do a video for every lecture topic we do.

  • @bronzebond4869
    @bronzebond4869 3 роки тому +1

    Bro you are doing a great job explaining all this. We appreciate the work you put in. Thanks again.

  • @vineetsharma4121
    @vineetsharma4121 4 роки тому +1

    Superb analysis!!! I had been searching for such complete analysis for so long; finally got it here.

  • @NasK330
    @NasK330 10 місяців тому

    Oh man! You can't tell how thankful I am for this video!

    • @BackToBackSWE
      @BackToBackSWE  10 місяців тому +1

      Happy Holidays 🎉 And we are thankful for your comment, NasK! We'd love to offer you a 40% Off our exclusive lifetime membership just use the code CHEER40 - backtobackswe.com/checkout?plan=lifetime-legacy&discount_code=CHEER40

  • @techservices7028
    @techservices7028 9 місяців тому

    most videos and books did not indicate that A[0]=-infinity. This video really helps to understand. Thanks!

  • @KixMayne91
    @KixMayne91 4 роки тому +1

    OMG I EFFING GET IT!!!!!!! Thank you so much, it was throwing me off thinking that the while loop was always supposed to execute n-1 time since its still a linear process. But now that you clarified it, will ONLY execute n-1 times if it never performs the swap operations. Other wise its performing n(n-1)/2 when it compares and swaps and compares again, etc... Thus making N^2 the average case since there will be moments where the comparison and swap occurs in an unsorted array.

    • @BackToBackSWE
      @BackToBackSWE  4 роки тому

      great lol and tldr tbh im fast replying to comments I luv u tho but I dont remember any specific math it is very much on the spot

  • @js4466
    @js4466 2 роки тому +1

    Your attitude and presentation makes learning fun and clear. I wish you the best in your future endeavours. Liked and subscribed.

  • @margaritasmoliakova7084
    @margaritasmoliakova7084 2 роки тому

    you are so good in explaining things!!! THANK YOU so much for the videos!!!

  • @maike3530
    @maike3530 2 роки тому

    I can't even express how thankful I am for your videos! They help me a lot in my studies! Your videos are amazing :)

  • @fabriciopolicarpo3725
    @fabriciopolicarpo3725 3 роки тому

    You gave me keys bro. up to now I understood everything but that forsaken arr[j + 1] = current. Now I understand the entire algorithm mechanics.

  • @joel_b9216
    @joel_b9216 4 роки тому +1

    broooooo.... duuuude!!!!! You're AMAZING. way better than my 50mins lecture

  • @supamdeepbains5172
    @supamdeepbains5172 4 роки тому +1

    You’re videos are really helpful ive got exam tomorrow and they’re helping

  • @zeffanayahyisrael8428
    @zeffanayahyisrael8428 5 років тому +2

    Yes this is EXCELLENT Work. Please continue. Thank you very much for your knowledge

  • @lorenzozuluaga4309
    @lorenzozuluaga4309 5 років тому +2

    wow lend me tell you you got a new subscriber, really apprecciate that you give to us all this knowledge, bless from colombia!!

    • @BackToBackSWE
      @BackToBackSWE  5 років тому +1

      hahaha wassup from america 🌽🌽

  • @iambongani
    @iambongani 4 роки тому +2

    The only way to appreciate these videos for everyone is to share them. Come on guys lets show some appreciation

  • @fredericoamigo
    @fredericoamigo Рік тому

    Thank you so much for this! Brilliant vid! Keep up the good work!

  • @aaishikighosh6154
    @aaishikighosh6154 4 роки тому +1

    Tysm for this.... I am 18 and I am starting out on these subjects... Nd you really make these easier to understand...

    • @BackToBackSWE
      @BackToBackSWE  4 роки тому +1

      great - you can go so far in this space, get good young

  • @khadijaanam62
    @khadijaanam62 5 років тому +2

    You are doing great! You are awesome at what you do!!! YOUR VIDEOS ARE SO DAMN HELPFUL! Keep up!

  • @sohanaggarwal8770
    @sohanaggarwal8770 2 роки тому

    Enjoyed the presentation. Explained clearly.

  • @hakancemgercek
    @hakancemgercek 5 років тому +1

    14:10 I'm brave enough to stay with this video because I'm trained to stay in the class while the tutor told everything which I didn't understand about this course XD. But thanks to you now everything "finds a home" in my brain. THX

  • @алексейфедоровичкарамазов

    Man!!!! Best videos on algorithm ❤️

  • @procode6881
    @procode6881 3 роки тому

    Hats off to the best explaination on insertion sort

  • @nadasa208
    @nadasa208 3 роки тому

    Thank you for this really perfect explanation !!

  • @guowanqi9004
    @guowanqi9004 5 років тому +3

    6:09 29 will trample over 10's value. 6:24 10 is still looking for a home. Dang that seems so sad

  • @Happy-on2is
    @Happy-on2is 4 роки тому +1

    Hii Mr
    I got a doubt 🤔🤔
    actually in worst case moves it is
    1 + (summation of i = 2 to n) 2 + (summation of j = 1 to i - 1) i
    right ???
    but you have mentioned
    1 + (summation of i = 2 to n) 2 + (summation of j = 1 to i - 1) 1
    difference is the last 1 and i in the above expression

  • @cameronsantiago3155
    @cameronsantiago3155 3 роки тому

    The Grind! The hussle!

  • @vishwassrinivas474
    @vishwassrinivas474 5 років тому +1

    Awesome,please do a video for finding the longest palindromic subsequence.

    • @BackToBackSWE
      @BackToBackSWE  5 років тому +1

      Yes, it's on the list, it'll come one day

  • @sajidsarkar9574
    @sajidsarkar9574 4 роки тому +1

    Can you cover algorithm strategies: Brute Force, Greedy, Dynamic Programming, and Divide and Conquer?

  • @cerenarkac3484
    @cerenarkac3484 2 роки тому

    Thank you very much for this useful video

  • @osandarathnayaka9002
    @osandarathnayaka9002 3 роки тому

    cool explanation thanks.

  • @Rahul-yg5kp
    @Rahul-yg5kp 4 роки тому +1

    Wow man great video.

  • @zaintahir3348
    @zaintahir3348 Рік тому

    THANK YOU!!!

  • @algoh0l1c
    @algoh0l1c 5 років тому +1

    Listening to this at 1.75 speed and enjoying it!

    • @BackToBackSWE
      @BackToBackSWE  5 років тому +1

      hahaha, I recommend everyone do that for learning vids. I do podcasts 1.5x and videos 1.5x-2x

    • @algoh0l1c
      @algoh0l1c 5 років тому +1

      @@BackToBackSWE actually, after my comment I tried 2x too, very effective. Thank you for the videos. They are helping a lot!

    • @BackToBackSWE
      @BackToBackSWE  5 років тому

      @@algoh0l1c nice

  • @favour_republic
    @favour_republic 11 місяців тому

    If only Nigeria lecturers teaches this way... The problem now is I understand yours but it's totally different from what I was taught in class and the lecturer expect me to write the exact thing he taught in class 😢 if not I'm not getting my full mark... Anyways thanks this your video was very helpful 🎉

    • @BackToBackSWE
      @BackToBackSWE  10 місяців тому

      Happy Holidays 🎉 What's important is getting your concepts clear! We'd love to offer you a 40% Off our exclusive lifetime membership just use the code CHEER40 - backtobackswe.com/checkout?plan=lifetime-legacy&discount_code=CHEER40

  • @paulpassiglia9997
    @paulpassiglia9997 4 роки тому +1

    Thank you so much

  • @sujithkrishnan6429
    @sujithkrishnan6429 5 років тому +1

    Wonderful videos, it would be great if we have sequence number for Videos, to follow easily,Thanks

  • @thanhtungtran8249
    @thanhtungtran8249 3 роки тому

    Thank you for super great videos

  • @AK-cl8iv
    @AK-cl8iv Рік тому

    reference:
    when i = 2, j = 1,0 ; i = 3, j = 2,1,0.... i = n, j = i-1, i-2,...,0 hence total number of comparisons for worst case is 2 + 3 + ... + n = n(n+1)/2 -1

  • @ashishm8850
    @ashishm8850 5 років тому +1

    Kudos to you! Thanks!

  • @JustJoelTV
    @JustJoelTV 2 роки тому

    Your clarity is next level. Thank you. Great video, thumbs up and sub from me

  • @saadmahmood5396
    @saadmahmood5396 3 роки тому

    is there a video where you explain the average case for insertion sort?

  • @alirezaRahmanikhalili
    @alirezaRahmanikhalili 5 років тому +1

    it is most useful video ever.

  • @andrewnguyen6396
    @andrewnguyen6396 3 роки тому

    thank you so much :)

  • @laggynacho
    @laggynacho 11 місяців тому

    Great Video!

    • @BackToBackSWE
      @BackToBackSWE  10 місяців тому

      Happy Holidays 🎉 Thank you for your kind words! We'd love to offer you a 40% Off our exclusive lifetime membership just use the code CHEER40 - backtobackswe.com/checkout?plan=lifetime-legacy&discount_code=CHEER40

  • @faysalahmedakash7703
    @faysalahmedakash7703 3 роки тому

    why the number of comparisons for worst case is not "n(n-1)/2" ? Won't the ith element do (i-1) comparisons to get into the 1st position?

  • @esraataher36
    @esraataher36 3 роки тому

    a very useful one

  • @booboo-oh1vd
    @booboo-oh1vd 3 роки тому

    OMG... THANK YOU

  • @lernordmac2711
    @lernordmac2711 4 роки тому +1

    0:01 Rock on dude

  • @JustSoji
    @JustSoji 5 років тому +1

    How different are comparisons and moves if we don’t use a sentinel

    • @BackToBackSWE
      @BackToBackSWE  5 років тому

      what do you mean "how different"

    • @JustSoji
      @JustSoji 5 років тому

      Back To Back SWE will the number of moves/comparisons change if we don’t use a sentinel

  • @viktorvostrikov9625
    @viktorvostrikov9625 5 років тому

    Thanks! Amazing series.., I watched bubble sort, but I still can't understand why you do you get (n-1) from the while loop set? How can you calculate bounds and say that it answer is n-1? Why when you can't use same approach if outer loop would not be 1?

    • @BackToBackSWE
      @BackToBackSWE  5 років тому

      can you timestamp it?

    • @viktorvostrikov9625
      @viktorvostrikov9625 5 років тому +1

      @@BackToBackSWE 16:30

    • @BackToBackSWE
      @BackToBackSWE  5 років тому

      @@viktorvostrikov9625 Ok so best case comparisons. We get n - 1 since that purple section will get hit n - 1 times and NEVER get entered in the best case (the array is already sorted...nothing needs to go backwards for insertion).

    • @viktorvostrikov9625
      @viktorvostrikov9625 5 років тому +1

      @@BackToBackSWE yes I get that, you will do only one comparison in for loop. and after all comparisons the purple area will be hit n-1.
      I just don't get the math of it and how you managed to convert Set from j=2 to n, to be equal to n-1.
      I thought that set supposed to mean 2,3,4,5,6...n. So you should sum all that and then you will get complexity, which is different than n-1.

    • @BackToBackSWE
      @BackToBackSWE  5 років тому +1

      @@viktorvostrikov9625 If j goes from 2 to n, how many iterations happen?
      Imagine n is 3:
      j = 2
      j = 3
      2 iterations.
      n was 3.
      So n - 1 iterations that the if statement is hit.

  • @noursafa22
    @noursafa22 Рік тому

    do the average case pls

  • @SumayahAlsakiti
    @SumayahAlsakiti Рік тому

    thaaaank you

  • @loganynguyen
    @loganynguyen 4 роки тому +2

    What uni are you at?

  • @alannah000
    @alannah000 Рік тому

    You are awesome

  • @JonnieZuramski
    @JonnieZuramski 5 років тому

    Do you think you'll eventually do average case?

    • @BackToBackSWE
      @BackToBackSWE  5 років тому

      no, I should've but it sucks and would've added 30+ minutes to recording time, are you in 351?

  • @laxmipoojaanegundi7757
    @laxmipoojaanegundi7757 5 років тому +1

    Can I be part of Back To Back SWE? I can assist in any work. Its so exciting to be part of Back To Back SWE

    • @BackToBackSWE
      @BackToBackSWE  5 років тому

      Yeah, I'm looking for writers that are good

  • @zkfdsldfjsdjfl1
    @zkfdsldfjsdjfl1 4 роки тому +3

    I used to take Fawzi’s 250 in that classroom 😂

    • @lernordmac2711
      @lernordmac2711 4 роки тому +2

      You could see Stamp from the windows if it was daytime I miss it lol

    • @zkfdsldfjsdjfl1
      @zkfdsldfjsdjfl1 4 роки тому +1

      @@lernordmac2711 YO the good times

    • @BackToBackSWE
      @BackToBackSWE  4 роки тому

      yeah it is in ESJ, top floor, all the way to the left.

    • @BackToBackSWE
      @BackToBackSWE  4 роки тому

      @@lernordmac2711 could u? I don't think u can but u can see Hornbake.

    • @BackToBackSWE
      @BackToBackSWE  4 роки тому

      @@zkfdsldfjsdjfl1 yes

  • @renjieyu8700
    @renjieyu8700 5 років тому +1

    Ben, love u 🤣 我想当你的小迷弟啊啊啊,Now, Let's deal with the sort problems

  • @volkanulker6432
    @volkanulker6432 3 роки тому

    Can you add subtitle to these contents ?

  • @yoshi4980
    @yoshi4980 5 років тому +3

    u didnt do average case :( but otherwise great video.

  • @CarolinaRutiliLima
    @CarolinaRutiliLima 6 місяців тому

    I wanted the average case aaaa

  • @JustSoji
    @JustSoji 5 років тому +1

    But what about average case

  • @abemelekdaniel8913
    @abemelekdaniel8913 Рік тому

    fine

  • @bhargavsai2449
    @bhargavsai2449 4 роки тому +1

    plz attach java code

    • @BackToBackSWE
      @BackToBackSWE  4 роки тому

      The repository is deprecated - we only maintain backtobackswe.com now.

  • @ahmadbodayr7203
    @ahmadbodayr7203 2 роки тому

    Read About Islam bro and thank you for your great explaination❤❤

  • @bhargavsai2449
    @bhargavsai2449 4 роки тому +1

    System.out.println("Superb");

  • @muhammadrezaulislam9999
    @muhammadrezaulislam9999 3 роки тому

    there was no average case. -.- i watched the whole video for average case but nope. -.-

  • @supamdeepbains5172
    @supamdeepbains5172 4 роки тому +1

    did you listen to eminem new album? music to be murdered by?