Welcome to my Java sort algorithm tutorial. Here I will cover all of the elementary sorting algorithms : Bubble, Selection and Insertion sort.
I also created a new method we can use to analyze the arrays so we can learn how the sorts work. I want this video to be very interactive so that you really understand the sort algorithms.
I also cover the linear and binary search algorithms. The code below will help you learn these algorithms perfectly.
If you like videos like this, it helps to tell Google+ [googleplusone]
Code From the Video
Hi Darek,
i always have a confusion, why we use two looping statements in sorting algorithms, it may looks silly question, but need some clarification.
One of the loops is starting at the end of the array and the other at the beginning. It is almost like a bat hitting a ball. The ball starts at one end and moves toward the bat. The bat hits it and it goes back to the beginning. The only difference in this situation is that after the bat hits the ball it moves closer to the balls starting position by 1 index. I hope that helps
Thanks for the example. 🙂
i will post again if i will have questions.
I’m glad to help 🙂
Can you create a Flash Sort programming I really need it for my defense
I’ll make sure I cover it when i get back into algorithms.
Hey Derek great tutorial as always, I was wondering if you can apply the same algorithm to Doubly Linked List and can you make a tutorial video of it.
Yes pretty much. I cover the doubly linked list here.
Very Effective tutorial,Excellent work,Keep it up
Thank you very much 🙂 I’m glad you enjoyed it
Hi Derek,
I was asked in the interview, how will you sort an array with 1 million values in it? Please let me know your thoughts on this.
Thanks
Raj
Hi Raj
QuickSort is normally faster then heap sort because of how it manages data in memory, but QuickSorts worst case performance is considerably worse then Heap Sort.
Hi Derek,
Your bubbleSort() function does not work correctly for a reverse
sorted array as the outer for loop iterates n-2 times when it should be iterating n-1 times.
To verify this for yourself, in your generateRandomArray() function, sort and reverse the array using inbuilt java functions
and then call the bubbleSort function.
(This is the second time I am trying to report this error. Hope you fix it.)
I’ll take a look at it. Sorry about not getting back to you quicker
The correct bubble sort is:
public void bubbleSort(){
// i starts at the end of the Array
// As it is decremented all indexes greater
// then it are sorted
for(int i = arraySize – 1; i > 0; i–){
// The inner loop starts at the beginning of
// the array and compares each value next to each
// other. If the value is greater then they are
// swapped
for(int j = 0; j < i; j++){
// To change sort to Descending change to theArray[j + 1]){
swapValues(j, j+1);
printHorzArray(i, j);
}
}
}
}
Derek Banas,
Just want to say that I’ve been learning more about serious problem solving in your tutorials than any other resource on the internet or otherwise.
I take my hat off and thank-you.
Thanks,
Aidan
Hi Aidan,
I’m very happy to hear that my tutorials have helped 🙂 Thanks for taking the time to tell me.
Thank you for preparing awesome tutorials. And giving them to internet free =)
You’re very welcome 🙂
Please Someone Post a Flash Sorting Program code !!!
Derek……you have been my online teacher and mentor for about 2 months now….and will continue to be for a long long time….thanks for taking your time to do allthe great stuff.
Thank you 🙂 I’m very happy I can help