An In-Depth Algorithmic Analysis of Bubble Sort. Best Case, Average 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: Analyze the exact amount of comparisons and swaps for the best, average, and worst case of Bubble Sort.
This took 2 hours to record and 2 hours to edit. Hope it helps.
Gauss's formula: mathcentral.uregina.ca/qq/data...
Expected Value: www.statisticshowto.datascien...
++++++++++++++++++++++++++++++++++++++++++++++++++
HackerRank: / @hackerrankofficial
Tuschar Roy: / tusharroy2525
GeeksForGeeks: / @geeksforgeeksvideos
Jarvis Johnson: / vsympathyv
Success In Tech: / @successintech

Пікірлер: 117

  • @BackToBackSWE
    @BackToBackSWE5 жыл бұрын

    Table of Contents: (this is a long one, grab some popcorn) We Will Do Something Different 0:00 - 0:17 Self Promotion 0:17 - 0:33 The 2 Fundamental Operations of Comparison Sorting Algorithms 0:33 - 0:46 Introducing How Bubble Sort Works 0:46 - 2:18 We Begin To Bubble An Item Up 2:18 - 3:21 We Continue Comparisons 3:21 - 4:27 1st Outer Loop Pass Is Done, 2nd Outer Loop Pass Now 4:27 - 5:01 Our Mission Today 5:01 - 5:45 The Best, Average, and Worst Cases For Input To Bubble Sort 5:45 - 6:05 The Best Case 6:05 - 6:56 The Worst Case 6:56 - 7:40 The Average Case 7:40 - 8:06 Summation Notation 8:06 - 9:30 Gauss Formula 9:30 - 10:27 Worst Case Analysis 10:27 - 11:59 We Got Kicked Out... 11:59 - 12:06 Worst Case Analysis (continued) 12:06 - 13:16 Our Task Is Now To Simplify 13:16 - 13:49 What Does The Inner For Loop really Say? 13:49 - 15:32 Simplifying The Inner For Loop 15:32 - 16:11 Our Last Task: Simplifying The Outer For Loop 16:11 - 19:02 We Use Gauss' Trick To Simplify The Outer For Loop 19:02 - 19:20 The Final Value For Worst Case Swaps In Terms of N 19:20 - 19:57 Geekin' 19:57 - 20:07 For The Worst Case, # of Comparisons = # of Swaps 20:07 - 20:36 A Bus Interrupts Me 20:36 - 20:40 The Best Case Does No Swaps 21:00 - 21:34 Expected Value Definition (So We Can Analyze The Average Case) 21:34 - 23:43 Let's Calculate The Swaps For The Average Case Now 23:43 - 26:10 Final Answer For The Average Case 26:10 - 27:42 Subscribe 27:42 - 28:26 The code for bubble sort is in the description. This took forever to make.

  • @bixbyknolls
    @bixbyknolls5 жыл бұрын

    I have no doubt this will be one of largest channels out there for SE interview prep. keep going bro!

  • @BackToBackSWE

    @BackToBackSWE

    5 жыл бұрын

    haha thanks

  • @spectermakoto9029

    @spectermakoto9029

    5 жыл бұрын

    I hope not small niche channels are the best

  • @BackToBackSWE

    @BackToBackSWE

    4 жыл бұрын

    @@spectermakoto9029 wut

  • @takatakboy
    @takatakboy4 жыл бұрын

    Ive watched so many interview review channels and youre the easily one of the best out there. I hope the channel gets more traction. Just pure easy to understand analysis that struggling learners need. Youre a god sent. Thank you.

  • @BackToBackSWE

    @BackToBackSWE

    4 жыл бұрын

    sure

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

    Wow, thank you. I'm literally half way through my semester in data structures and I finally feel like I can see the connection between the concept and the code. I was totally stuck. Your explanations are awesome!

  • @larah2682
    @larah26823 жыл бұрын

    The most helpful video ever! Thank you for taking the time to do this.

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

    OMG this is so helpful thank you so much for making this video! I have an exam tomorrow and this is the best study material I've found. Thank you for putting in the effort!!

  • @BackToBackSWE

    @BackToBackSWE

    5 жыл бұрын

    sure, I think I'm in your class haha

  • @RedExpert2000
    @RedExpert20002 жыл бұрын

    Brilliance at its best. Good job man. Thumbs up as i understood the topic really well from your video

  • @bssun2849
    @bssun28494 жыл бұрын

    This is definitely one (maybe the one) of the best channel!

  • @BackToBackSWE

    @BackToBackSWE

    4 жыл бұрын

    thx

  • @michaeldemse3944
    @michaeldemse39444 жыл бұрын

    Everything about this video is perfect. Thank you.

  • @BackToBackSWE

    @BackToBackSWE

    4 жыл бұрын

    nice, u perfect

  • @ManishKumar-rz9ub
    @ManishKumar-rz9ub5 ай бұрын

    Awesome explanation!!!

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

    Very ,very thorough explanation. Excellent.

  • @ozzyfromspace
    @ozzyfromspace3 жыл бұрын

    I wish you and your channel the very best bro! 🙏🏽✨☝🏽🎊

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

    this is just amazing , thank you

  • @jl_woodworks
    @jl_woodworks3 жыл бұрын

    I chuckled when you said you weren't sure what Gauss' last name was. Nice video. Your content is awesome.

  • @navyabinu74
    @navyabinu744 жыл бұрын

    thank you so much.....this video helps me to understand the topic clearly.

  • @BackToBackSWE

    @BackToBackSWE

    4 жыл бұрын

    great

  • @alvin78269
    @alvin782693 жыл бұрын

    This really helps me a lot. Thanks!

  • @BackToBackSWE

    @BackToBackSWE

    3 жыл бұрын

    great

  • @magneticrohit9855
    @magneticrohit98553 жыл бұрын

    Keep the good work going on brother...

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

    Hey man, I just wanted to take the time to appreciate your teaching skills, it is a gift. you literally just taught someone who does not have a degree in anything but passionate about Software development bubble sort and mathematics, truly appreciate your work a lot. If you need people to mentor please let me know I am in

  • @BackToBackSWE

    @BackToBackSWE

    4 жыл бұрын

    Thx and wym

  • @iambongani

    @iambongani

    4 жыл бұрын

    @@BackToBackSWE I mean, I just started learning how to code with a remote school and solving algorithms is one of the biggest things I really want to be good at. I am a step by step kind of a person. I don't like cramming things but I want to know the in depth. Just like your classes. So if you ever want to teach a beginner I am available. Or if you have material I can buy from you that you wrote please I'd like to support your movement

  • @master4755
    @master47553 жыл бұрын

    You have become my fav teacher :)

  • @Calisthenoob
    @Calisthenoob5 жыл бұрын

    You’re gonna get really big soon!

  • @BackToBackSWE

    @BackToBackSWE

    5 жыл бұрын

    haha, maybe...maybe not. I'm content doing what I'm doing.

  • @FadillahZakiyah
    @FadillahZakiyah3 жыл бұрын

    This video is very useful, thank you so much.

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

    just found a great channel for algo and data struc

  • @mohamedalaty7632
    @mohamedalaty76323 жыл бұрын

    شكرا علي الشرح الوافي والممتع تحياتي من ليبيا

  • @Firstusee256
    @Firstusee2565 жыл бұрын

    Please make videos on merge , quick sort and counting sort..

  • @BackToBackSWE

    @BackToBackSWE

    5 жыл бұрын

    k

  • @ThaiNguyen-gg8xj
    @ThaiNguyen-gg8xj2 жыл бұрын

    Thank you many times. You've been helping me a lot.

  • @BackToBackSWE

    @BackToBackSWE

    2 жыл бұрын

    Thank you, we have got your back!! 😀 Do check out backtobackswe.com/platform/content and please recommend us to your family and friends 😀

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

    Thank you so much

  • @cuerpoymentesaludables
    @cuerpoymentesaludables4 ай бұрын

    It's the best explanation. Thank you for sharing.

  • @meczupmeczup1193
    @meczupmeczup11932 жыл бұрын

    Greetings from Turkey, thank you for your nice explanation.

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

    Great video as always

  • @BackToBackSWE

    @BackToBackSWE

    4 жыл бұрын

    thx

  • @mithunshaha4342
    @mithunshaha43424 жыл бұрын

    many many thanks to you bro,for your hard working to creaate this type of excellent tutorial.it is my request to you for creating merge sort algorithm .

  • @BackToBackSWE

    @BackToBackSWE

    4 жыл бұрын

    I already did

  • @emankamal-5628
    @emankamal-56284 жыл бұрын

    very nice explaining ! thank u

  • @BackToBackSWE

    @BackToBackSWE

    4 жыл бұрын

    sure

  • @lokeshprajapati9197
    @lokeshprajapati91975 жыл бұрын

    so much explanation. keep it up bro

  • @BackToBackSWE

    @BackToBackSWE

    5 жыл бұрын

    thanks

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

    Hey bro, this was a really nice video and I understood most of it, I didn't quite follow the pseudocode though. I wasn't sure why you started as i=2 for the summation. Other than that it clarified my doubts on how bubble sort works

  • @shrshawn
    @shrshawn3 жыл бұрын

    Really love ur videos! best till now for me. Also, what is the name of the music at the end?

  • @manojg4451
    @manojg44515 жыл бұрын

    Appreciate the effort.Kindly, make sure that the viewer can see the pseudo code while manually implementing the algorithm, so that we can compare it with implementation

  • @BackToBackSWE

    @BackToBackSWE

    5 жыл бұрын

    k

  • @Nico-rl4bo
    @Nico-rl4bo2 жыл бұрын

    good video :)

  • @tmt023
    @tmt0233 жыл бұрын

    So what will be the best case time complexity? Is it O(n^2) according to your algorithm?

  • @BackToBackSWE

    @BackToBackSWE

    3 жыл бұрын

    Yes. O(n) is the best case for (modified) bubble sort if the array is already sorted, there is another video for that

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

    Can you make a video on loop invariant ant

  • @pariiyiy3147
    @pariiyiy31474 жыл бұрын

    God bless you! You saved me!

  • @BackToBackSWE

    @BackToBackSWE

    4 жыл бұрын

    ye

  • @TheChromeLegend
    @TheChromeLegend5 жыл бұрын

    Another great video. What do you think about competitive programming?

  • @BackToBackSWE

    @BackToBackSWE

    5 жыл бұрын

    Haven't tried it, but it is very similar to what we basically get asked in SWE interviews. Good book on it (only skimmed this): cses.fi/book/

  • @jimwin2011
    @jimwin20114 жыл бұрын

    Beautiful👌👏👏

  • @BackToBackSWE

    @BackToBackSWE

    4 жыл бұрын

    ye

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

    in my opinion you are better than mit.Thankyou for depth

  • @BackToBackSWE

    @BackToBackSWE

    Жыл бұрын

    Thank you Surendra 🎉 Please enjoy a special coupon from us - backtobackswe.com/checkout?plan=lifetime-legacy&discount_code=SUB 🚀

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

    I rarely write comments. But this video is very useful. Thank you so much for all the efforts and keep doing great content.

  • @BackToBackSWE

    @BackToBackSWE

    Жыл бұрын

    Thank you, means a lot 🎉 You can also check out our free DSA course - backtobackswe.com/

  • @keredo854
    @keredo8543 жыл бұрын

    you're amazing.

  • @BackToBackSWE

    @BackToBackSWE

    3 жыл бұрын

    thx

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

    love u life saver

  • @BackToBackSWE

    @BackToBackSWE

    Жыл бұрын

    Thank you 🎉 Please enjoy a special coupon from us - backtobackswe.com/checkout?plan=lifetime-legacy&discount_code=SUB 🚀

  • @RedExpert2000
    @RedExpert20002 жыл бұрын

    Does the value of 2 is user input?

  • @ikaros9727
    @ikaros97274 жыл бұрын

    Hey. Im having some understand issues with 19:37. Why to we change n to n-1 in Gauss Formula? Is it because of the i-1 or because we start with i = 2 instead of i = 1? And doesnt the i = 2 for i -1 negate itself so we start to count from 1 to n? Feels like in that case we could use Gauss Formula as it is. Best regards

  • @BackToBackSWE

    @BackToBackSWE

    4 жыл бұрын

    I don't remember the math much in this video

  • @AARUSHPRATIMAYANK

    @AARUSHPRATIMAYANK

    4 жыл бұрын

    Gauss formula will not work the way you are expecting. n is relaced with n-1 because of the lower bound 2. The precise answer would be (n(n-1) /2 ) -1

  • @Firstusee256
    @Firstusee2565 жыл бұрын

    Awesome...

  • @BackToBackSWE

    @BackToBackSWE

    5 жыл бұрын

    hey

  • @yigithansaglam9128
    @yigithansaglam91283 жыл бұрын

    thanks bro

  • @BackToBackSWE

    @BackToBackSWE

    3 жыл бұрын

    Any time

  • @husainkanchwala6918
    @husainkanchwala69184 жыл бұрын

    At 20:51 the formula for runtime is n(n-1)/2 where in best case scenario n will be 0 as there will be no swapping leading to best-case runtime to O(1) which is not correct best-case complexity for the bubble sort. Bubble sort best-case runtime is achieved by modifying the algorithm to have a flag to break the outer loop if the array is already sorted leading to have the best case O(n). Otherwise with the solution you mentioned even the best-case scenario will give runtime of O(n2).

  • @BackToBackSWE

    @BackToBackSWE

    4 жыл бұрын

    This is too long to read (im fast replying to comments) but i love you

  • @MrEdibles
    @MrEdibles3 жыл бұрын

    For avg case, wouldn't the notation be sigma instead of O? Nice explanation though!

  • @undergradalgo2248
    @undergradalgo22485 жыл бұрын

    How would you find the sum of possibilities if we had 6 different color on dice instead of 6 different numbers?

  • @BackToBackSWE

    @BackToBackSWE

    5 жыл бұрын

    That is a really good question. I'm honestly not sure. EV is attained by multiplying each possible outcome's value by the likelihood the outcome will happen. Then taking the sum across the values. When the outcome is a qualitative measure that scrambles my brain. Here are some things I pulled up from researching this: Random Variables Aren't Always Numbers: www.quora.com/Does-a-random-variable-always-take-on-values-that-are-numbers Assigning Values To Qualitative Outcomes: math.stackexchange.com/questions/1700381/expected-value-of-a-coin-toss Doesn't do much but, ah well, I'll figure this out someday.

  • @cocoarecords
    @cocoarecords4 жыл бұрын

    amazing

  • @BackToBackSWE

    @BackToBackSWE

    4 жыл бұрын

    thanks

  • @radhikarajani439
    @radhikarajani4394 жыл бұрын

    Vry gud performance I likes it

  • @BackToBackSWE

    @BackToBackSWE

    4 жыл бұрын

    thx

  • @mohammedarafat8059
    @mohammedarafat80595 жыл бұрын

    You're the fucking man, I have a algorithms exam on tuesday and this video helped a lot, someone already said it but if you could do analysis of merge, heap, and insertion sort thatd be amazing

  • @BackToBackSWE

    @BackToBackSWE

    5 жыл бұрын

    I have done all of those.

  • @mohammedarafat8059

    @mohammedarafat8059

    5 жыл бұрын

    I just saw, thank you bro for the knowledge, you're a lifesaver! P.S: I see you do vids at UMD, I'm actually a student there, I'm using your videos to study for my 351 exam haha

  • @BackToBackSWE

    @BackToBackSWE

    5 жыл бұрын

    @@mohammedarafat8059 hahahaha, hey, can you do me a favor and share the heap sort video in piazza? It'd be weird if I did it. Or not...I don't really care but I think it'd help many people.

  • @mohammedarafat8059

    @mohammedarafat8059

    5 жыл бұрын

    ​@@BackToBackSWE I'm not on the piazza for this class, never signed up lol, but I sent your vids to a few ppl, one who knows you too btw, who are taking it. You should post the bubble and insertion sort vids on there tho bc those were really helpful for the practice exam. It's not weird if you're promoting a service you provide if its useful to the people you're promoting it to. Self promo is only weird if you're promoting a service in a setting where no one wants to hear it, and trust me the ppl in my class need your vids lol

  • @BackToBackSWE

    @BackToBackSWE

    5 жыл бұрын

    @@mohammedarafat8059 Eh, I don't feel comfortable forcing it

  • @anweshadatta7670
    @anweshadatta76705 жыл бұрын

    Sir you are doing this analysis informally as you are using the average,then how can you write E[X]?? Because we know that E[X]=sum(x.P{X=x}).

  • @BackToBackSWE

    @BackToBackSWE

    4 жыл бұрын

    I haven't replied to this for a bit, replying to close this out in my "unresponded to comments" feed.

  • @babon_zia
    @babon_zia4 жыл бұрын

    hi can you help me about bubble sorting index complexity big O and omega / (a1,a2,...............................an) n>=2

  • @BackToBackSWE

    @BackToBackSWE

    4 жыл бұрын

    wassup

  • @nabi7600
    @nabi76004 жыл бұрын

    Wikipedia says n# swaps for average is O(n) .. not O(n^2) why?

  • @BackToBackSWE

    @BackToBackSWE

    4 жыл бұрын

    Can u link - not sure what you are referencing

  • @nabi7600

    @nabi7600

    4 жыл бұрын

    @@BackToBackSWE sorry it was n# comparisons

  • @anweshadatta7670
    @anweshadatta76705 жыл бұрын

    You are great sir 😍.Love from India..

  • @BackToBackSWE

    @BackToBackSWE

    5 жыл бұрын

    thanks

  • @kylei6216
    @kylei62164 жыл бұрын

    22:19

  • @BackToBackSWE

    @BackToBackSWE

    4 жыл бұрын

    what did I do?

  • @_why_3881
    @_why_38812 жыл бұрын

    Well it is Gauß 🤣🤣🤣 9:38

  • @_why_3881

    @_why_3881

    2 жыл бұрын

    Seems like this bug went unnoticed for 3yrs kappa

  • @abdullahalimran4416
    @abdullahalimran44164 жыл бұрын

    When swap is done, i = i-1

  • @BackToBackSWE

    @BackToBackSWE

    4 жыл бұрын

    what

  • @ozzDeveveloperOpenForWork
    @ozzDeveveloperOpenForWork2 ай бұрын

    why dont you before starting always remind people that the position of n is the index and it starts at 0 always, so we do i+1? i feel like a constant reminder would help. or maybe everyone knows this and I'm new so I need this but everyone else already ahead of me :D

  • @strokiytytytyt
    @strokiytytytyt6 ай бұрын

    ajmoooo majstorreeee

  • @CarlosSousa-wn1sn
    @CarlosSousa-wn1sn3 жыл бұрын

    I'm so lost in all this :(

  • @BackToBackSWE

    @BackToBackSWE

    3 жыл бұрын

    what is confusing, lemme know

  • @jonnyevans1115
    @jonnyevans11156 ай бұрын

    So great

Келесі