Insertion Sort Algorithm - Theory + Code

Поделиться
HTML-код
  • Опубликовано: 30 июл 2024
  • This is the third video in the sorting algorithm series where we cover insertion sort in depth. We look at how the algorithm works, the complexity analysis, optimisation, and code.
    Take part in the learning in public initiative! Share your learnings on LinkedIn and Twitter with #DSAwithKunal & don't forget to tag us!
    👉 Resources
    - Join Replit: join.replit.com/kunal-kushwaha
    - Complete Java DSA playlist: • Java + DSA + Interview...
    - Code, Assignments, & Notes: github.com/kunal-kushwaha/DSA...
    ➡️ Connect with me: kunalkushwaha.com
    =========================================
    Timestamps:
    0:00 Introduction
    0:40 Insertion Sort
    16:23 Complexity of Insertion Sort
    16:43 Worst Case
    19:07 Best Case
    21:03 Why use Insertion Sort?
    24:24 Code for Insertion Sort
    30:18 Outro
    #sorting #placement #dsa #interviews

Комментарии • 250

  • @KunalKushwaha
    @KunalKushwaha  День назад

    DSA + interview preparation playlist: ruclips.net/p/PL9gnSGHSqcnr_DxHsP7AW9ftq0AtAyYqJ

  • @pavan5524
    @pavan5524 2 года назад +314

    I wish teachers from my college watch these videos and learn how to teach dsa! 😶

    • @vedanthbaliga7686
      @vedanthbaliga7686 2 года назад +20

      Im not attending my college classes😂after this course. It's a surprise you still attend classes

    • @ranirathore4176
      @ranirathore4176 2 года назад +15

      After watching this course I ask cross questions to faculty , it's really fun😂

    • @vedanthbaliga7686
      @vedanthbaliga7686 2 года назад +3

      @@ranirathore4176 same😂

    • @pavan5524
      @pavan5524 2 года назад

      @@vedanthbaliga7686 the point was, you'd attend if a teacher like Kunal was teaching 😂

    • @ashreynahar8456
      @ashreynahar8456 2 года назад

      @@vedanthbaliga7686 same 😅

  • @fv5895
    @fv5895 2 года назад +44

    first time in my life I was able to solve 3 leetcode medium questions in one attempt. Thank you bro.

  • @akshaytakrani6886
    @akshaytakrani6886 2 года назад +88

    When kunal teaches, the concepts are crystal clear ❤️

  • @ankit_1012
    @ankit_1012 2 года назад +63

    Teaching in the simplest way possible yet most effective way of teaching.I'll prefer to binge watch your videos rather than prime/Netflix....

  • @karmatsering158
    @karmatsering158 2 года назад +36

    His teaching materials should be distributed to all the online professors.

  • @chiragvohra6673
    @chiragvohra6673 2 года назад +18

    Every time kunal is saying don't worry about complextity,One thing I want to say to Kunal In binary Search You have covered more time complexity than other youtuber's whole complexity lecture. Even you are saying I will make a Complexity video on this. That's why You are gem to us.😉😉

    • @gautamjha928
      @gautamjha928 Год назад +4

      yes, you are right.....i am placed in paytm just by watching his entire DSA playlist

  • @vaibhavyadav2674
    @vaibhavyadav2674 2 года назад +58

    Bhaiya can't wait to watch your next playlists on web development , machine learning , and many more
    Had become big fan of yours 😍😍

    • @KunalKushwaha
      @KunalKushwaha  2 года назад +14

      Glad to hear that

    • @SonaliSingh-jy8pw
      @SonaliSingh-jy8pw 5 месяцев назад +1

      @@KunalKushwaha please pls pls do a playlist for mern stack - webd

  • @owaisnazirdar3575
    @owaisnazirdar3575 2 года назад +20

    I Don't Know How To Thank You But I Am Sharing It Through All My Social Media Platforms

  • @devanshtiwari178
    @devanshtiwari178 4 месяца назад +1

    Your explanations themselves are so good that I code the algorithms myself. Before following this playlist I used to think that these algorithms have to be learned and now I laugh at myself

  • @gautampoddar7785
    @gautampoddar7785 2 года назад +5

    Doing a great job! Always needed a good playlist I could depend for DSA placement prep!

  • @sohamsattigeri1750
    @sohamsattigeri1750 2 года назад +2

    The best thing about the lecture is amount of time given to explain the algorithm to the time given to coding

  • @shubhamagrawal78
    @shubhamagrawal78 Год назад +5

    Hey Kunal! Loving your way of explanation and the way you make difficult concepts easier and simpler is beyond expectation. I learnt a lot from your videos, I learnt indentation, writing clean code, logic building and what not. Please complete this playlist as soon as possible. It will be beneficial for everyone who started this series hearing your words that this is the only course you need to get a job at FAANGM.

  • @shiwanithagele4544
    @shiwanithagele4544 Год назад

    from zero interest in coding to solving questions from my end ... you always help me thank you so much ... and god bless you with more happiness and success.

  • @Raavan-07
    @Raavan-07 Год назад

    after watching 8-9 different videos of insertion sort from every source but won't be able to understand the internal working of insertion sort. But finally, when I saw your detailed explanation of the insertion sort video, it cleared my all doubts. Thanks, Kunal Kuswahaaa...

  • @lostt3435
    @lostt3435 2 года назад +2

    hey, very detailed video Kunal. Got every bit of it. Thank you to put your time and efforts into this. Nobody explains dsa in this much of depth. Thank you😊

  • @sumitpatil5676
    @sumitpatil5676 2 года назад +9

    I used to watch and learn daily from this course but haven't done anything past 15 days. Hope I continue to learn from today. 🙂

  • @charlesopuoro5295
    @charlesopuoro5295 Год назад

    Another great video Kunal. You are the man. Thanks for your charitable endeavours.

  • @nehagadekar7381
    @nehagadekar7381 2 года назад +1

    Everything seems so easy when u teach some people are deliberately making taboo of it is so difficult I am thankful to you for this quality content 👍

  • @user-mk8zz3ow4f
    @user-mk8zz3ow4f 5 месяцев назад

    You are the best teacher in the entire world to learn about the Data Structure and the algorithm

  • @hemanthsavasere934
    @hemanthsavasere934 9 месяцев назад

    Hope Kunal brings out more quality content like these. Loved this

  • @charugullasairitvik3099
    @charugullasairitvik3099 2 года назад

    entire insertion sort explained clearly in detail and with good explanation...

  • @suvraneelsaha8973
    @suvraneelsaha8973 2 года назад +2

    25 mins explanation 5 mins of code
    loved it

  • @abhiraj533
    @abhiraj533 2 года назад +1

    Awesome content.. Not every educator can ease concepts out as simple as you do. Keep educating ...

  • @SatyamKumar-lj5bi
    @SatyamKumar-lj5bi 2 года назад +2

    Kudos to you for uploading soon ! ❤️❤️

  • @mayankgupta9988
    @mayankgupta9988 Год назад

    Best Explanation video for Insertion Short I found on RUclips 🤩

  • @ashwinikalyan9437
    @ashwinikalyan9437 2 года назад +8

    Literally binge watching your content 🙌🙌

    • @KunalKushwaha
      @KunalKushwaha  2 года назад +4

      Hope you enjoy!

    • @ashwinikalyan9437
      @ashwinikalyan9437 2 года назад +1

      @@KunalKushwaha LOVE THEM SO MUCH THANK YOU!!!GOD BLESS YOU YOU PURE SOUL

  • @D.S.Apkare
    @D.S.Apkare 2 года назад +1

    Kunal Sir
    Thanks for this video as well as for code and notes from GitHub
    It helped me very well
    You explain very well that anyone can understand from age 2 to age 90. There can also understand who don't know to read and write and only Know English
    Thanks for providing this
    ☺️☺️

  • @alexA-zf4mk
    @alexA-zf4mk 2 года назад +1

    thank u for ur amazing efforts ,it really helped me to understand dsa topics

  • @undergroundartist6069
    @undergroundartist6069 10 месяцев назад

    your god for me brother no one teaches like you....teachers from our college never teach us like your teaching...Thank you

  • @vikaspanwar5194
    @vikaspanwar5194 2 года назад

    Watched this video during viva and explained this algo well to my teacher.
    Thanks kunal bhai

  • @sakshijain9637
    @sakshijain9637 2 года назад

    Ur amazing just completed watching selection sort

  • @Mr_Kaif__
    @Mr_Kaif__ 10 месяцев назад

    I just understood that what I have to do and then I made the code logic by myself.
    Thank you so much Kunal bhaiya.

  • @Helly_Patel
    @Helly_Patel 2 года назад +1

    Thanks for teaching us like no one did till now!! One small request, please make lectures on dynamic programming as well!!

  • @priyankashaw1238
    @priyankashaw1238 Год назад

    Your explanations are so detailed that I'm usually able to write programs without even seeing your code.

  • @tolulopemalomo8922
    @tolulopemalomo8922 Год назад

    You explained this so clearly, thank you!

  • @dhworld9428
    @dhworld9428 Год назад

    Kunal u r great person I wish every teacher watch this vdo and tech him students this way🎉

  • @masroorshah4968
    @masroorshah4968 2 года назад +1

    won't come easier than this! great explanation

  • @sujaydey9160
    @sujaydey9160 2 года назад +2

    Usually I don't comment but you made me to like and comment in your videos. You owe me man. Also enjoying your DevOps stuff parallelly. Ahh one thing I want to let you know, I gave my computer networking exam by just watching your networking video twice, nothing else and I nailed it 😉. Hope to meet you one day ❤️

  • @user-code404
    @user-code404 Месяц назад +1

    there is one more implementation of Insertion sort in which the overhead of swap function is avoided.:
    public static int[] optimizedInsertionSort(int[] nums){
    if(nums.length == 0) return new int[0];
    else{
    for (int i = 1; i< nums.length; i++){
    int key = nums[i];
    int j = i- 1;
    while(j>=0 && nums[j] > key){
    nums[j+1] = nums[j];
    j--;
    }
    nums[j+1] = key;
    }
    return nums;
    }
    }

  • @ravindraverma8413
    @ravindraverma8413 11 месяцев назад

    The way to explain complexity is awesome.

  • @swooshruti
    @swooshruti 6 месяцев назад

    It is amazing to learn every step so wonderfully explained by you

  • @piyushkhandelwal1662
    @piyushkhandelwal1662 2 года назад

    Sir you are awesome your explanation is great and one thing i write sir in my every comment because you are like my mentor a real teacher 🤗🤗🤗🤗🤗🤗🤗🤗🤗🤗

  • @wheatleyOX
    @wheatleyOX Год назад

    perfect explanation! thank you very much

  • @Mohit_Gupta24
    @Mohit_Gupta24 3 месяца назад

    One observation - for every pass we are sorting pass + 1 elements of array i.e. when pass = 0(i = 0), 2 elements are sorted.
    This sort happens using swapping technique which can be visualised as ''Bubble sort in reverse' - basically here we are swapping in reverse order - like compare adjacent element and swap and repeat :)
    So the min element of array comes at first index position of array as a part of this swap.

  • @HomesickCoder
    @HomesickCoder 2 года назад +1

    Bhaiya just one word for uh, thankyou guru ji , wishing you a beautiful life ahead I'll meet you one day ❤️

  • @shuklshivam
    @shuklshivam 2 года назад

    Amazing video @kunal. (Concepts == cleared) -> true

  • @akhiluniyal9455
    @akhiluniyal9455 8 месяцев назад

    Thanks kunal that explanation was epic, I was struggling in understanding this concept.

  • @arshsandhu5707
    @arshsandhu5707 Год назад

    His explanation was so good that i was able to write the code myself before checking his ❤❤❤

  • @Iron.agrawal
    @Iron.agrawal 4 месяца назад

    Superb explanation. Absolutely amazing.

  • @KaisarAnvar
    @KaisarAnvar Год назад

    The hardest problem I faced in your lecture was 2D matrix array. I always return back to that video to grasp the details, otherwise everything is CRYSTAL clear!

  • @GOKULK-ll8ur
    @GOKULK-ll8ur 10 месяцев назад

    best explanation bro explained everything that it take only five minutes to code myself

  • @ai_tuberr
    @ai_tuberr 18 дней назад

    Thank you the concepts are very clear now

  • @goswamianshuman
    @goswamianshuman 2 года назад +1

    amazing as always ❤❤

  • @BackEndGenius
    @BackEndGenius Год назад

    Thanks alot for detailed explanation.

  • @vanshsharma2486
    @vanshsharma2486 2 года назад

    great video bro, thank you so much

  • @PROTECHRAHUL
    @PROTECHRAHUL 2 года назад +1

    Kunal bhai Is rocking 😎

  • @md.arslan9789
    @md.arslan9789 Месяц назад

    beautiful explanation!

  • @Content_creater_entertainment
    @Content_creater_entertainment 11 дней назад +1

    Best playlist ever

  • @sojuu.11
    @sojuu.11 28 дней назад +1

    Great teacher.

  • @vishalparashar4976
    @vishalparashar4976 10 месяцев назад

    after you explain i just code it myself thanks sir

  • @nagendratalari1002
    @nagendratalari1002 2 года назад

    Kunal on 🔥.... thank-you ji

  • @nagarjunaakkisetty6801
    @nagarjunaakkisetty6801 Год назад

    Great Kunal sir I loved your explanation man

  • @vinayryuzakikale7247
    @vinayryuzakikale7247 Год назад

    Awesome as always

  • @itishachoudhary906
    @itishachoudhary906 4 месяца назад

    Thank you.
    great explanation...

  • @architkumar1265
    @architkumar1265 2 года назад +1

    Hey Kunal, just want to appreciate your efforts. I love your videos and these videos are actually making my concepts more strong. There was a quick question of mine that is it essential to buy any book for Java or your video lectures and notes are sufficient for placement purpose and other open source contribution purposes...????🙄

  • @ashwinikalyan9437
    @ashwinikalyan9437 2 года назад +2

    Boy's on fireee 🔥🔥🔥

  • @malavipande6693
    @malavipande6693 Год назад

    ThankYou Kunal G!😇

  • @detexter3143
    @detexter3143 2 года назад +1

    dont believe him guys...anyone watching this video just go once through the comment section you will not need more proof that this is the best course on the internet and he has the best teaching skills.... i am an idiot, i hated dsa but the way he teaches it makes me motivated to keep on doing and know what, i am improving my problem solving.... he not only teaches dsa but also the most important skill which is problem solving and how to approach a problem. just believe in this course and keep on solving and supporting this channel.

  • @82hariharan
    @82hariharan 2 года назад +1

    Clearly explained. Thank you.

  • @vedanthbaliga7686
    @vedanthbaliga7686 2 года назад +1

    3 videos in under 24 hours🤯thanks Kunal. Idk how you do this😬

  • @Ankurkumar-jr2ro
    @Ankurkumar-jr2ro Год назад

    you taught the concept so well that now my Genetics also know Insertion sort. Hence my grand children will also be good in sorting now.

  • @rajsumanth9
    @rajsumanth9 2 месяца назад

    Super explanation ❤😊

  • @akhilreddybollu5551
    @akhilreddybollu5551 2 года назад +1

    I love the way you teaching 😍😍🥰🥰

  • @sumitsaha6941
    @sumitsaha6941 Год назад

    Great explanation

  • @sreenivaspakalapati8123
    @sreenivaspakalapati8123 2 года назад +1

    Unstoppable 🔥

  • @ibrahim-lf5he
    @ibrahim-lf5he 2 года назад

    Thanks for the video sir

  • @MadhuH-vd4kb
    @MadhuH-vd4kb Месяц назад

    Bro you are genius.

  • @sanugupta2965
    @sanugupta2965 2 года назад

    Excellent lecture....

  • @Jashu-er7gs
    @Jashu-er7gs 5 месяцев назад +1

    Thankss kunall

  • @saurabhjaswal21
    @saurabhjaswal21 2 года назад

    Great Explanation

  • @10raunakdubey7
    @10raunakdubey7 2 года назад

    bro superbbbbb loving yrr this palylist

  • @arshsharma3591
    @arshsharma3591 2 года назад

    really helpful . thanks

  • @prashantindurkar
    @prashantindurkar 2 года назад

    Killing it on fire 🔥🔥😉

  • @arulkumar998
    @arulkumar998 Год назад

    thank you kunal

  • @nagaarjunk.r3808
    @nagaarjunk.r3808 2 года назад

    🔥🔥 awesome 😎 !!

  • @vinitjain7
    @vinitjain7 11 месяцев назад

    Amazing course

  • @kabir0x23
    @kabir0x23 2 года назад

    great explanation 🚀

  • @samyakshah9119
    @samyakshah9119 16 дней назад

    Great video

  • @sanjairs6934
    @sanjairs6934 2 года назад

    As a beginner,I felt this is better than CLRS pseudocode.

  • @mukulsehgal2190
    @mukulsehgal2190 4 дня назад

    great lecture

  • @CodeforTonight
    @CodeforTonight 2 года назад +1

    Already know the Insertion Sort but I always found something new..like break loop "that's cool".

  • @aritrachatterjee147
    @aritrachatterjee147 2 года назад +6

    Hey Kunal I commented on the last video also ,, it's good that you are uploading in a regular basis ❤️ my question is will there be any long video like the one of binary search where u explained every possible topic questions... Will there be that kind of video for sorting? Just wanted to ask thanks ❤️

    • @KunalKushwaha
      @KunalKushwaha  2 года назад +5

      Yes there will be many over the course, because sorting is combination of many concepts

  • @jithuboi
    @jithuboi Год назад

    Thank you.

  • @ashwani3220
    @ashwani3220 2 года назад

    please continue this series

  • @yatinchauhan1710
    @yatinchauhan1710 Год назад

    finally i understood the insertion sort.

  • @ShivamDubey1
    @ShivamDubey1 2 года назад +1

    Now, Kunal is in Form 😎

  • @nandakumarreddy1500
    @nandakumarreddy1500 Год назад +1

    Actually I am getting same no.of swaps in insertion sort and bubble sort ,can you please resolve my issue.

  • @cindrasenareddy1929
    @cindrasenareddy1929 Год назад +1

    gurujii!!!!!!!!!!!!!!!!! u are great

  • @abhineveash
    @abhineveash 3 месяца назад

    awesome video