Merge Sort Algorithm in Java - Full Tutorial with Source

แชร์
ฝัง
  • เผยแพร่เมื่อ 10 เม.ย. 2021
  • Complete Java course: codingwithjohn.thinkific.com/...
    Full source code available HERE: codingwithjohn.com/merge-sort...
    Coding the Merge Sort algorithm in Java with recursion! Can we sort 100,000,000, or even 1 billion ints?
    This is a slightly more complex recursive Java coding lesson tutorial, where we'll use recursion to write our own implementation of VERY efficient Merge Sort sorting algorithm in Java.
    Merge Sort is a fantastic sorting algorithm, a little more advanced but great algorithm for intermediate Java students to learn.
    Learn or improve your Java by watching it being coded live!
    Hey, I'm John! I'm a Lead Java Software Engineer who has been in the industry for more than a decade. I love sharing what I've learned over the years in a way that's understandable for all levels of Java developers.
    Let me know what else you'd like to see!
    Links to any stuff in this description are affiliate links, so if you buy a product through those links I may earn a small commission.
    📕 THE best book to learn Java, Effective Java by Joshua Bloch
    amzn.to/36AfdUu
    📕 One of my favorite programming books, Clean Code by Robert Martin
    amzn.to/3GTPVhf
    🎧 Or get the audio version of Clean Code for FREE here with an Audible free trial
    www.audibletrial.com/johnclean...
    🖥️Standing desk brand I use for recording (get a code for $30 off through this link!)
    bit.ly/3QPNGko
    📹Phone I use for recording:
    amzn.to/3HepYJu
    🎙️Microphone I use (classy, I know):
    amzn.to/3AYGdbz
    Donate with PayPal (Thank you so much!)
    www.paypal.com/donate/?hosted...
    ☕Complete Java course:
    codingwithjohn.thinkific.com/...
    codingwithjohn.com
  • วิทยาศาสตร์และเทคโนโลยี

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

  • @nguyencongthaisonk14hcm57
    @nguyencongthaisonk14hcm57 2 ปีที่แล้ว +34

    I'm very weak in algorithms. From watching your video, the tutorial is very easy to understand. I understand how merge sort works. Thank you very much from the Vietnamese guy !

    • @CodingWithJohn
      @CodingWithJohn  2 ปีที่แล้ว +8

      Thanks Vietnamese Guy! Very glad I was able to help!

  • @metdelta1
    @metdelta1 2 ปีที่แล้ว +178

    Perhaps the BEST explanation of Merge Sort out there. 👍🏻
    The code along with variable names, justifies the natural thinking of the human mind.
    Thanks a lot ❤️
    Subscribed ✅
    Best wishes and hope your channel gets all the love and support it deserves.

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

      Agreed, he explained it clearly and step by step, such a great explanation!!!

  • @akosdanielbollok4956
    @akosdanielbollok4956 ปีที่แล้ว +51

    This is pure gold! I wish you did a full Data structures&algorithms course, that would be awesome.

  • @moeal5110
    @moeal5110 2 ปีที่แล้ว +52

    I watched and read neumors explanations about this but only after watching your video I was able to understand each line and now I can see it in my brain's eyes. I also dreamt about it. Thanks a lot! Please do more

  • @mir.9805
    @mir.9805 ปีที่แล้ว +27

    I can't believe I've watched this entire video and without being bored. I can't even sit in class for 15 minutes without going to sleep and I'm literally watching this at 2:32am in bed.

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

    I've been searching for a good explanation and a good clean code
    but luckily !! i found both in one video
    you're an amazing guy

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

      true a clean code is a must for understanding ....

  • @taldennis8058
    @taldennis8058 2 ปีที่แล้ว +25

    This video is something else, I watched all the big channels before I got here, this explanation is by far the most detailed and the most accurate,
    also providing an explanation for all the edge cases.
    the implementation is super clear and clean.
    this channel is underrated, I wish I knew this channel earlier.
    thank you so much, you're the best!!

  • @cr8444
    @cr8444 2 ปีที่แล้ว +5

    I can't thank you enough for this clean explanation. I haven't been able to understand this algorithm until I stumbled on your video. Now I practically know what each line of code means. You're a genius!!

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

    I had to watch more than once to really absorb the info. It still is a lot less time and money than it costs me to listen to lectures at my university. Thank you for taking the time to make this video!

  • @akshaypatel9982
    @akshaypatel9982 2 ปีที่แล้ว +9

    Wow, the first explanation that made complete sense with 0 confusion.Thank you very much! Wish you were my teacher back in college lol

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

    Seriously I love the content you make, its made my learning much more better. You're so relaxed and calm about the way you explain your code. Good job!!

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

    John you did an awesome job in this video! You're the best course I could find on the merge sort algorithm. I really want to thank you from France for that. Keep up the good work :)

  • @J-wm4ss
    @J-wm4ss 2 ปีที่แล้ว +3

    Thanks! This makes SO MUCH MORE SENSE than other explanations!

  • @HisExcellencyAKK
    @HisExcellencyAKK 2 ปีที่แล้ว +15

    Great work! possibly memory can be improved a bit by passing indices (start, mid, end) into split subroutine instead of sub arrays. We would only need an auxiliary space of size n at merge subroutine. Since merge subroutine happens after split subroutines, the maximum auxiliary space that will be needed is n instead of n*log(n).

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

    Absolutely brilliant explanation! I was so confused for a school assignment on why the last two while loops exist in the code. Turns out it was just cleanup!

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

    Gave the link to this in the comments of every video I watched to understand merge sort because this is the best explanation of Merge sort. Thanks a lot man!!! Subscribed

  • @AceNinja1101
    @AceNinja1101 2 ปีที่แล้ว +8

    Very informative video! Really could have used this back when I was in college lol. Also just attempted to run this with 1 billion elements and took about 8 and half minutes using C# for anyone who's curious!

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

    Hi Mr. John, I've seen so many videos on different algorithms of other people but your explanation is crystal clear and unique

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

    You do not know how much I looked around for a better explanation. You nailed it. Earned a new subbie.

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

    Hands down this is the best sorting algorithm video i have seen on youtube. Thanks John

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

    Great work John, really appreciate it. Highly undervalued channel. Hope you get the support you deserve.

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

    What an excellent explanation !! Simple, clear and concise. Thank you very much.

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

    I am looking for this kind of explanation for a long time. Thank you so much john for this extraordinary tutorial. Loved it and subscribed immediatley.

  • @haidaralihammoud2686
    @haidaralihammoud2686 6 หลายเดือนก่อน +1

    That is by far the best explanation out there! Amazing technique of teaching and breaking it down. Thanks a lot!

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

    Very good illustration and easy to understand steps. I have stumbled upon the videos of John by accident, and I am really happy that I have. Kudos to you. subscribed :) .

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

    Whenever I need to refer algorithms I will directly watch your videos thanks for explaining so clearly.

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

    The only person on yt that actually explained the merge subroutine properly, thanks, +1 sub

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

    I was so frustrated and sad about not understanding the merge sort. Your explnation is very clear, made my day. Thanks a lot! :)

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

    For such comprehensive&best merge sort out there, you won a subscriber. Thanks.

  • @BlueHat1
    @BlueHat1 10 หลายเดือนก่อน +1

    This is the best explanation of merge sort I've ever heard. Thank you!!

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

    my english is not good to understand all words you said but when i look into your code i absolutely understand all, thank you very much.

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

    Such a calm and beautiful explanation for merge sort algo , loved it. And yeah ,you earned a new subscriber.

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

    This video is insanely well made!! Good job :)

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

    You are, without a doubt, one of the most talented educators I've come across (both online and offline).

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

    Honestly, this is the best video I have ever seen about merge sort.

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

    I love your easy amazing explanation of the code and the concept, thank you so much ❤️

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

    I've finilly learned this. Thanks a lot dude!

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

    Finally I got this!!!
    Thank you!!!
    The best explanation so far!!!

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

    Thank you. Watched the video. Went to the code. Copied it down with a pen on paper to understand better. Rewatched the video. I think I have grasped it.

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

    great, you are the only one that explained it in a way that i understand

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

    Great video, super easy to follow and made understanding merge sort way easier

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

    This is by far the best tutorial for merge sort, thanks so much

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

    Hey Bro, it is for sure, one of the best tutorial about this subject I ever saw, I was struggling to understand it, but now it´s clearwater!!!!!
    Thanks for that.
    Greetings from Brazil.

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

    Thank you so much! This was super helpful for my assignment. I feel like I really understand now.

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

    awesome video! couldn't understand merge sort at all before this explanation, thank you so much

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

    Really good explanation! Thanks John! Your videos are spot on!

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

    This is by far the best sorting app I've seen someone code. Awesome.

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

    Great explanation John! It was easy to learn and understand this algorithm with your lesson!

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

    You are such a good teacher. Very talented at communicating information and concepts. 1 million sorted thanks to you.

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

    Are you planning to make a series out of these algorithms? Because having a video on quicksort, heapsort, etc from you would be super amazing and helpful

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

    You really made it look so easy and understandable

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

    Hi John! Thanks a lot for your video. Quite helpful for my C++ programming assignment. Cheers!

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

    Loved every second of it!

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

    Professors at top CS programs like UC Berkeley (where I suffered) aren't able to explain this stuff as well and as clearly as you in multiple 2-hour-long lectures. From the bottom of my heart, I thank you for existing.

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

    Subscribed! Helped me through my Algo and data structure unit!! Best coding tutorial out here!!

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

    Your videos let me fall in love with java! So much Java fun!

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

    Thank you, this explanation is so clear and short.

  • @user-xc9ne4oq3r
    @user-xc9ne4oq3r 2 ปีที่แล้ว

    This is really great! you make it really easy. Thank you for your work!

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

    Keep it up man, your videos are absolutely amazing

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

    Thanks John! Very clear explanation

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

    That explanation was AMAZING ! Thank you !

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

    thanks alot i was reall struggling to learn merging sorted arrays ,but this video rwas eally helped me then all the others that i watched

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

    Best lecture on the subject I've come across. Love the demo at the end too. I know there's a way to write this algorithm with 1 helper array (instead of creating new arrays all the time), it seems not to have mattered too much.

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

    This video is amazing! Thank you for your explanation!!

  • @user-pb6ps2mb4y
    @user-pb6ps2mb4y ปีที่แล้ว

    Awesome explanation! As usual!!!
    Thank you, John, so much!!!!
    You're the best!!😊

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

    Super clean coding! Thank you

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

    Best one, getting addicted to your videos!!!

  • @jeremy-hq9de
    @jeremy-hq9de 4 หลายเดือนก่อน

    Helped alot, thanks!

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

    This is really helpful! Thank you for your work!

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

    straight to my brain .thanks!

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

    love this tutorial, thanks for the amazing explanation and for sharing it

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

    Definitely the best explanation out there. I'm subscribed.

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

    This really helped me. Many many thanks!!!

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

    I liked the way u describe the stuff so clear and nice

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

    Great video THANKS JOHN!!

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

    Thank you so much for the explanation. You’re a life saver 😄

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

    Amazing teaching skills - perfection execution

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

    This is super helpful and very well presented! Thanks!

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

    wow, this is a rlly good explanation, thank you so much, i look forward to any of your new videos. do you think if you can do a video on multithread performance optimization

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

    Thank u john for putting it in my head!
    u got a lifetime subscriber.

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

    seriously one of the best merge sort explanation

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

    Excellent explanation John

  • @Eww...NotTheHumansAgain
    @Eww...NotTheHumansAgain ปีที่แล้ว

    Thank you very much for this clear like crystal explanation!

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

    Thanks, your explanation is very clear.

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

    I like this. I wish there more algorithm tutorials based in java. Please make more.

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

    Please please do make videos on all algorithms. Its the best and non confusing explanation ever. Cheers mate.

  • @AliBulut-tg6bh
    @AliBulut-tg6bh 4 หลายเดือนก่อน

    We all have been taught that merge sort is a fast efficient but memory poor algorithm. But to actually see that happen really changes things. I think it was the first time I saw someone pushing the algorithm to its limit memory-wise. Thank you sir, it was a great explanation.

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

    Thanks John for a real good explanation of Merge Sort algorithm with code.

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

    Amazing guide, thank you.

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

    worked amazing!

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

    Really nicely explained

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

    Thank you, Sir. This was great. Would love to see you take a run at all Algos. Maybe Bucket Sort?

  • @cesar-on-youtube
    @cesar-on-youtube ปีที่แล้ว

    You're an excellent teacher. Thank you.

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

    the best...this algorithm stuck in my mind hardly

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

    Thank you for this great tutorial!

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

    Thank you for these videos.yours explanations are amazing and really clear. Can you do more algorithms too please

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

    im new to this channel and already loving the short gem contents

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

      Me too I just started an apprenticeship recently for Software Engineering and this channel has helped a ton on understanding some of the more complex features of the Java language.

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

    great work. thanks for sharing.

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

    Thank you so much for this!

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

    Really awesome john🎉!❤