Sorting Algorithms Performance Analysis

RMAG news

For those who study algorithms and programming logic, we know there are some powerful algorithms in matter of efficiency. But have you ever seen numbers showing the real difference between them?
I asked that to myself and I decided to implement by myself some famous algorithms and timed them when sorting two particulars arrays of n size. We can see it bellow:

Testing sorting algorithms

Array length: 100000

Testing Merge Sort
Best case average time: 0.045 seconds
Worst case average time: 0.041 seconds
Testing Heap Sort
Best case average time: 0.022 seconds
Worst case average time: 0.016 seconds
Testing Quick Sort
Best case average time: 0.021 seconds
Worst case average time: 0.021 seconds
Testing Selection Sort
Best case average time: 16.457 seconds
Worst case average time: 18.538 seconds
Testing Bubble Sort
Best case average time: 0.001 seconds
Worst case average time: 40.580 seconds

the average gets more precise when you increase the times you execute the algorithms, in this case, each algorithm has been executed 10 times. I choose that amount because the Selection and Bubble would take a lot to finish if I insert higher values..

Leave a Reply

Your email address will not be published. Required fields are marked *