Merge Sort | Algorithm | Pseudocode | Dry Run | Code | Strivers A2Z DSA Course

Sdílet
Vložit
  • čas přidán 8. 07. 2024
  • Problem Link: bit.ly/3DN7ccC
    Full Course With Notes: takeuforward.org/strivers-a2z...
    Notes/C++/Java/Python Codes: takeuforward.org/data-structu...
    You can follow me across social media, all my handles are below:
    Linkedin/Instagram/Telegram: linktr.ee/takeUforward
    00:00 - MERGE SORT - O(N log N)
    1:16 - What is Merge sort
    3:00- Algorithm
    17:15 - approach
    20:34 - pseudo code
    25:00 - dry run on divide (pseudo code breakdown)
    32:42 - approach of merge
    33:46 - pseudo code of merge
    40:33 - Code
    44:10 - Time complexity analysis
    48:05 - Space complexity analysis

Komentáře • 841

  • @takeUforward
    @takeUforward  Před rokem +165

    Let's march ahead, and create an unmatchable DSA course! ❤
    Can someone please add timestamps, I will add them post-it.

    • @msdarshankirthic9990
      @msdarshankirthic9990 Před rokem +4

      time stamps done bro

    • @harshavardhan184
      @harshavardhan184 Před rokem +5

      Bhai please upload videos asap..😭we from a normal tier 3 college are hoping for your videos...pls don't late

    • @harshavardhan184
      @harshavardhan184 Před rokem +4

      #striver pls make videos faster bhai 😭

    • @harshavardhan184
      @harshavardhan184 Před rokem +4

      #striver pls make videos faster bhai 😭..your content is too gud ...but our placements are going on fastly

    • @Shubham-bh1ph
      @Shubham-bh1ph Před rokem +3

      Bhaiya please be fast in terms of uploading videos 😭😭😭

  • @Akash-xr6we
    @Akash-xr6we Před rokem +444

    inspiration recording at 3 am when he can create content with so much dedication then why can't we learn dsa with same dedication hats off to you man.💯💯

    • @random-xl3zm
      @random-xl3zm Před 6 měsíci +3

      190 + likes to this comment but no sub comments
      Lemme fix it

    • @random-xl3zm
      @random-xl3zm Před 6 měsíci +8

      Hare krishna

    • @random-xl3zm
      @random-xl3zm Před 6 měsíci +10

      Hare krishna hare krishna krishna krishna hare hare
      Hare rama hare rama rama rama hare hare
      Chant this and be happy

    • @Akash-xr6we
      @Akash-xr6we Před 6 měsíci +1

      @@random-xl3zm 😂😂 thanks dude

    • @random-xl3zm
      @random-xl3zm Před 6 měsíci +8

      @@Akash-xr6we no worries
      Jai siya ram😁

  • @raodevendrasingh
    @raodevendrasingh Před rokem +158

    just woke up and started doing dsa, and you are recording it at midnight, your efforts are not wasted at all Sir!! Thank you for providing such quality content for free.

    • @hiteshpanchal5772
      @hiteshpanchal5772 Před rokem +13

      same brother.............i was watching the video suddenly at last striver said it's 3.30am and i just felt sham on my self boz he is teaching till night and i don't learn genuinely..

  • @msdarshankirthic9990
    @msdarshankirthic9990 Před rokem +134

    MERGE SORT - O(nlogn) - divide and conquer
    1:16 - What is and Why Merge sort
    3:00- Divide
    5:54- Merge
    Pseudo code
    17:15 - approach (divide)
    20:34 - pseudo code (divide)
    25:00 - dry run on divide (pseudo code breakdown)
    32:42 - approach (merge)
    33:46 - pseudo code (merge)
    40:33 - C++ code
    44:10 - Time complexity analysis
    48:05 - Space complexity analysis

  • @expl0itr
    @expl0itr Před 3 měsíci +25

    In 4 years of college, when teachers came to copy and paste from their 10year old notes I couldn't gain any interest in DSA and felt stupid and never touched the topic post exam. And everything instantly clicked when I watched this video. Honestly your course is giving me insane confidence already. Hope I can make a change within a year, though it's difficult after doing full-time job but I get my confidence back when i see you making this huge stuff after working same or more hours. Planning to stay consistent! Thanks a lot!
    PS: We have the same chair 😁

  • @darshanakv4946
    @darshanakv4946 Před 2 měsíci +24

    The title "STRIVER" for a reason!!✅

  • @amitpatil6244
    @amitpatil6244 Před rokem +37

    This is called content 🤓✨

  • @saivarun5529
    @saivarun5529 Před rokem +23

    Superb explanation, sat for around 4hrs to understand how merge sort is working and then I found this video. Understood clearly within 50mins. Very nice and deep explanation.

  • @prathamesh_utube
    @prathamesh_utube Před rokem +18

    Thanks Striver, I 'understood' it perfectly! This channel has the potential to become huge with content like this.

  • @deveshmanitripathi9419
    @deveshmanitripathi9419 Před rokem +18

    Striver teaching how to code is just like a story. It really seems so easy to understand 😊

  • @varuntanwar6746
    @varuntanwar6746 Před rokem +3

    I hope you realize how much value you are creating. It's much more than you think. Thanks a lot!!

  • @payaljain6825
    @payaljain6825 Před 11 měsíci +7

    This level of clarity would have never been possible without ur video. Your energy of teaching any topic is what makes it more interesting. 🤟

  • @kaizjessani7303
    @kaizjessani7303 Před rokem +30

    In my 4 years of engineering and 7 years of work experience, I finally understood merge sort with recursion. I can finally move ahead and sleep properly😂 Thank you so much. Really appreciated 🙏🙏🙏 Love you bro ❤

  • @Pooja-we3xs
    @Pooja-we3xs Před rokem +9

    Before I use to feel merge sort very difficult but after watching this video, I understood it very clearly. Thank you Striver.

  • @pcyvlogs8130
    @pcyvlogs8130 Před 7 měsíci +3

    From all the CZcams tutorials, I definitely think that your videos are the best in terms of explanation and easy understanding. Thanks a lot, and please keep it up, I love the content!!!!!

  • @cinime
    @cinime Před rokem +8

    Understood! Super amazing explanation as always!! Thank you for your great effort even in the midnight !!!

  • @navneetuppal9753
    @navneetuppal9753 Před rokem +4

    As expected, Striver's Top notch explanation made Merge sort crystal clear. UNDERSTOOD!! thankyou striver for all the content

  • @nandanitiwari8098
    @nandanitiwari8098 Před 6 měsíci +2

    These is the best explanation I have find in my entire dsa life. The best part that I always found in other dsa lectures is the best dry run and how to convert that explanation in code.
    ALOT OF THANKS.
    And that Time and Space Complexity part is like "Add a feather in a cap"

  • @subhamsharma9097
    @subhamsharma9097 Před rokem +11

    You are the real hero .. providing such a beautiful content in free of cost. thanks a lot bro.

  • @simran5048
    @simran5048 Před 11 měsíci +1

    Thankyou for explaining this very tough algo in a very simple way , now it's just get locked in my mind , all credit goes to you !! Thanks a lot !

  • @MANISHKUMAR-vn1yh
    @MANISHKUMAR-vn1yh Před rokem +5

    best merge sort explanation on CZcams ever I'll never forget that thanks bhaiyya!

  • @ishaanrawal9327
    @ishaanrawal9327 Před rokem +31

    It's 3:34 in the AM right now and I'm absolutely loving your videos and implementing them simultaneously! I can't ever thank you enough for the amazing content that you've put out! I have my placement drive starting in approximately 100 days and plan to make the most out of it with the help of your lessons! Dil se thank you bhai! Will update my placement status soon!

  • @yhbarve
    @yhbarve Před rokem +10

    This was the best explanation for Merge Sort on CZcams! Thanks

  • @mayankyadav1290
    @mayankyadav1290 Před 8 měsíci +2

    I'm pausing the video in between just to appreciate you, the way you explain things is just awesome man. Keep the good work coming. God bless you.

  • @user-ny1je3oh1f
    @user-ny1je3oh1f Před 3 měsíci

    i have already watched 20 videos about this sorting, and your are the best!!!!!!!!!! thanks!!!)))

  • @SimranSingh-sc2ou
    @SimranSingh-sc2ou Před rokem

    The best explanation I have ever come across. From the explanation to the complexity part all things were perfectly explained. Thank you so much sir!!

  • @LearnwithEase20
    @LearnwithEase20 Před 8 měsíci

    Your passion for teaching is truly inspiring. Thank you for going above and beyond to help us succeed. Your efforts are greatly appreciated.

  • @magnetrix
    @magnetrix Před 11 měsíci

    Highly Understood !!!!!!!
    Dil se thank you bhai! After watching your videos, I don't feel the need to see the code as it's pseudocode & dry run are explained so well that it give me confidence to write the whole code by myself.

  • @user-hk6qe4ts2y
    @user-hk6qe4ts2y Před 2 měsíci

    non other youtubers has such a type of dedication hats off

  • @devanshusangra6294
    @devanshusangra6294 Před 9 měsíci +5

    44:2 - "I write codes in one go", the confidence i want

  • @Sarjais_Raja
    @Sarjais_Raja Před měsícem

    The amount of energy and effort you put in this is amazing

  • @Vikhyath_Shetty
    @Vikhyath_Shetty Před měsícem +1

    The best explanation on merge sort! I had a confusion while backtracking, which has been sorted out now.

  • @premsoni619
    @premsoni619 Před 11 měsíci +2

    Wow, this DSA course is absolutely fantastic! 🚀 The explanations are clear and easy to follow, and the examples provided really helped solidify my understanding. I've been searching for a comprehensive resource like this, and I'm so glad I stumbled upon it. A huge shoutout to the creator for putting together such a valuable learning resource. Kudos! 👏💯 #DSA #TUF

  • @javeriyabegum8622
    @javeriyabegum8622 Před rokem

    Understood!! Best explanation evr on utube...Thank u Striver

  • @SR09947
    @SR09947 Před rokem +1

    Waah bhai thank you i watched a lot of videos of mergesort but no one had explained like u bro❤

  • @GauravChaubey-xo5uh
    @GauravChaubey-xo5uh Před rokem +2

    As expected one of the best and up to the point topic explanation 🔥🔥

  • @kshitijsrivastava7849
    @kshitijsrivastava7849 Před rokem +1

    watching ur for first time and my mind blown by ur explanation ....really great work..hats off to u

  • @ritikumaroy
    @ritikumaroy Před rokem +11

    A little correction at 24:37
    You can't write if(low>=high). It will cross the time limit in some cases. As I'm facing this issue in GFG merge sort problem. Instead use if(low==high)

  • @tahuraalam7
    @tahuraalam7 Před 10 dny

    I haven’t seen anyone making such
    in depth videos 😮. You are doing a great job striver ❤

  • @changed217
    @changed217 Před 11 měsíci +15

    The efforts taken to make this video must have been insane, because this was frankly explained so well it's honestly brilliant. Thank you for all your efforts. Completing this at 4:47am here.

    • @iamnoob7593
      @iamnoob7593 Před 6 měsíci +4

      No compromise on sleep from my side , Body does not listen to emotions

  • @ArunKumar-vd8zt
    @ArunKumar-vd8zt Před 2 měsíci +1

    One of the best explanations I have ever seen on CZcams 🛐

  • @secretcoder7
    @secretcoder7 Před rokem

    I watched this lecture two times and I get everything about merge sort
    Thankyou striver bhaiya I started ur atoz dsa playlist 🥳🥳♥️

  • @user-zm8fw9bi3r
    @user-zm8fw9bi3r Před 11 měsíci

    This course is so much helpful for me, thank you so much for this amazing free course .

  • @rudranshnemade6299
    @rudranshnemade6299 Před 9 měsíci

    Thank you striver for the first time I can code the complete algo of merge sort on my own Thank you💖

  • @_Kunal_Pawar
    @_Kunal_Pawar Před 4 měsíci

    Once again, an outstanding video! Thank you for investing so much effort in breaking down the approach, providing clear pseudocode, illustrating with recursion trees, and finally, implementing the solution. Take good care of your health too! I hope that you are at least getting sleep for 7 to 8 hours.

  • @nischayagrawalVlogs
    @nischayagrawalVlogs Před rokem +1

    Kya explain kiya hai bro !! like wtf pure yt pe itna acha explanation nai mila meko. Hats off to you my man.

  • @TrendyGamer007
    @TrendyGamer007 Před rokem +2

    just mind blowing explanation .

  • @rb-work
    @rb-work Před rokem

    Sir you are a Straight up god for these topics, Thanks for this great explanation.

  • @snehapawar1688
    @snehapawar1688 Před 7 měsíci

    Best merge sort explanation ever!! Thanks a lot.

  • @prakashkundula8860
    @prakashkundula8860 Před 6 měsíci

    Hats off for your explanation...
    you've made me understood recursion with one video

  • @ksankethkumar7223
    @ksankethkumar7223 Před rokem +8

    int mid =(low + high) / 2; might give an integer over flow resulting in a negative index which would throw Array out of Bounds Exception and hence its a good practice to use int mid = low + ((high - low) / 2); or faster way is int mid = (low + high) >>> 1 (For Java) and int mid = ((unsigned int)low + (unsigned int)high)) >> 1 (For CPP) to avoid any kind of overflows..

    • @magnetrix
      @magnetrix Před 11 měsíci +1

      Cherry on the cake

    • @utkarshsingh5652
      @utkarshsingh5652 Před 9 měsíci

      why in the last we did arr[i] = temp[i-low] and not arr[i]=temp[i
      ]

    • @ksankethkumar7223
      @ksankethkumar7223 Před 9 měsíci

      @@utkarshsingh5652 Because every time the low is not zero. In deeper recursive calls, low can be anything

    • @shivangitekriwal3056
      @shivangitekriwal3056 Před měsícem

      ​@@ksankethkumar7223but we added elements in temp so index might be from 0 to high??

  • @ashishsahay1901
    @ashishsahay1901 Před 11 měsíci +1

    @Raj you are changing the field of programming even the concepts and the visualization which are difficult for the experienced professional by watching your videos feel like it's just a cakewalk. Thanks for the content, keep doing it.
    JAVA CODE for the merge Sort Algorithm----- TC--O(n*logn) & SC--O(n)
    import java.util.*;
    public class Solution {
    public static void mergeSort(int[] arr, int n) {
    // Write your code here.
    ms(arr,0,n-1);
    }
    public static void ms(int arr[],int low,int high)
    {
    if(low>=high)
    {
    return;
    }
    int mid = (low+high)/2;
    ms(arr, low, mid);
    ms(arr, mid+1, high);
    merge(arr,low,mid,high);
    }
    public static void merge(int arr[],int low,int mid,int high)
    {
    int left = low;
    int right = mid+1;
    java.util.List temp = new ArrayList();
    while(left

  • @siddesh1210
    @siddesh1210 Před rokem

    Just started watching the DSA sheet 3-4 days back and after every video just one word for uh bro wow,superb,amazing❤.Got heart and thankyou soo much for such a amazing and quality content❤.

  • @utsavseth6573
    @utsavseth6573 Před rokem

    Legendary striver , simply legendary explaination.

  • @AmanKumar-fe2ez
    @AmanKumar-fe2ez Před rokem +6

    Best merge sort ever but i little bit mad so have to watch it 2-3 times to get properly in my head btw thankyou Striver

  • @ishwaripednekar5164
    @ishwaripednekar5164 Před 8 měsíci +1

    Hats off to you for such free content❤

  • @mdfaizanmdfaizan6041
    @mdfaizanmdfaizan6041 Před měsícem +1

    Great explanation sir, i didn't understand this concept from love babbar sir so i came here and got it ❤❤❤

  • @RahulKumar-ng8rs
    @RahulKumar-ng8rs Před 10 měsíci

    Thanks for the hardwork Striver, you are an inspiration.

  • @nagarajmnaiknagaraj1813
    @nagarajmnaiknagaraj1813 Před měsícem

    How i express your teaching skills
    You r amazing!!!
    I seen so many videos on merge sort but no one explain like you even my college professor
    I thank to myself for finding this amazing playlist.

  • @MitaliMaurya-k4x
    @MitaliMaurya-k4x Před 12 dny

    Thankyou for your efforts!! I have never enjoyed learning DSA before the way I enjoy it through your lectures

  • @ahnafadib8774
    @ahnafadib8774 Před 9 dny

    how is bro so good at explaining, smb give this man an award

  • @yashbulsara6167
    @yashbulsara6167 Před rokem +1

    Perfect explanation ❤

  • @thenikhildaiya.
    @thenikhildaiya. Před rokem +1

    Super Super easy explanation!! Thanks for the content👍👍👍

  • @hansrajsinghpatwari4103

    understood by a great teacher ❤

  • @studynewthings1727
    @studynewthings1727 Před 9 měsíci +1

    Thankyou STRIVER, I understood the space complexity of the merge Sort.

  • @hitensamalia
    @hitensamalia Před 7 měsíci +1

    kuch kuch aata tha lekin video dekh ke accha se ho gya sab clear... Thanks, bhaiya!!!😊

  • @parthkumar5141
    @parthkumar5141 Před 5 měsíci

    Appreciable, someone suggested that I ought to watch you.

  • @santhoshs8373
    @santhoshs8373 Před 10 měsíci

    Understood Very much clearly!! Thank you❤

  • @Abhishek-et5ox
    @Abhishek-et5ox Před 11 měsíci

    best video for understanding merge sort, when compared to other videos available on

  • @ishitafantasyworld3452
    @ishitafantasyworld3452 Před 7 měsíci

    What a session this has been, Love You Striver.

  • @SanmayJainAC
    @SanmayJainAC Před 5 měsíci

    thankyou for your efforts........i am getting the concepts very clearly

  • @vardhamanbhandari5644
    @vardhamanbhandari5644 Před rokem +2

    Understood!! Best Explanation ever🙌🙌🙌🙌 #Striver Aka

  • @akshayaashok8794
    @akshayaashok8794 Před rokem +1

    Understood clearly 💯 thank you 💯🔥

  • @codinglover5251
    @codinglover5251 Před 5 měsíci +2

    your explanation method is awesome as compare to other .
    I saw many video in merge sort but I understand only in this video.
    thank you sir❤❤🔥🔥👍

  • @HariRam-ou1ij
    @HariRam-ou1ij Před 6 měsíci +1

    dry run part was superb man...🔥🔥

  • @selvaarumugam370
    @selvaarumugam370 Před rokem

    I can understand the whole video bruh very great jus got it rat into my hands in my first yr I am very lucky to find u soon.

  • @bhavya8608
    @bhavya8608 Před rokem

    Understood!! Loved the explanation!🙌

  • @saijrap-wf2tk
    @saijrap-wf2tk Před rokem +1

    I have understood everything. Sir thanks to make such a best video.

  • @justvibin6601
    @justvibin6601 Před 3 měsíci

    Amazing ! No dbts at all ...understood without replaying any parts .

  • @shahbano9672
    @shahbano9672 Před 8 měsíci

    You explain the best! Hats Off :)

  • @shreyashukla4764
    @shreyashukla4764 Před rokem

    Understood, most clear explanation

  • @kuldeepghorpade722
    @kuldeepghorpade722 Před 6 měsíci

    Your are one of the best instructor, youtuber❤

  • @rajpalsinghchauhan8213

    Best Explaination of Merge Sort, Really thank you Striver.

  • @lakshmitirupatamma2139
    @lakshmitirupatamma2139 Před rokem +1

    Very good explanation Sir. Thank you so much for your efforts.

  • @hscadmissionhacks8574
    @hscadmissionhacks8574 Před 8 měsíci +1

    you are an absolute legend,love from Bangladesh

  • @siddharthdwivedi4102
    @siddharthdwivedi4102 Před rokem

    incomparable teaching skills.

  • @MATTUPALLINVSGKESAVAKUMARBCE
    @MATTUPALLINVSGKESAVAKUMARBCE Před 8 měsíci +1

    hatsoff for your dedication striver 🙌

  • @sauravfarkade7032
    @sauravfarkade7032 Před rokem

    Thanks for this Quality series, lots of respect for you bhaiya!!

  • @AmanKumar-fe2ez
    @AmanKumar-fe2ez Před rokem +1

    Thankyou for the lecture striver

  • @user-pu3by6bd8u
    @user-pu3by6bd8u Před 8 měsíci

    super explaination... thank you bhaiya!!

  • @twishanuaichroy1938
    @twishanuaichroy1938 Před rokem

    The explanation is top notch my man.

  • @studious264
    @studious264 Před rokem

    May god bless you. It was a gem. Respect you Hard work.

  • @rudranshchoudhary5279
    @rudranshchoudhary5279 Před měsícem

    so much clearity in explanation

  • @manideep7148
    @manideep7148 Před měsícem

    The best explanation ever !

  • @YashPatel-ih5ex
    @YashPatel-ih5ex Před 3 měsíci

    Thank you sir so much for the explaination, i've been try to dry run it and try to understand this from morning, but after watching this video everything has cleared. Hats off to you for your efforts.

  • @Srinu_KK_2030
    @Srinu_KK_2030 Před 4 měsíci

    Best of All for Merge Sort 👌👌👌👌

  • @Musicuvakavi1823
    @Musicuvakavi1823 Před 2 měsíci

    This is the best merge sort video I have never seen before Thanks a lot Sir

  • @thefourhourtalk
    @thefourhourtalk Před měsícem

    it took me near about 4 hours to completely understand the sorting technique I am in first year of engineering an average guy hoping that ..... this stuff takes time for beginners

  • @user-zn8qd5mx4r
    @user-zn8qd5mx4r Před rokem

    You are awesome , you had clear all my doubt , thanks for this buddy.

  • @kaizjessani7303
    @kaizjessani7303 Před rokem

    May God bless you with Success and good health... This content is Pure Gold ❤️