Best step by step explanation of merge sort code in KZbin
@divyamehta28635 жыл бұрын
initialization for right array can be resolved by taking ,int right[] = new int[array.length-mid]; Otherwise really a good explanation of code.
@neolegionar4 жыл бұрын
True but first thing that came to my mind was int right[] = new int[mid+array.length%2]
@phabove73 жыл бұрын
@@neolegionar : It should be division and not modulo, right? Mod 2 will only return either 0 or 1.
@DR-ng7oh2 жыл бұрын
I cannot even begin to say how much this helped
@greentorainchannel3862 жыл бұрын
One of the best video in youtube for merge sort.. 👍👍👍👍👍 easy to understand and remember...
@iamarnabpal3 жыл бұрын
This is the beauty of bottom-up approach. This tutorial is so easy to understand because Johnathon did a bottom-up approach. Hands down, the best tutorial on merge sort in Java on YT. This video should have had 1 million likes.
@deepakmodi103 жыл бұрын
No words to describe how easy you made this algo. Easy to understand.
@markd27973 жыл бұрын
2:46 this is ONE EXAMPLE of what made your tutorial different and exponentially better than other tutorials. You stopped and asked “what if” then proceeded to answer that “what if” immediately. Other tutorials just starts with an array of size 8, explains merge sort as “DiViDe aNd cOnqUeR” then call it a day. So, I’d like to say thank you for making this great tutorial.
@rachamallidorasrivignesh44992 жыл бұрын
The way of teaching is excellent johnathon tq.
@xingjianwang18944 жыл бұрын
This explanation is simpler and better than GeeksforGeeks, tbh.
@saikiranj8075 жыл бұрын
Although I don't take paid courses online , I seriously think you should make one. You have a natural talent at explaining code. Seriously, it's the best explanation on KZbin, ever!
@iyadshaheen46933 жыл бұрын
just came across this, amazing video, I do have one comment and it just simplifies the code much more. my comment is that if the array of size 7 -> mid point is 7/2 = 3 you initialize that first array with size 3 and then you initialize the right array with, (consider array is the main original array name), array.length - midpoint size and that is 4 so that way you don't really need all those if else statements. it works if the array was of size 8 too (even split). other than that greatttt work and very good vid
@javaexpertsa89475 жыл бұрын
Unbelievable Tutorial, i tried so many courses and watched so many videos and still couldn't understand Merge Sort, because the instructor didn't explain the code well or just show the code without saying a single word. Thank you so much!
@yolopassion6 жыл бұрын
The best explanation of Java Code for Merge Sort on You tube
@nguyenphuc20464 жыл бұрын
best explanation you could found on youtube
@bm10783 жыл бұрын
Thankyou so much, this explanation is literally so much better than what was in my textbook lol
@cenkercanbulut30695 жыл бұрын
Finally, someone, with full control over what he does , explaining it... A BIG THANKS LIKE AND SUB!
@mongoose16184 жыл бұрын
This is so much simpler to understand and easy to remember, Thank you! However, I think you must correct your IF condition at line 71 to if(left[leftPointer]
@twitjunkie60073 жыл бұрын
Are you talking about the case where elements in the left and right are same ? I tried creating an array with same elements and ran this code. It is working.
@phabove73 жыл бұрын
I think his code will also produce the same result. Because, without equality check, the first element in the right half should be the same.
@HorizonSpeed264 жыл бұрын
Thanks for the code explaination, now the implementation of merge sort makes sense in terms of the conceptual explaination of merge sort.
@blastoice92813 жыл бұрын
Gotta say, I like your solution the best. Clear explanation too, thanks alot.
@DeepsWar4 жыл бұрын
This is such a great explanation. Had been struggling to understand the concept and code accordingly and this implementation & explanation is too good. Thanks again!
@pradyumna6684 жыл бұрын
your explanation helped me a lot keep doing more videos on ds and algo
@minhtanchu2403 жыл бұрын
Thank you so much! Easy to understand.
@filiptomic85315 жыл бұрын
Omg thank you so much this is the best explanation I found on KZbin
@mikaelalvian81603 жыл бұрын
Amazing explanation! Thank you, Sir!
@laleen1234 жыл бұрын
By far the best version, Thank you
@Morkizas5 жыл бұрын
The f***g BEST explanation of Merge Sort, you saved me a lot of nerves :)
@romannejouta65463 жыл бұрын
Very well explained!!! Thank you!
@liyingfeng24643 жыл бұрын
super clearly explained, thank you so much!
@ramansb10083 жыл бұрын
Excellent explaination!
@yahiamostafa47185 жыл бұрын
The Best Explanation
@aneilievska98834 жыл бұрын
OMG this was awesome, please when you have time cover Quick Sort.
@rajshreerai6283 жыл бұрын
thank you.. this was awesome
@vinayr22655 жыл бұрын
wow.. excellent explanation.. the best one i came across.. thank you very much
@hegyilevente2214 жыл бұрын
That one was life saving. Thank you!
@davidaraujo20495 жыл бұрын
Thank you soo soo much, you just saved my exam tomorrow !!!
@maddy36563 жыл бұрын
Very helpful, thank you!
@rejithregi25885 жыл бұрын
very clearly explained
@Superb_virg5 жыл бұрын
Thank you great explanation. I have one question however: why does the incrementing of the pointers have to happen when they are used and not after? 18:05 And why do you get a weird output if you do not?
@ankitjoshi65455 жыл бұрын
Hey Samuel, It is not necessary to do leftpointer++. He just meant that do not forget to increment. you can split that (single line) result[resultpointer++] = left[leftpointer++]; is same as {three lines of code} result[resultpointer] = left[leftpointer]; resultpointer++; leftpointer++; you will get weird output if you do not increment . you will remain at the same pointer as previous iteration. you need to increment pointer to point next index in next iteration right.
@rixflores42045 жыл бұрын
Bro wtf you are the best 👌 thanks from mexico
@mohdarshad94274 жыл бұрын
best step by step code explaination ever found on youtube for merge sort thank u so much . how can i contact with u ?
@palaksdarji4 жыл бұрын
This is superb.
@Joy-mf6xo3 жыл бұрын
Thank you!
@Mona001-01g4 жыл бұрын
Johnathon could you please also make a video for binary search in java. You explain so well. Somehow I understand much better when you do since i tried other videos in vain
@ragabhassan10433 жыл бұрын
that was great thank you
@willemvheerden71855 жыл бұрын
Awesome tutorial
@zeeshanhasnani6 жыл бұрын
Thanks a lot! Your explanations were awesome and concise! :D
@znveleisi15663 жыл бұрын
what should i change to make it sort in a descending order
@sivaprasath87663 жыл бұрын
Awesome!!!!
@SinteXCod5 жыл бұрын
Ty mate, now I finally understand it!
@bouhenniouahiba88924 жыл бұрын
i need help , how does the synchronization between several users (modify the same shared file) with algorithms
@charlibravo25785 жыл бұрын
Really helpful! Thank you so much!!
@eoghanfeighery73833 жыл бұрын
Just out of curiosity, is it possible to this program with an instantiable class containing multiple datatypes (String, integer, double)
@luckypatilbhosle0075 жыл бұрын
I understood code .........Thank you sir...........
@goodyramsesgarciatrujillan40353 жыл бұрын
ur the best ty
@sdfghuihef56023 жыл бұрын
Thank you
@606shann4 жыл бұрын
Awesome sir, Thanks a lot
@FutureWiredTec5 жыл бұрын
Thank you very much that was very helpful
@loisesp80613 жыл бұрын
Where did you compile this? What app did you use to run this code. Thanks in advance :)
@ramgopal25205 жыл бұрын
I am somewhere stuck in the recursion of the method Merge. Could someone help me with it. Other than that I understood everything. And I have been going through merge sort for a lot of days and this guy nailed it with his explanation !! Still stuck in the recursive part 😢
@kshitijnegi81512 жыл бұрын
I am stuck too
@Mona001-01g4 жыл бұрын
What happens when both leftpointer and righpointer values are equal?
@muhammadahmadi70964 жыл бұрын
Wow, was amazing 😍👌
@irfancalsr79823 жыл бұрын
Amazing
@UKcouple1736 жыл бұрын
clearly explained thank you so much
@adithyanalluri48815 жыл бұрын
Excellent!!
@vincemarkarnedo66445 жыл бұрын
Great vid. But please next time add comments
@tufanatha77984 жыл бұрын
Awesome explanation ! few lines of coding can be reduced (27~35) by replacing: int[] right=new int[array.length-middle];
@pointless88465 жыл бұрын
Hey I really liek your video, I am pretty new to Java and I had a question about incrementing in your merge method, specifically about left[leftPointer++], wouldn't it increment first then chose the index. For example: leftPointer = 0 left[leftPointer++] would become left[1] or does in take leftPointer as the index then it increments? I am not sure if you understand my question.
@-0----0----0----.-----.----.-74 жыл бұрын
no it willl not....its postfix increment right...soo it willl only increment after....prefix which is ++x will do exactly as you said...but not postfix x++
@pradyumna6684 жыл бұрын
thank you so much
@drikast4 жыл бұрын
why did you increment: "result[rightPointer++] = right[rightPointer++]"? isn't it supposed to start from the first element [0]? Won't the increment point at the second[1]?
@-0----0----0----.-----.----.-74 жыл бұрын
no it willl not....its postfix increment right...soo it willl only increment after....prefix which is ++x will do exactly as you said...but not postfix x++
@luckypatilbhosle0075 жыл бұрын
It is not working for large arrray.............. ArrayIndexOutOfBoundException is coming
@waynemack66375 жыл бұрын
does this with an odd amount of items in array
@eagerassaultixopi45585 жыл бұрын
at 2:08 i don't understand the usage if(array.length
@GFC13375 жыл бұрын
because if the array is of size 1, then it's [8] for example. Therefore it's already sorted. It's impossible for 1 number to be sorted.
@qaipak16 жыл бұрын
Correct me if wrong (and this might be nitpicking if I'm not) but around 12:00 when you are checking which one is less, should it not be less than equals to? Otherwise in equal cases the right and left will swap. Yes your array will be sorted but I believe Merge sort is supposed to be in place i.e, inputs should be in the order they were inserted in. Again I might be wrong being a novice.
@JohnKwisses5 жыл бұрын
I believe that you are correct. The values will be the same, but for best practice, you should use
@qaipak15 жыл бұрын
@@JohnKwisses Thanks. Great video btw!
@MYmotivationn4 жыл бұрын
perfect bro
@jacobjacob57356 жыл бұрын
Is this faster than comparing two numbers and switch their places within a counter for i and j?
@arnoc.21076 жыл бұрын
It is way more efficient. The runtime of a well-implemented mergeSort-algorithm is log(n) in the worst case. Meanwhile, having two for-loops comparing two elements at a time and switching them if necessary, has a WAY longer runtime.
@manis84835 жыл бұрын
Hi Johnathan Your way of explaining the code was just amazing. But when i try to recreate your code, i am getting an array out of bound exception. my code.... package sortingAlgo; public class MergeSorting { private static void printArray(int[] ar) { for (int i : ar) { System.out.print(i + " "); } System.out.println(); } private static int[] mergeSort(int[] ar) { if (ar.length
@JohnKwisses5 жыл бұрын
Change this: for (int j = 0; j < right.length; j++) { right[j] = ar[midpoint + 1]; } To this: for (int j = 0; j < right.length; j++) { right[j] = ar[midpoint + j]; } In your mergeSort method (changing the 1 to a j).
@vishalbisht55545 жыл бұрын
The code explained by tutorial has error it will never work for larger array.
@jm7849524 жыл бұрын
okkkkk. and i thought it was my mistake....how can i fix this?
@curtistackie74596 жыл бұрын
I don't understand what you mean by "while there are elements left in the array" at 17:37 when you don't delete any elements from any arrays at any point.
@JohnKwisses6 жыл бұрын
The while loop will only run if there are elements still in the left or the right array starting from the left or right pointer position onwards. If a pointers position is equal to the length of its respective array, it means that there are no more elements to check in the array and the loop does not need to be run. For example, the loop would not run if the arrays did not contain any elements (the length of the array is not less than the position of its pointer). Another example, the loop would run if the left array had one element and the right array was empty (the length of the left array would be less than the position of its pointer). Same as if the right array had one element and the left array was empty (due to the exclusive OR operator as defined in the while loop). Hope this helps!
@3bdoelnaggar5 жыл бұрын
THANKS
@bantikumar88366 жыл бұрын
too good !!!!! but these are easily understandable need clarity in graph and trees
@samirallahverdi49484 жыл бұрын
What a long soluthion!
@AryanSingh2512.5 жыл бұрын
Why java code is so much different than C?
@castro66125 жыл бұрын
because they are different language
@-0----0----0----.-----.----.-74 жыл бұрын
me as a programmer duh.. 5:09
@shadmansudipto72873 жыл бұрын
at 8:30 you create pointers, but you do not explain what you mean by pointers, wastes a lot of time trying to understand that.