Implementation of sorting algorithms
- Bubble Sort

2. Selection Sort

3. Insertion Sort

Out of these three algorithm which one is better? How can you measure this?
Important influence factors to the performance of a sorting algorithm can be separated into two main parts:
- Memory Consumption of the algorithm
- Total runtime of an algorithm
In case the program is to some case a program which interacts with others also the response time is a very important fact of the performance of a program.
How to measure Memory Consumption?
The total used / free memory of an program can be obtained in the program via java.lang.Runtime.getRuntime(); The runtime has several met

hod which relates to the memory. The following code example demonstrate its usage.
- Calculate memory consumption for above sorting algorithms using above function for 100 arrays.

- Bubble sort algorithm has the minimum number of standard deviation

- But Insertion sort algorithm has the minimum memory usage. (298.98KB)
- Difference of standard deviation between bubble and insertion has 9.452, but average has 136. So, insertion algorithm is good for memory consumption

Performance of algorithm according to memory usage
From https://en.wikipedia.org/wiki/Sorting_algorithm

How to measure runtime of an algorithm?
Use System.nanoTime(); to get the start time and the end time and calculate the difference.
- Calculate run-time for above sorting algorithms using above function for 100 arrays.

Summary

Conclusion
The response time is a very important fact of the performance of a program. So, insertion algorithm has the minimum run time.
Considering runtime and memory consumption, insertion algorithm is the best sorting algorithm.
Performance of algorithm according to response time
From https://en.wikipedia.org/wiki/Sorting_algorithm
