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

Ғылым және технология

Free 5-Day Mini-Course: backtobackswe.com
Try Our Full Platform: backtobackswe.com/pricing
📹 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.uregina.ca/qq/data...
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
    @BackToBackSWE5 жыл бұрын

    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

    3 жыл бұрын

    Watch Ravindra Babu Ravula's Video on KZread.

  • @rishabhjha447

    @rishabhjha447

    3 жыл бұрын

    kzread.info/dash/bejne/dINllpeBebiugso.html

  • @dreamzsiva
    @dreamzsiva4 жыл бұрын

    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

    4 жыл бұрын

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

  • @sushruttabakade6088
    @sushruttabakade60885 жыл бұрын

    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!

  • @BackToBackSWE

    @BackToBackSWE

    5 жыл бұрын

    hahahahaha nice.

  • @mariasandru5566
    @mariasandru55664 жыл бұрын

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

  • @BackToBackSWE

    @BackToBackSWE

    4 жыл бұрын

    yo

  • @dead_gawk
    @dead_gawk5 ай бұрын

    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

    21 күн бұрын

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

  • @GamerGabbar
    @GamerGabbar5 жыл бұрын

    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! 🙏

  • @BackToBackSWE

    @BackToBackSWE

    5 жыл бұрын

    Nice sure

  • @fortresssanitarium2205
    @fortresssanitarium22053 жыл бұрын

    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

  • @bronzebond4869
    @bronzebond48693 жыл бұрын

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

  • @superchillh3o
    @superchillh3o3 жыл бұрын

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

  • @BackToBackSWE

    @BackToBackSWE

    3 жыл бұрын

    sure

  • @maike3530
    @maike3530 Жыл бұрын

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

  • @zainabsherani8950
    @zainabsherani89505 жыл бұрын

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

  • @BackToBackSWE

    @BackToBackSWE

    5 жыл бұрын

    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.

  • @vineetsharma4121
    @vineetsharma41214 жыл бұрын

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

  • @BackToBackSWE

    @BackToBackSWE

    4 жыл бұрын

    great

  • @warrenbinder3612
    @warrenbinder36123 жыл бұрын

    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!

  • @BackToBackSWE

    @BackToBackSWE

    3 жыл бұрын

    Glad it was helpful!

  • @js4466
    @js4466 Жыл бұрын

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

  • @anrihek5701
    @anrihek57015 жыл бұрын

    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 жыл бұрын

    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.

  • @margaritasmoliakova7084
    @margaritasmoliakova70842 жыл бұрын

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

  • @leahkelley8452
    @leahkelley84525 жыл бұрын

    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 жыл бұрын

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

  • @leahkelley8452

    @leahkelley8452

    5 жыл бұрын

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

  • @BackToBackSWE

    @BackToBackSWE

    5 жыл бұрын

    I'm a 2nd year.

  • @leahkelley8452

    @leahkelley8452

    5 жыл бұрын

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

  • @BackToBackSWE

    @BackToBackSWE

    5 жыл бұрын

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

  • @fredericoamigo
    @fredericoamigo10 ай бұрын

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

  • @nadasa208
    @nadasa2083 жыл бұрын

    Thank you for this really perfect explanation !!

  • @lorenzozuluaga4309
    @lorenzozuluaga43095 жыл бұрын

    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 жыл бұрын

    hahaha wassup from america 🌽🌽

  • @procode6881
    @procode68813 жыл бұрын

    Hats off to the best explaination on insertion sort

  • @techservices7028
    @techservices70286 ай бұрын

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

  • @khadijaanam62
    @khadijaanam625 жыл бұрын

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

  • @BackToBackSWE

    @BackToBackSWE

    5 жыл бұрын

    thanks

  • @zeffanayahyisrael8428
    @zeffanayahyisrael84285 жыл бұрын

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

  • @BackToBackSWE

    @BackToBackSWE

    5 жыл бұрын

    thanks

  • @supamdeepbains5172
    @supamdeepbains51724 жыл бұрын

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

  • @BackToBackSWE

    @BackToBackSWE

    4 жыл бұрын

    nice, umd?

  • @NasK330
    @NasK3307 ай бұрын

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

  • @BackToBackSWE

    @BackToBackSWE

    7 ай бұрын

    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

  • @sohanaggarwal8770
    @sohanaggarwal87702 жыл бұрын

    Enjoyed the presentation. Explained clearly.

  • @KixMayne91
    @KixMayne913 жыл бұрын

    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

    3 жыл бұрын

    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

  • @user-yb6oc4tj2w
    @user-yb6oc4tj2w4 жыл бұрын

    Man!!!! Best videos on algorithm ❤️

  • @BackToBackSWE

    @BackToBackSWE

    4 жыл бұрын

    thx

  • @hakancemgercek
    @hakancemgercek5 жыл бұрын

    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

  • @BackToBackSWE

    @BackToBackSWE

    5 жыл бұрын

    thanks

  • @zaintahir3348
    @zaintahir3348 Жыл бұрын

    THANK YOU!!!

  • @osandarathnayaka9002
    @osandarathnayaka90023 жыл бұрын

    cool explanation thanks.

  • @thanhtungtran8249
    @thanhtungtran82493 жыл бұрын

    Thank you for super great videos

  • @joel_b9216
    @joel_b92164 жыл бұрын

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

  • @BackToBackSWE

    @BackToBackSWE

    4 жыл бұрын

    no u

  • @fabriciopolicarpo3725
    @fabriciopolicarpo37252 жыл бұрын

    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.

  • @iambongani
    @iambongani4 жыл бұрын

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

  • @BackToBackSWE

    @BackToBackSWE

    4 жыл бұрын

    lol

  • @cameronsantiago3155
    @cameronsantiago31552 жыл бұрын

    The Grind! The hussle!

  • @aaishikighosh6154
    @aaishikighosh61543 жыл бұрын

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

  • @BackToBackSWE

    @BackToBackSWE

    3 жыл бұрын

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

  • @andrewnguyen6396
    @andrewnguyen63962 жыл бұрын

    thank you so much :)

  • @ashishm8850
    @ashishm88505 жыл бұрын

    Kudos to you! Thanks!

  • @BackToBackSWE

    @BackToBackSWE

    5 жыл бұрын

    ya

  • @booboo-oh1vd
    @booboo-oh1vd3 жыл бұрын

    OMG... THANK YOU

  • @esraataher36
    @esraataher363 жыл бұрын

    a very useful one

  • @vishwassrinivas474
    @vishwassrinivas4745 жыл бұрын

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

  • @BackToBackSWE

    @BackToBackSWE

    5 жыл бұрын

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

  • @cerenarkac3484
    @cerenarkac34842 жыл бұрын

    Thank you very much for this useful video

  • @BackToBackSWE

    @BackToBackSWE

    Жыл бұрын

    Glad it was helpful!

  • @laggynacho
    @laggynacho8 ай бұрын

    Great Video!

  • @BackToBackSWE

    @BackToBackSWE

    7 ай бұрын

    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

  • @paulpassiglia9997
    @paulpassiglia99974 жыл бұрын

    Thank you so much

  • @BackToBackSWE

    @BackToBackSWE

    4 жыл бұрын

    sure

  • @Rahul-yg5kp
    @Rahul-yg5kp4 жыл бұрын

    Wow man great video.

  • @BackToBackSWE

    @BackToBackSWE

    4 жыл бұрын

    thanks

  • @alirezaRahmanikhalili
    @alirezaRahmanikhalili5 жыл бұрын

    it is most useful video ever.

  • @BackToBackSWE

    @BackToBackSWE

    5 жыл бұрын

    haha bold statement

  • @JustJoelTV
    @JustJoelTV2 жыл бұрын

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

  • @BackToBackSWE

    @BackToBackSWE

    Жыл бұрын

    Thanks for the sub!

  • @user-ti2kd2yo1w
    @user-ti2kd2yo1w10 ай бұрын

    thaaaank you

  • @alannah000
    @alannah000 Жыл бұрын

    You are awesome

  • @sajidsarkar9574
    @sajidsarkar95743 жыл бұрын

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

  • @BackToBackSWE

    @BackToBackSWE

    3 жыл бұрын

    maybe

  • @guowanqi9004
    @guowanqi90045 жыл бұрын

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

  • @BackToBackSWE

    @BackToBackSWE

    5 жыл бұрын

    indeed

  • @sujithkrishnan6429
    @sujithkrishnan64295 жыл бұрын

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

  • @BackToBackSWE

    @BackToBackSWE

    5 жыл бұрын

    thx

  • @saadmahmood5396
    @saadmahmood53962 жыл бұрын

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

  • @noursafa22
    @noursafa22 Жыл бұрын

    do the average case pls

  • @uzboxing5238
    @uzboxing52384 жыл бұрын

    Listening to this at 1.75 speed and enjoying it!

  • @BackToBackSWE

    @BackToBackSWE

    4 жыл бұрын

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

  • @uzboxing5238

    @uzboxing5238

    4 жыл бұрын

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

  • @BackToBackSWE

    @BackToBackSWE

    4 жыл бұрын

    @@uzboxing5238 nice

  • @lernordmac2711
    @lernordmac27114 жыл бұрын

    0:01 Rock on dude

  • @BackToBackSWE

    @BackToBackSWE

    4 жыл бұрын

    what did I do

  • @Happy-on2is
    @Happy-on2is4 жыл бұрын

    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

  • @BackToBackSWE

    @BackToBackSWE

    4 жыл бұрын

    im not sure - I don't remember the math

  • @Happy-on2is

    @Happy-on2is

    4 жыл бұрын

    @@BackToBackSWE 🙄😕

  • @faysalahmedakash7703
    @faysalahmedakash77033 жыл бұрын

    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?

  • @loganynguyen
    @loganynguyen4 жыл бұрын

    What uni are you at?

  • @BackToBackSWE

    @BackToBackSWE

    4 жыл бұрын

    This one umd.edu/

  • @favour_republic
    @favour_republic8 ай бұрын

    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

    7 ай бұрын

    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

  • @viktorvostrikov9625
    @viktorvostrikov96255 жыл бұрын

    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 жыл бұрын

    @@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 жыл бұрын

    @@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 жыл бұрын

    @@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.

  • @abemelekdaniel8913
    @abemelekdaniel8913 Жыл бұрын

    fine

  • @JustSoji
    @JustSoji4 жыл бұрын

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

  • @BackToBackSWE

    @BackToBackSWE

    4 жыл бұрын

    what do you mean "how different"

  • @JustSoji

    @JustSoji

    4 жыл бұрын

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

  • @CarolinaRutiliLima
    @CarolinaRutiliLima4 ай бұрын

    I wanted the average case aaaa

  • @renjieyu8700
    @renjieyu87005 жыл бұрын

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

  • @BackToBackSWE

    @BackToBackSWE

    5 жыл бұрын

    I want to be your brother too

  • @laxmipoojaanegundi7757
    @laxmipoojaanegundi77574 жыл бұрын

    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

    4 жыл бұрын

    Yeah, I'm looking for writers that are good

  • @JonnieZuramski
    @JonnieZuramski4 жыл бұрын

    Do you think you'll eventually do average case?

  • @BackToBackSWE

    @BackToBackSWE

    4 жыл бұрын

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

  • @yoshi4980
    @yoshi49805 жыл бұрын

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

  • @BackToBackSWE

    @BackToBackSWE

    5 жыл бұрын

    I know :(

  • @volkanulker6432
    @volkanulker64323 жыл бұрын

    Can you add subtitle to these contents ?

  • @zkfdsldfjsdjfl1
    @zkfdsldfjsdjfl14 жыл бұрын

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

  • @lernordmac2711

    @lernordmac2711

    4 жыл бұрын

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

  • @zkfdsldfjsdjfl1

    @zkfdsldfjsdjfl1

    4 жыл бұрын

    @@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

  • @JustSoji
    @JustSoji4 жыл бұрын

    But what about average case

  • @BackToBackSWE

    @BackToBackSWE

    4 жыл бұрын

    uh

  • @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

  • @bhargavsai2449
    @bhargavsai24494 жыл бұрын

    plz attach java code

  • @BackToBackSWE

    @BackToBackSWE

    4 жыл бұрын

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

  • @bhargavsai2449
    @bhargavsai24494 жыл бұрын

    System.out.println("Superb");

  • @BackToBackSWE

    @BackToBackSWE

    4 жыл бұрын

    thx

  • @supamdeepbains5172
    @supamdeepbains51724 жыл бұрын

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

  • @BackToBackSWE

    @BackToBackSWE

    4 жыл бұрын

    yeah

  • @ahmadbodayr7203
    @ahmadbodayr7203 Жыл бұрын

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

  • @muhammadrezaulislam9999
    @muhammadrezaulislam99992 жыл бұрын

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

Келесі